浏览代码

Merge branch 'cygx7.5'

ziwen 2 年之前
父节点
当前提交
eae21ad24e
共有 3 个文件被更改,包括 35 次插入12 次删除
  1. 7 6
      services/cygx_research_summary.go
  2. 6 6
      services/task.go
  3. 22 0
      utils/common.go

+ 7 - 6
services/cygx_research_summary.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"context"
 	"fmt"
 	"hongze/hongze_task/models/data_manage"
 	"hongze/hongze_task/services/alarm_msg"
@@ -11,7 +12,7 @@ import (
 	"time"
 )
 
-func CygxResearchSummary() (err error) {
+func CygxResearchSummary(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
 			go alarm_msg.SendAlarmMsg("CygxResearchSummary-定时本周生成研究汇总失败, ErrMsg:\n"+err.Error(), 3)
@@ -19,8 +20,8 @@ func CygxResearchSummary() (err error) {
 		}
 	}()
 	//content := "本周研究汇总"
-	friday := utils.GetNowWeekFriday().Add(15 * time.Hour)
-	lastfriday := utils.GetLastWeekFriday().Add(15 * time.Hour)
+	friday := utils.GetNowWeekThursday().Add(9 * time.Hour)
+	lastfriday := utils.GetLastWeekThursday().Add(9 * time.Hour)
 	lastMonth := int(lastfriday.Month())
 	month := int(friday.Month())
 	lastDay := lastfriday.Day()
@@ -487,15 +488,15 @@ func CygxResearchSummary() (err error) {
 	return
 }
 
-func CygxLastWeekSummary() (err error) {
+func CygxLastWeekSummary(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
 			go alarm_msg.SendAlarmMsg("CygxLastWeekSummary-定时生成上周纪要汇总失败, ErrMsg:\n"+err.Error(), 3)
 			fmt.Println(err)
 		}
 	}()
-	tuesday := utils.GetNowWeekTuesday().Add(8 * time.Hour)
-	lastTuesday := utils.GetLastWeekTuesday().Add(8 * time.Hour)
+	tuesday := utils.GetNowWeekThursday().Add(8 * time.Hour)
+	lastTuesday := utils.GetLastWeekThursday().Add(8 * time.Hour)
 	lastMonth := int(lastTuesday.Month())
 	month := int(tuesday.Month())
 	lastDay := lastTuesday.Day()

+ 6 - 6
services/task.go

@@ -117,13 +117,13 @@ func Task() {
 	task.AddTask("定时发布研报语音播报", publishVoiceBroadcast)
 
 	// 定时生成本周研究汇总
-	//cygxResearchSummary := task.NewTask("cygxResearchSummary", "0 0 15 * * 5", CygxResearchSummary)
-	//task.AddTask("定时生成本周研究汇总", cygxResearchSummary)
+	cygxResearchSummary := task.NewTask("cygxResearchSummary", "0 0 9 * * 4", CygxResearchSummary)
+	task.AddTask("定时生成本周研究汇总", cygxResearchSummary)
 	// 定时生成上周纪要汇总
-	//CygxLastWeekSummary := task.NewTask("CygxLastWeekSummary", "0 0 8 * * 2", CygxLastWeekSummary)
-	//task.AddTask("定时生成上周纪要汇总", CygxLastWeekSummary)
-	CygxResearchSummary()
-	CygxLastWeekSummary()
+	CygxLastWeekSummary := task.NewTask("CygxLastWeekSummary", "0 0 8 * * 4", CygxLastWeekSummary)
+	task.AddTask("定时生成上周纪要汇总", CygxLastWeekSummary)
+	//CygxResearchSummary()
+	//CygxLastWeekSummary()
 	task.StartTask()
 
 	fmt.Println("task end")

+ 22 - 0
utils/common.go

@@ -572,6 +572,28 @@ func GetLastWeekTuesday() time.Time {
 	return mondayTime
 }
 
+// GetNowWeekFriday 获取本周周四的时间
+func GetNowWeekThursday() time.Time {
+	offset := int(time.Thursday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
+// GetLastWeekFriday 获取上周周四的时间
+func GetLastWeekThursday() time.Time {
+	offset := int(time.Thursday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset-7)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
 // GetNowWeekFriday 获取本周周五的时间
 func GetNowWeekFriday() time.Time {
 	offset := int(time.Friday - time.Now().Weekday())