wkyuer hai 2 semanas
pai
achega
3795a305ac
Modificáronse 2 ficheiros con 33 adicións e 11 borrados
  1. 5 0
      sendBidToSftp/config.yaml
  2. 28 11
      sendBidToSftp/main.go

+ 5 - 0
sendBidToSftp/config.yaml

@@ -32,4 +32,9 @@ sftp:
   user: qx-jy-purchase-data
   pwd: GFYDBO9Y7HOJUOAT
 
+sendTime:
+  start: "2021-08-21 00:00:00"
+  end: "2021-08-28 00:00:00"
+
+
 qwRobotNotice: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e7792e7a-159d-4419-b1ed-27ea19b6ea54"

+ 28 - 11
sendBidToSftp/main.go

@@ -49,20 +49,37 @@ var (
 		}
 		g.Log().Infof(ctx, "%s共有增量数据%d条", dataShow, count)
 
-		sendFail := send.UpLoadFilesToSftp(ctx, fullName)
-		if sendFail != nil {
-			g.Log().Infof(ctx, "文件传输异常 %v", sendFail.Error())
+		var (
+			startDateStr = g.Cfg().MustGet(ctx, "sendTime.start").String()
+			endDateStr   = g.Cfg().MustGet(ctx, "sendTime.end").String()
+			isSend       = false
+			now          = time.Now()
+		)
+		ss, ss_err := time.ParseInLocation(time.DateTime, startDateStr, time.Local)
+		se, se_err := time.ParseInLocation(time.DateTime, endDateStr, time.Local)
+		if se_err != nil || ss_err != nil {
+			g.Log().Errorf(ctx, "格式化发送时间异常 %v %v", ss_err, se_err)
+		} else {
+			if now.After(ss) && now.Before(se) {
+				isSend = true
+			}
 		}
-
-		if qwRobotNotice := g.Cfg().MustGet(ctx, "qwRobotNotice").String(); qwRobotNotice != "" {
-			var content string
-			content = fmt.Sprintf("任务[%s]\n共%d条标讯数据", dataShow, count)
+		if isSend {
+			sendFail := send.UpLoadFilesToSftp(ctx, fullName)
 			if sendFail != nil {
-				content += fmt.Sprintf("\n成功上传失败:%v", sendFail)
+				g.Log().Infof(ctx, "文件传输异常 %v", sendFail.Error())
 			}
-			g.Log().Infof(ctx, content)
-			if err := send.SendSimpleMsg2ChatBot(content); err != nil {
-				g.Log().Errorf(ctx, "发送企业微信消息异常 %s", err.Error())
+
+			if qwRobotNotice := g.Cfg().MustGet(ctx, "qwRobotNotice").String(); qwRobotNotice != "" {
+				var content string
+				content = fmt.Sprintf("任务[%s]\n共%d条标讯数据", dataShow, count)
+				if sendFail != nil {
+					content += fmt.Sprintf("\n成功上传失败:%v", sendFail)
+				}
+				g.Log().Infof(ctx, content)
+				if err := send.SendSimpleMsg2ChatBot(content); err != nil {
+					g.Log().Errorf(ctx, "发送企业微信消息异常 %s", err.Error())
+				}
 			}
 		}
 	}