浏览代码

优化累计值转月的计算

xiexiaoyuan 2 年之前
父节点
当前提交
a06eeae92f
共有 1 个文件被更改,包括 14 次插入34 次删除
  1. 14 34
      models/predict_edb_data_calculate_ljzzy.go

+ 14 - 34
models/predict_edb_data_calculate_ljzzy.go

@@ -218,34 +218,7 @@ func refreshAllPredictCalculateLjzzy(to orm.TxOrmer, edbInfoId, source int, from
 		dataMap[v.DataTime] = v.Value
 	}
 	existDataMap := make(map[string]string)
-	//查找实际日期, 如果实际日期不是月末值,则把上个月末日期作为实际日期
-	for yk, yv := range yearMap {
-		for i := 1; i <= 12; i++ {
-			if dataCurrentItem, ok := yv[i]; ok {
-				if i == 1 {
-					if latestDateStr < dataCurrentItem.DataTime { //假如最新的实际值不是1月末
-						if lastYearDate, ok1 := yearMap[yk-1]; ok1 {
-							if latestDateStr > lastYearDate[12].DataTime { //同时最新的实际值不是1月末,也不是上一年的12月末
-								latestDateStr = lastYearDate[12].DataTime
-							}
-						}
-					}
-				}else if i == 2 {
-					dataOne := strconv.Itoa(yk) + "-01-31"
-					if latestDateStr > dataOne && latestDateStr < dataCurrentItem.DataTime {
-						latestDateStr = dataOne
-					}
 
-				}else{
-					if dataPreItem, ok2 := yv[i-1]; ok2 {
-						if latestDateStr > dataPreItem.DataTime && latestDateStr < dataCurrentItem.DataTime {
-							latestDateStr = dataPreItem.DataTime
-						}
-					}
-				}
-			}
-		}
-	}
 	for yk, yv := range yearMap {
 		_, oneMonthOk := yv[1]
 		_, twoMonthOk := yv[2]
@@ -295,10 +268,6 @@ func refreshAllPredictCalculateLjzzy(to orm.TxOrmer, edbInfoId, source int, from
 									err = tmpErr
 									return
 								}
-
-								if latestDateStr == date {
-									latestValue= val
-								}
 							}
 							//end 1月无值
 
@@ -350,9 +319,6 @@ func refreshAllPredictCalculateLjzzy(to orm.TxOrmer, edbInfoId, source int, from
 					err = tmpErr
 					return
 				}
-				if latestDateStr == date {
-					latestValue= val
-				}
 			}
 		}
 	}
@@ -364,5 +330,19 @@ func refreshAllPredictCalculateLjzzy(to orm.TxOrmer, edbInfoId, source int, from
 			return
 		}
 	}
+
+	//确定最终值
+	var finalLast EdbInfoSearchData
+	sql = ` SELECT data_time , value FROM edb_data_predict_calculate_ljzzy WHERE edb_info_id=? and data_time<=? ORDER BY data_time DESC `
+	tmpErr := to.Raw(sql, edbInfoId, latestDateStr).QueryRow(&finalLast)
+	if tmpErr != nil {
+		if tmpErr.Error() != utils.ErrNoRow() {
+			err = tmpErr
+		}
+		return
+	}else{
+		latestDateStr = finalLast.DataTime
+		latestValue = finalLast.Value
+	}
 	return
 }