浏览代码

内陆和沿海日期优化

ziwen 3 年之前
父节点
当前提交
abb6161739
共有 2 个文件被更改,包括 32 次插入5 次删除
  1. 17 3
      services/commodity_coal_coastal.go
  2. 15 2
      services/commodity_coal_inland.go

+ 17 - 3
services/commodity_coal_coastal.go

@@ -26,10 +26,24 @@ func FileCoalCoastal() () {
 		month = strconv.Itoa(dateMonth)
 		month = "0"+month
 	}
-	sday := time.Now().Day()
-	day := strconv.Itoa(sday)
 	path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新%s.%s.xlsx"
-	path = fmt.Sprintf(path, month, day)
+	for i := 0;i < 7;i++{
+		sday := time.Now().AddDate(0,0,-i).Day()
+		day := strconv.Itoa(sday)
+		npath := fmt.Sprintf(path, month, day)
+		fmt.Println(npath)
+		exist,err := PathExists(npath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		if exist{
+			path = npath
+			break
+		}
+	}
+
+
 	xlFile, err := xlsx.OpenFile(path)
 	if err != nil {
 		fmt.Println(err)

+ 15 - 2
services/commodity_coal_inland.go

@@ -19,8 +19,21 @@ func FileCoalInland() () {
 		}
 	}()
 	//path := "static/file/内陆17省动力煤终端用户供耗存20220322.xlsx"
-	path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存%s.xlsx"
-	path = fmt.Sprintf(path,time.Now().Format(utils.FormatDateUnSpace))
+	path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存-%s.xlsx"
+	for i := 0;i < 7;i++{
+		npath := fmt.Sprintf(path,time.Now().AddDate(0,0,-i).Format(utils.FormatDateUnSpace))
+		fmt.Println(npath)
+		exist,err := PathExists(npath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		if exist{
+			path = npath
+			break
+		}
+	}
+
 	xlFile, err := xlsx.OpenFile(path)
 	if err != nil {
 		fmt.Println(err)