浏览代码

预测指标计算

xyxie 11 月之前
父节点
当前提交
590b6e8e00
共有 1 个文件被更改,包括 8 次插入6 次删除
  1. 8 6
      models/base_predict_from_calculate.go

+ 8 - 6
models/base_predict_from_calculate.go

@@ -266,7 +266,7 @@ func RefreshAllPredictCalculate(edbInfoIdList []*EdbInfo, edbInfoId, source, sub
 // refreshAllPredictCalculate 刷新预测计算指标的全部数据
 func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int) (latestDateStr string, latestValue float64, err error) {
 	fmt.Println("startDate:", startDate)
-
+	var startDateValue float64
 	// 最小的结束日期 , 最晚的数据开始日期
 	var newLatestDate, minLatestDate, maxStartDate time.Time
 	dateList := make([]string, 0) // 第一个指标的日期数据
@@ -430,10 +430,10 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 				removeDateList = append(removeDateList, sk)
 				continue
 			}
-			/*// 最近实际日期的实际数据
-			if latestDateStr >= sk {
-				latestValue, _ = decimal.NewFromFloat(calVal).Truncate(4).Float64() //保留4位小数
-			}*/
+			// 最近实际日期的实际数据
+			if maxStartDate.Format(utils.FormatDate) == sk {
+				startDateValue, _ = decimal.NewFromFloat(calVal).Truncate(4).Float64() //保留4位小数
+			}
 			saveValue := decimal.NewFromFloat(calVal).RoundCeil(4).String() //utils.SubFloatToString(calVal, 4)
 			if existVal, ok := dataMap[sk]; !ok {
 				dataTime, _ := time.ParseInLocation(utils.FormatDate, sk, time.Local)
@@ -499,7 +499,9 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 		e := to.Raw(sql, edbInfoId, latestDateStr).QueryRow(&latestDate)
 		if e != nil {
 			if e.Error() == utils.ErrNoRow() {
-				//todo 空值怎么处理
+				//首个日期
+				latestDateStr = maxStartDate.Format(utils.FormatDate)
+				latestValue = startDateValue
 			} else {
 				err = fmt.Errorf("查询最新日期失败,Err:" + e.Error())
 				return