|
@@ -10,7 +10,7 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// EdbInfoRefreshAllFromBaseV3 全部刷新指标(切换到edb_lib服务)
|
|
|
+// EdbInfoRefreshAllFromBase 全部刷新指标(切换到edb_lib服务)
|
|
|
// @author Roc
|
|
|
// @datetime 2022-09-16 11:04:44
|
|
|
// @description 将原有的单个指标刷新,调整为批量多个指标刷新
|
|
@@ -24,7 +24,7 @@ func EdbInfoRefreshAllFromBase(edbInfoIdList []int, refreshAll bool) (err error,
|
|
|
}()
|
|
|
|
|
|
// 获取关联的基础指标
|
|
|
- newBaseEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
|
|
|
+ newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -217,11 +217,100 @@ func EdbInfoRefreshAllFromBase(edbInfoIdList []int, refreshAll bool) (err error,
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 4、更新动态环差值
|
|
|
+ {
|
|
|
+ predictEdbInfoIdList := make([]int, 0)
|
|
|
+ for _, v := range newBasePredictEdbInfoArr {
|
|
|
+ predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
|
|
|
+ }
|
|
|
+ fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
|
|
|
+ predictEdbConfCalculateMappingDetailList, tmpErr := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(predictEdbInfoIdList)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, bv := range predictEdbConfCalculateMappingDetailList {
|
|
|
+ result, tmpErr := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, bv.EdbCode, "")
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
|
|
|
+ errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Ret != 200 {
|
|
|
+ fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
|
|
|
+ errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
|
|
|
+ err = errors.New("刷新失败:" + errmsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //5、刷新相关预测计算指标
|
|
|
+ for _, v := range predictCalculateArr {
|
|
|
+ edbInfo := newPredictCalculateMap[v]
|
|
|
+ if edbInfo == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ startDate = edbInfo.StartDate
|
|
|
+ source := edbInfo.Source
|
|
|
+ if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
|
|
|
+ startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
|
|
|
+ } else {
|
|
|
+ if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
|
|
|
+ startDate = ``
|
|
|
+ if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
|
|
|
+ startDate = edbInfo.StartDate
|
|
|
+ } else {
|
|
|
+ sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ errmsg = tmpErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ frequency := edbInfo.Frequency
|
|
|
+ var limitDay int
|
|
|
+ switch frequency {
|
|
|
+ case "日度":
|
|
|
+ limitDay = utils.DATA_REFRESH
|
|
|
+ case "周度":
|
|
|
+ limitDay = utils.DATA_REFRESH * 7
|
|
|
+ case "月度":
|
|
|
+ limitDay = utils.DATA_REFRESH * 30
|
|
|
+ case "季度":
|
|
|
+ limitDay = utils.DATA_REFRESH * 90
|
|
|
+ case "年度":
|
|
|
+ limitDay = utils.DATA_REFRESH * 365
|
|
|
+ default:
|
|
|
+ limitDay = utils.DATA_REFRESH
|
|
|
+ }
|
|
|
+ startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
|
|
|
+ errmsg = "RefreshPredictEdbCalculateData Err:" + tmpErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Ret != 200 {
|
|
|
+ fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
|
|
|
+ errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
|
|
|
+ err = fmt.Errorf("刷新失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
|
|
|
-func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
|
|
|
+func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
|
|
|
calculateList, err := data_manage.GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
|
|
@@ -449,6 +538,16 @@ func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr []*data_
|
|
|
// 普通计算指标的id
|
|
|
sort.Ints(calculateArr)
|
|
|
|
|
|
+ // 普通预测指标去重
|
|
|
+ newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
|
|
|
+ basePredictMap := make(map[int]int)
|
|
|
+ for _, v := range basePredictEdbInfoArr {
|
|
|
+ if _, ok := basePredictMap[v.EdbInfoId]; !ok {
|
|
|
+ newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, v)
|
|
|
+ }
|
|
|
+ basePredictMap[v.EdbInfoId] = v.EdbInfoId
|
|
|
+ }
|
|
|
+
|
|
|
// 预测计算指标去重
|
|
|
newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
|
|
|
for _, v := range predictCalculateInfoArr {
|