ziwen 2 年之前
父节点
当前提交
df63da9ba3
共有 1 个文件被更改,包括 48 次插入28 次删除
  1. 48 28
      services/commodity_coal_inland.go

+ 48 - 28
services/commodity_coal_inland.go

@@ -5,6 +5,7 @@ import (
 	"github.com/mozillazg/go-pinyin"
 	"github.com/tealeg/xlsx"
 	"hongze/hongze_data_crawler/models"
+	"hongze/hongze_data_crawler/services/alarm_msg"
 	"hongze/hongze_data_crawler/utils"
 	"strconv"
 	"time"
@@ -15,42 +16,61 @@ func FileCoalInland() () {
 	defer func() {
 		if err != nil {
 			fmt.Println("RefreshDataFromCoalInland Err:" + err.Error())
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoalInland ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+			msg := "失败提醒"+"RefreshDataFromCoalInland ErrMsg:"+err.Error()
+			go alarm_msg.SendAlarmMsg(msg, 3)
+			//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoalInland ErrMsg:"+err.Error(), utils.EmailSendToUsers)
 		}
 	}()
-	//path := "static/file/内陆17省动力煤终端用户供耗存20220408.xlsx"
 	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
-		}
-		if i < 3 && !exist{
-			npath := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存.xlsx"
-			fmt.Println(npath)
-			exist,err := PathExists(npath)
-			if err != nil {
-				fmt.Println(err)
-				return
-			}
-			if exist{
-				path = npath
-				break
-			}
-		}
+	//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
+	//	}
+	//	if i < 3 && !exist{
+	//		npath := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存.xlsx"
+	//		fmt.Println(npath)
+	//		exist,err := PathExists(npath)
+	//		if err != nil {
+	//			fmt.Println(err)
+	//			return
+	//		}
+	//		if exist{
+	//			path = npath
+	//			break
+	//		}
+	//	}
+	//}
+	exist,err := PathExists(path)
+	if err != nil {
+		fmt.Println(err)
+		return
 	}
-	xlFile, err := xlsx.OpenFile(path)
+	if !exist{
+		path = "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存.xlsx"
+	}
+	exist,err = PathExists(path)
 	if err != nil {
 		fmt.Println(err)
 		return
 	}
+	var xlFile *xlsx.File
+	if exist {
+		xlFile, err = xlsx.OpenFile(path)
+		if err != nil {
+			fmt.Println("OpenFile err:",err)
+			return
+		}
+	}else {
+		return
+	}
 
 	var mappingItems []*models.BaseFromCoalmineMapping
 	var indexItems []*models.BaseFromCoalmineInlandIndex