|
@@ -0,0 +1,60 @@
|
|
|
+package data
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "eta/eta_task/models/data_manage"
|
|
|
+ "eta/eta_task/services/alarm_msg"
|
|
|
+ "eta/eta_task/utils"
|
|
|
+ "fmt"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// RefreshBaseFromKplerIndex 刷新通过api方式对接的Kpler数据
|
|
|
+func RefreshBaseFromKplerIndex(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := fmt.Sprintf("RefreshBaseFromKplerIndex-刷新Kpler数据失败, %v", err)
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ kplerObj := new(data_manage.BaseFromKplerIndex)
|
|
|
+ num, err := kplerObj.GetApiNum()
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("RefreshBaseFromKplerIndex-获取需要刷新的数据失败, %v", err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if num == 0 {
|
|
|
+ utils.FileLog.Info("RefreshBaseFromKplerIndex-没有需要刷新的数据")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ frequencys := []string{"日度", "周度", "月度", "季度", "年度"}
|
|
|
+ for _, frequency := range frequencys {
|
|
|
+ startDate := time.Now().Format(utils.FormatDate)
|
|
|
+ if frequency == "周度" {
|
|
|
+ startDate = time.Now().AddDate(0, 0, -5).Format(utils.FormatDate)
|
|
|
+ } else if frequency == "月度" {
|
|
|
+ startDate = time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
|
|
|
+ } else if frequency == "季度" {
|
|
|
+ startDate = time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
|
|
|
+ } else if frequency == "年度" {
|
|
|
+ startDate = time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshUrl := "kpler/index/refresh_by_api"
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ param["Frequency"] = frequency
|
|
|
+ param["StartDate"] = startDate
|
|
|
+ res, e := postRefreshEdbData(param, refreshUrl)
|
|
|
+ if e != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("RefreshBaseFromKplerIndex-postRefreshEdbData, frequency: %s, err: %v", frequency, e))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if res != nil && res.Ret != 200 {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("RefreshBaseFromKplerIndex-postRefreshEdbData, frequency: %s, Ret: %d, ErrMsg: %s", frequency, res.Ret, res.ErrMsg))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|