|
@@ -0,0 +1,105 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/mysteel_watch/global"
|
|
|
+ "eta/mysteel_watch/utils"
|
|
|
+ "eta/mysteel_watch/watch"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var BaseStartDate = "1991-01-01"
|
|
|
+
|
|
|
+// CheckRefreshConfig
|
|
|
+// @Description: 定时检查刷新配置
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-01-11 14:04:08
|
|
|
+func CheckRefreshConfig() {
|
|
|
+ var err error
|
|
|
+ errMsgList := make([]string, 0)
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Info("定时检查刷新配置失败:", err.Error())
|
|
|
+ }
|
|
|
+ if len(errMsgList) > 0 {
|
|
|
+ global.LOG.Info("定时检查刷新配置异常:\n", strings.Join(errMsgList, "\n"))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ resp, err := watch.GetRefreshConfigList()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取刷新配置失败:", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ list := resp.Data
|
|
|
+ if len(resp.Data) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now()
|
|
|
+ frequencyMap := make(map[string]string)
|
|
|
+ for _, item := range list {
|
|
|
+ fmt.Println(item)
|
|
|
+ if _, ok := frequencyMap[item.Frequency]; ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ frequencyMap[item.Frequency] = item.Frequency
|
|
|
+
|
|
|
+ startDate := BaseStartDate // 默认全部刷新
|
|
|
+ endDate := time.Now().Format(utils.FormatDate)
|
|
|
+ filePre := item.Frequency
|
|
|
+
|
|
|
+ switch item.Frequency {
|
|
|
+ case "日度":
|
|
|
+ filePre = "day"
|
|
|
+ endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, 0, -item.RefreshDataNum).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "周度":
|
|
|
+ filePre = "week"
|
|
|
+ endDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, 0, -item.RefreshDataNum*7).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "旬度":
|
|
|
+ filePre = "tendan"
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, 0, -item.RefreshDataNum*10).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "月度":
|
|
|
+ filePre = "month"
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, -item.RefreshDataNum, 0).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "季度":
|
|
|
+ filePre = "season"
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, -item.RefreshDataNum*3, 0).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "半年度":
|
|
|
+ filePre = "half_year"
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(0, -item.RefreshDataNum*6, 0).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ case "年度":
|
|
|
+ filePre = "year"
|
|
|
+ if item.RefreshAllData == 0 {
|
|
|
+ startDate = now.AddDate(-item.RefreshDataNum, 0, 0).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加入到待刷新列表
|
|
|
+ err = indexMergeV2(item.Frequency, startDate, endDate, filePre)
|
|
|
+ if err != nil {
|
|
|
+ errMsgList = append(errMsgList, fmt.Sprintf("合并刷新%s指标失败,err:%s", item.Frequency, err.Error()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("刷新结束")
|
|
|
+}
|