|
@@ -268,7 +268,7 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
fmt.Println("startDate:", startDate)
|
|
|
|
|
|
// 最小的结束日期 , 最晚的数据开始日期
|
|
|
- var minLatestDate, maxStartDate time.Time
|
|
|
+ var newLatestDate, minLatestDate, maxStartDate time.Time
|
|
|
dateList := make([]string, 0) // 第一个指标的日期数据
|
|
|
|
|
|
realSaveDataMap := make(map[string]map[int]float64)
|
|
@@ -276,15 +276,15 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
|
|
|
for edbInfoIndex, v := range edbInfoIdList {
|
|
|
// 单独存储max、min函数里的指标的数据
|
|
|
- /*tmpLatestDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
|
|
|
+ tmpNewLatestDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
|
|
|
if tmpErr != nil {
|
|
|
- err = errors.New(`最近的日期格式化失败;日期:` + v.EndDate + `;err:` + tmpErr.Error())
|
|
|
+ err = errors.New(`最近的日期格式化失败;日期:` + v.LatestDate + `;err:` + tmpErr.Error())
|
|
|
return
|
|
|
}
|
|
|
- if minLatestDate.IsZero() || tmpLatestDate.Before(minLatestDate) {
|
|
|
- minLatestDate = tmpLatestDate
|
|
|
+ if newLatestDate.IsZero() || tmpNewLatestDate.Before(minLatestDate) {
|
|
|
+ newLatestDate = tmpNewLatestDate
|
|
|
}
|
|
|
- tmpStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.StartDate, time.Local)
|
|
|
+ /*tmpStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.StartDate, time.Local)
|
|
|
if tmpErr != nil {
|
|
|
err = errors.New(`最近的日期格式化失败;日期:` + v.StartDate + `;err:` + tmpErr.Error())
|
|
|
return
|
|
@@ -343,9 +343,6 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
}
|
|
|
addSql := ` INSERT INTO edb_data_predict_calculate (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
|
|
|
var isAdd bool
|
|
|
- if !minLatestDate.IsZero() {
|
|
|
- latestDateStr = minLatestDate.Format(utils.FormatDate)
|
|
|
- }
|
|
|
|
|
|
//获取指标所有数据
|
|
|
dataList := make([]*EdbData, 0)
|
|
@@ -433,10 +430,10 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
removeDateList = append(removeDateList, sk)
|
|
|
continue
|
|
|
}
|
|
|
- // 最近实际日期的实际数据
|
|
|
- if latestDateStr == sk {
|
|
|
+ /*// 最近实际日期的实际数据
|
|
|
+ if latestDateStr >= sk {
|
|
|
latestValue, _ = 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)
|
|
@@ -493,5 +490,27 @@ func refreshAllPredictCalculate(to orm.TxOrmer, edbInfoIdList []*EdbInfo, edbInf
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //查询预测日期
|
|
|
+ if !newLatestDate.IsZero() {
|
|
|
+ latestDateStr = newLatestDate.Format(utils.FormatDate)
|
|
|
+ sql = fmt.Sprintf(` SELECT * FROM %s WHERE edb_info_id = ? and data_time <= ? ORDER BY data_time desc limit 1`, dataTableName)
|
|
|
+ var latestDate EdbData
|
|
|
+ e := to.Raw(sql, edbInfoId, latestDateStr).QueryRow(&latestDate)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ //todo 空值怎么处理
|
|
|
+ } else {
|
|
|
+ err = fmt.Errorf("查询最新日期失败,Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ floatValue, _ := strconv.ParseFloat(latestDate.Value, 64)
|
|
|
+ latestDateStr = latestDate.DataTime
|
|
|
+ latestValue = floatValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|