xyxie 11 月之前
父节点
当前提交
94a3895793
共有 2 个文件被更改,包括 12 次插入10 次删除
  1. 1 1
      controllers/base_from_predict_calculate.go
  2. 11 9
      models/base_predict_from_calculate.go

+ 1 - 1
controllers/base_from_predict_calculate.go

@@ -999,7 +999,7 @@ func (this *PredictCalculateController) Refresh() {
 			edbInfoList = append(edbInfoList, edbInfo)
 		}
 
-		latestDateStr, latestValue, err = models.RefreshAllPredictCalculate(edbInfoList, edbInfoTag, edbInfo.EdbInfoId, source, edbInfo.SubSource, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, edbInfoIdBytes, edbInfo.EmptyType, edbInfo.MaxEmptyType)
+		latestDateStr, latestValue, err = models.RefreshAllPredictCalculate(edbInfoList, edbInfoTag, edbInfo.EdbInfoId, source, edbInfo.SubSource, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, edbInfoIdBytes, edbInfo.EmptyType, edbInfo.MaxEmptyType, edbInfo.Extra)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			errMsg = "RefreshCalculate Err:" + err.Error()
 			break

+ 11 - 9
models/base_predict_from_calculate.go

@@ -267,7 +267,6 @@ func RefreshAllPredictCalculate(edbInfoIdList []*EdbInfo, edbInfoTag map[string]
 // refreshAllPredictCalculate 刷新预测计算指标的全部数据
 func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInfoTag map[string]int, edbInfoId, source, subSource int, edbCode, formulaStr, startDate string, edbInfoIdBytes []string, emptyType, maxEmptyType int, extra string) (latestDateStr string, latestValue float64, err error) {
 	fmt.Println("startDate:", startDate)
-	var startDateValue float64
 	// 最小的结束日期 , 最晚的数据开始日期
 	var newLatestDate, minLatestDate, maxStartDate time.Time
 	dateList := make([]string, 0) // 第一个指标的日期数据
@@ -294,7 +293,7 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 			err = errors.New(`最近的日期格式化失败;日期:` + v.LatestDate + `;err:` + tmpErr.Error())
 			return
 		}
-		if newLatestDate.IsZero() || tmpNewLatestDate.Before(minLatestDate) {
+		if newLatestDate.IsZero() || tmpNewLatestDate.Before(newLatestDate) {
 			newLatestDate = tmpNewLatestDate
 		}
 		/*tmpStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.StartDate, time.Local)
@@ -479,10 +478,6 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 				removeDateList = append(removeDateList, sk)
 				continue
 			}
-			// 最近实际日期的实际数据
-			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)
@@ -548,9 +543,16 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
 		e := to.Raw(sql, edbInfoId, latestDateStr).QueryRow(&latestDate)
 		if e != nil {
 			if e.Error() == utils.ErrNoRow() {
-				//首个日期
-				latestDateStr = maxStartDate.Format(utils.FormatDate)
-				latestValue = startDateValue
+				//首个日期的值
+				sql = fmt.Sprintf(` SELECT * FROM %s WHERE edb_info_id = ? ORDER BY data_time ASC limit 1`, dataTableName)
+				e = to.Raw(sql, edbInfoId).QueryRow(&latestDate)
+				if e != nil {
+					err = fmt.Errorf("查询最新日期失败,Err:" + e.Error())
+					return
+				}
+				floatValue, _ := strconv.ParseFloat(latestDate.Value, 64)
+				latestDateStr = latestDate.DataTime
+				latestValue = floatValue
 			} else {
 				err = fmt.Errorf("查询最新日期失败,Err:" + e.Error())
 				return