Sfoglia il codice sorgente

判断文件是否存在防止重复下载

xyxie 7 mesi fa
parent
commit
8b6fe1fbb4
1 ha cambiato i file con 6 aggiunte e 6 eliminazioni
  1. 6 6
      services/base_from_yongyi.go

+ 6 - 6
services/base_from_yongyi.go

@@ -217,8 +217,8 @@ func YongyiDownloadWeekyly(cont context.Context) (err error) {
 	fmt.Printf("endDate: %s\n", endDate)
 	dataFileExsit := false
 	chartFileExist := false
-	filePath := fmt.Sprintf("%s-%s%s", startDate, endDate, "涌益咨询 周度数据.xlsx")
-	filePath = filepath.Join(utils.YongyiReadFilePath, filePath)
+	fileName := fmt.Sprintf("%s-%s%s", startDate, endDate, "涌益咨询 周度数据.xlsx")
+	filePath := filepath.Join(utils.YongyiReadFilePath, fileName)
 
 	fmt.Println("YongyiDownloadWeekyly: " + filePath)
 
@@ -227,7 +227,7 @@ func YongyiDownloadWeekyly(cont context.Context) (err error) {
 	if e == nil { //文件或者目录存在
 		dataFileExsit = true
 	} else if os.IsNotExist(e) { //文件或者目录不存在
-		filePath = filepath.Join(utils.YongyiFilePath, filePath)
+		filePath = filepath.Join(utils.YongyiFilePath, fileName)
 
 		fmt.Println("YongyiDownloadWeekyly: " + filePath)
 
@@ -237,14 +237,14 @@ func YongyiDownloadWeekyly(cont context.Context) (err error) {
 			dataFileExsit = true
 		}
 	}
-	filePath = fmt.Sprintf("%s-%s%s", utils.YongyiReadFilePath, startDate, endDate, "周度图表版图.xlsx")
-	filePath = filepath.Join(utils.YongyiReadFilePath, filePath)
+	fileName = fmt.Sprintf("%s-%s%s", startDate, endDate, "周度图表版图.xlsx")
+	filePath = filepath.Join(utils.YongyiReadFilePath, fileName)
 	fmt.Println("YongyiDownloadWeekyly: " + filePath)
 	_, e = os.Stat(filePath)
 	if e == nil { //文件或者目录存在
 		chartFileExist = true
 	} else if os.IsNotExist(e) { //文件或者目录不存在
-		filePath = filepath.Join(utils.YongyiFilePath, filePath)
+		filePath = filepath.Join(utils.YongyiFilePath, fileName)
 		fmt.Println("YongyiDownloadWeekyly: " + filePath)
 		// 从已处理的表格中查询是否已存在,如果已存在,也无需下载
 		_, e = os.Stat(filePath)