Bladeren bron

Merge branch 'bug/5154'

Roc 2 maanden geleden
bovenliggende
commit
a3e0d16d08
3 gewijzigde bestanden met toevoegingen van 158 en 474 verwijderingen
  1. 39 0
      models/base_calculate.go
  2. 67 197
      models/edb_data_calculate_tbz.go
  3. 52 277
      models/predict_edb_data_calculate_tbz.go

+ 39 - 0
models/base_calculate.go

@@ -303,14 +303,28 @@ func (obj BaseCalculate) Tbz() (dateDataMap map[time.Time]float64, err error, er
 
 	var dateArr []time.Time
 	dataMap := make(map[string]*EdbInfoData) // 避免因为时间戳导致的日期不对,还是用string来表示比较合适
+	var firstDataTime time.Time              // 第一条数据的日期
 	for _, v := range dataList {
 		v.DataTime = time.Date(v.DataTime.Year(), v.DataTime.Month(), v.DataTime.Day(), 0, 0, 0, 0, v.DataTime.Location())
 		dateArr = append(dateArr, v.DataTime)
 		dataMap[v.DataTime.Format(utils.FormatDate)] = v
+		firstDataTime = v.DataTime
 	}
 
+	if firstDataTime.IsZero() {
+		errMsg = "无数据"
+		err = errors.New(errMsg)
+		return
+	}
+	firstDataTime = firstDataTime.AddDate(1, 0, 0)
+
 	// 开始计算
 	for _, currentDate := range dateArr {
+		// 如果当前日期的日期早于数据最早的日期,那么就不往下执行了
+		if currentDate.Before(firstDataTime) {
+			break
+		}
+
 		//当前日期
 		currentDateStr := currentDate.Format(utils.FormatDate)
 		currentItem, ok := dataMap[currentDateStr]
@@ -1883,3 +1897,28 @@ func TransDateData2EdbData(dateData map[time.Time]float64) (edbData []*EdbInfoDa
 	})
 	return
 }
+
+// EdbInfoSearchDataToEdbInfoData
+// @Description: 数据格式转换
+// @author: Roc
+// @datetime 2024-08-22 16:30:34
+// @param list []*EdbInfoSearchData
+// @return result []*EdbInfoData
+// @return err error
+func EdbInfoSearchDataToEdbInfoData(list []*EdbInfoSearchData) (result []*EdbInfoData, err error) {
+	result = make([]*EdbInfoData, 0)
+	for _, v := range list {
+		dataTime, tmpErr := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		result = append(result, &EdbInfoData{
+			EdbDataId: v.EdbDataId,
+			DataTime:  dataTime,
+			Value:     v.Value,
+		})
+	}
+
+	return
+}

+ 67 - 197
models/edb_data_calculate_tbz.go

@@ -210,25 +210,35 @@ func refreshAllCalculateTbz(to orm.TxOrmer, edbInfoId, source, subSource int, fr
 	edbInfoIdStr := strconv.Itoa(edbInfoId)
 	//计算数据
 
+	// 获取来源指标数据
 	dataList, err := GetEdbDataListAll(fromEdbInfo.Source, fromEdbInfo.SubSource, FindEdbDataListAllCond{
-		EdbInfoId:         fromEdbInfo.EdbInfoId,
-		StartDataTime:     startDate,
-		StartDataTimeCond: ">=",
+		EdbInfoId: fromEdbInfo.EdbInfoId,
+		//StartDataTime:     startDate,
+		//StartDataTimeCond: ">=",
 	}, 0)
 	if err != nil {
 		return err
 	}
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
+
+	// 来源指标数据参与计算
+	calculateDataList, err := EdbInfoSearchDataToEdbInfoData(dataList)
+	if err != nil {
+		return err
+	}
+	baseCalculate := BaseCalculate{
+		DataList:  calculateDataList,
+		Frequency: fromEdbInfo.Frequency,
+		Source:    3,
+	}
+	dateDataMap, err, _ := baseCalculate.Tbz()
+	if err != nil {
+		return err
 	}
-	fmt.Println("source:", source)
-	//获取指标所有数据
+
+	//获取当前已经入库的指标所有数据
 	existDataList := make([]*EdbData, 0)
 	dataTableName := GetEdbDataTableName(source, subSource)
-	fmt.Println("dataTableName:", dataTableName)
+	//fmt.Println("dataTableName:", dataTableName)
 	sql := `SELECT * FROM %s WHERE edb_info_id=? `
 	sql = fmt.Sprintf(sql, dataTableName)
 	_, err = to.Raw(sql, edbInfoId).QueryRows(&existDataList)
@@ -236,206 +246,65 @@ func refreshAllCalculateTbz(to orm.TxOrmer, edbInfoId, source, subSource int, fr
 		return err
 	}
 	existDataMap := make(map[string]string)
+	removeDataTimeMap := make(map[string]bool) //需要移除的日期数据
 	for _, v := range existDataList {
 		existDataMap[v.DataTime] = v.Value
+		removeDataTimeMap[v.DataTime] = true
 	}
-	fmt.Println("existDataMap:", existDataMap)
+	//fmt.Println("existDataMap:", existDataMap)
+
 	addSql := ` INSERT INTO edb_data_calculate_tbz(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
 	var isAdd bool
 	existAddDataMap := make(map[string]string)
-	for _, av := range dateArr {
-		currentItem := dataMap[av]
-		if currentItem != nil {
-			//当前日期
-			currentDate, err := time.ParseInLocation(utils.FormatDate, av, time.Local)
-			if err != nil {
-				return err
-			}
-			//上一年的日期
-			preDate := currentDate.AddDate(-1, 0, 0)
-			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-				//dataTime, _ := time.ParseInLocation(utils.FormatDate, date, time.Local)
-				timestamp := currentDate.UnixNano() / 1e6
-				timestampStr := fmt.Sprintf("%d", timestamp)
-				val := TbzDiv(currentItem.Value, findItem.Value)
-
-				if existVal, ok := existDataMap[av]; !ok {
-					if _, existOk := existAddDataMap[av]; !existOk {
-						addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-						isAdd = true
-					}
-					existAddDataMap[av] = av
-				} else {
-					existValDecimal, err := decimal.NewFromString(existVal)
-					existStr := existValDecimal.String()
-					if existStr != val {
-						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-						sql = fmt.Sprintf(sql, dataTableName)
-						_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-						if err != nil {
-							return err
-						}
-					}
-				}
-				continue
-			} else {
-				if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-					for i := 0; i <= 35; i++ {
-						nextDateDay := preDate.AddDate(0, 0, i)
-						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								existValDecimal, err := decimal.NewFromString(existVal)
-								existStr := existValDecimal.String()
-								if existStr != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							preDateDay := preDate.AddDate(0, 0, -i)
-							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
 
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									existValDecimal, err := decimal.NewFromString(existVal)
-									existStr := existValDecimal.String()
-									if existStr != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-								break
-							}
-						}
-					}
-				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TbzDiv(currentItem.Value, findItem.Value)
+	for currentDate, valFloat := range dateDataMap {
+		currentDateStr := currentDate.Format(utils.FormatDate)
+		timestamp := currentDate.UnixNano() / 1e6
+		timestampStr := fmt.Sprintf("%d", timestamp)
+		val := decimal.NewFromFloat(valFloat).String()
 
-						if existVal, ok := existDataMap[av]; !ok {
-							if _, existOk := existAddDataMap[av]; !existOk {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-							}
-							existAddDataMap[av] = av
-						} else {
-							existValDecimal, err := decimal.NewFromString(existVal)
-							existStr := existValDecimal.String()
-							if existStr != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-								if err != nil {
-									return err
-								}
-							}
-						}
-						break
-					}
-				} else {
-					nextDateDay := preDate.AddDate(0, 0, 1)
-					nextDateDayStr := nextDateDay.Format(utils.FormatDate)
+		//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该日期
+		delete(removeDataTimeMap, currentDateStr)
 
-					preDateDay := preDate.AddDate(0, 0, -1)
-					preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-					for i := 0; i < 35; i++ {
-						if i >= 1 {
-							nextDateDay = nextDateDay.AddDate(0, 0, i)
-							nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-						}
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
+		if existVal, ok := existDataMap[currentDateStr]; !ok {
+			if _, existOk := existAddDataMap[currentDateStr]; !existOk {
+				addSql += GetAddSql(edbInfoIdStr, edbCode, currentDateStr, timestampStr, val)
+				isAdd = true
+			}
+			existAddDataMap[currentDateStr] = currentDateStr
+		} else {
+			existValDecimal, err := decimal.NewFromString(existVal)
+			existStr := existValDecimal.String()
+			if existStr != val {
+				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+				sql = fmt.Sprintf(sql, dataTableName)
+				_, err = to.Raw(sql, val, edbInfoId, currentDateStr).Exec()
+				if err != nil {
+					return err
+				}
+			}
+		}
+	}
 
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-								}
-								existAddDataMap[av] = av
-							} else {
-								existValDecimal, err := decimal.NewFromString(existVal)
-								existStr := existValDecimal.String()
-								if existStr != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return err
-									}
-								}
-							}
-							break
-						} else {
-							if i >= 1 {
-								preDateDay = preDateDay.AddDate(0, 0, -i)
-								preDateDayStr = preDateDay.Format(utils.FormatDate)
-							}
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-								timestamp := currentDate.UnixNano() / 1e6
-								timestampStr := fmt.Sprintf("%d", timestamp)
-								val := TbzDiv(currentItem.Value, findItem.Value)
+	//删除已经不存在的指标数据(由于该指标当日的数据删除了)
+	{
+		removeDateList := make([]string, 0)
+		for dateTime := range removeDataTimeMap {
+			removeDateList = append(removeDateList, dateTime)
+		}
+		removeNum := len(removeDateList)
+		if removeNum > 0 {
+			//如果拼接指标变更了,那么需要删除所有的指标数据
+			sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (`+utils.GetOrmInReplace(removeNum)+`) `, dataTableName)
 
-								if existVal, ok := existDataMap[av]; !ok {
-									if _, existOk := existAddDataMap[av]; !existOk {
-										addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-										isAdd = true
-									}
-									existAddDataMap[av] = av
-								} else {
-									existValDecimal, err := decimal.NewFromString(existVal)
-									existStr := existValDecimal.String()
-									if existStr != val {
-										sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-										sql = fmt.Sprintf(sql, dataTableName)
-										_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-										if err != nil {
-											return err
-										}
-									}
-								}
-								break
-							}
-						}
-					}
-				}
+			_, err = to.Raw(sql, edbInfoId, removeDateList).Exec()
+			if err != nil {
+				err = fmt.Errorf("删除自有数据的明细数据失败,Err:" + err.Error())
+				return
 			}
 		}
 	}
+
 	if isAdd {
 		addSql = strings.TrimRight(addSql, ",")
 		_, err = to.Raw(addSql).Exec()
@@ -443,6 +312,7 @@ func refreshAllCalculateTbz(to orm.TxOrmer, edbInfoId, source, subSource int, fr
 			return err
 		}
 	}
+
 	return
 }
 

+ 52 - 277
models/predict_edb_data_calculate_tbz.go

@@ -270,22 +270,32 @@ func (obj PredictTb) refresh(to orm.TxOrmer, edbInfo, fromEdbInfo *EdbInfo, edbC
 	edbInfoIdStr := strconv.Itoa(edbInfoId)
 
 	// 获取关联指标数据
-	dataList, err := GetPredictEdbDataListAllByStartDate(fromEdbInfo, 1, startDate)
+	dataList, err := GetPredictEdbDataListAllByStartDate(fromEdbInfo, 0, "")
 	if err != nil {
 		return
 	}
 
-	latestDateStr = fromEdbInfo.LatestDate
-	//计算数据
-	var dateArr []string
-	dataMap := make(map[string]*EdbInfoSearchData)
-	for _, v := range dataList {
-		dateArr = append(dateArr, v.DataTime)
-		dataMap[v.DataTime] = v
+	// 来源指标数据参与计算
+	calculateDataList, err := EdbInfoSearchDataToEdbInfoData(dataList)
+	if err != nil {
+		return
+	}
+	baseCalculate := BaseCalculate{
+		DataList:  calculateDataList,
+		Frequency: fromEdbInfo.Frequency,
+		Source:    3,
+	}
+	dateDataMap, err, _ := baseCalculate.Tbz()
+	if err != nil {
+		return
 	}
+
+	// 真实数据的最后日期
+	latestDateStr = fromEdbInfo.LatestDate
+
 	//获取指标所有数据
 	existDataList := make([]*EdbData, 0)
-	fmt.Println("dataTableName:", dataTableName)
+	//fmt.Println("dataTableName:", dataTableName)
 
 	sql := `SELECT * FROM %s WHERE edb_info_id=? `
 	sql = fmt.Sprintf(sql, dataTableName)
@@ -300,285 +310,50 @@ func (obj PredictTb) refresh(to orm.TxOrmer, edbInfo, fromEdbInfo *EdbInfo, edbC
 		removeDataTimeMap[v.DataTime] = 1
 	}
 
-	fmt.Println("existDataMap:", existDataMap)
+	//fmt.Println("existDataMap:", existDataMap)
 	addSql := ` INSERT INTO edb_data_predict_calculate_tbz (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
 	var isAdd bool
 	existAddDataMap := make(map[string]string)
-	for _, av := range dateArr {
-		//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该日期
-		delete(removeDataTimeMap, av)
 
-		currentItem, ok := dataMap[av]
-		if !ok || currentItem == nil {
-			continue
-		}
+	for currentDate, valFloat := range dateDataMap {
+		currentDateStr := currentDate.Format(utils.FormatDate)
+		timestamp := currentDate.UnixNano() / 1e6
+		timestampStr := fmt.Sprintf("%d", timestamp)
+		val := decimal.NewFromFloat(valFloat).String()
 
-		//当前日期
-		currentDate, tmpErr := time.ParseInLocation(utils.FormatDate, av, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		//上一年的日期
-		preDate := currentDate.AddDate(-1, 0, 0)
-		preDateStr := preDate.Format(utils.FormatDate)
-		if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
-			//dataTime, _ := time.ParseInLocation(utils.FormatDate, date, time.Local)
-			timestamp := currentDate.UnixNano() / 1e6
-			timestampStr := fmt.Sprintf("%d", timestamp)
-			val := TbzDiv(currentItem.Value, findItem.Value)
-
-			if existVal, ok := existDataMap[av]; !ok {
-				if _, existOk := existAddDataMap[av]; !existOk {
-					addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-					isAdd = true
+		//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该日期
+		delete(removeDataTimeMap, currentDateStr)
 
-					// 实际数据的值
-					if fromEdbInfo.LatestDate == av {
-						latestValueDecimal, tmpErr := decimal.NewFromString(val)
-						if tmpErr != nil {
-							return
-						}
-						latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-					}
-				}
-				existAddDataMap[av] = av
-			} else {
-				existValDecimal, tmpErr := decimal.NewFromString(existVal)
-				if tmpErr != nil {
-					err = tmpErr
-					return
-				}
-				existStr := existValDecimal.String()
-				if existStr != val {
-					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-					sql = fmt.Sprintf(sql, dataTableName)
-					_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-					if err != nil {
-						return
-					}
-				}
+		if existVal, ok := existDataMap[currentDateStr]; !ok {
+			if _, existOk := existAddDataMap[currentDateStr]; !existOk {
+				addSql += GetAddSql(edbInfoIdStr, edbCode, currentDateStr, timestampStr, val)
+				isAdd = true
 			}
-			continue
+			existAddDataMap[currentDateStr] = currentDateStr
 		} else {
-			if fromEdbInfo.Frequency == "月度" { //向上和向下,各找一个月
-				for i := 0; i <= 35; i++ {
-					nextDateDay := preDate.AddDate(0, 0, i)
-					nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-					if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TbzDiv(currentItem.Value, findItem.Value)
-
-						if existVal, ok := existDataMap[av]; !ok {
-							if _, existOk := existAddDataMap[av]; !existOk {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-
-								// 实际数据的值
-								if fromEdbInfo.LatestDate == av {
-									latestValueDecimal, tmpErr := decimal.NewFromString(val)
-									if tmpErr != nil {
-										return
-									}
-									latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-								}
-							}
-							existAddDataMap[av] = av
-						} else {
-							existValDecimal, tmpErr := decimal.NewFromString(existVal)
-							if tmpErr != nil {
-								err = tmpErr
-								return
-							}
-							existStr := existValDecimal.String()
-							if existStr != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-								if err != nil {
-									return
-								}
-							}
-						}
-						break
-					} else {
-						preDateDay := preDate.AddDate(0, 0, -i)
-						preDateDayStr := preDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
-
-									// 实际数据的值
-									if fromEdbInfo.LatestDate == av {
-										latestValueDecimal, tmpErr := decimal.NewFromString(val)
-										if tmpErr != nil {
-											return
-										}
-										latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-									}
-								}
-								existAddDataMap[av] = av
-							} else {
-								existValDecimal, tmpErr := decimal.NewFromString(existVal)
-								if tmpErr != nil {
-									err = tmpErr
-									return
-								}
-								existStr := existValDecimal.String()
-								if existStr != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return
-									}
-								}
-							}
-							break
-						}
-					}
-				}
-			} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-				if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
-					timestamp := currentDate.UnixNano() / 1e6
-					timestampStr := fmt.Sprintf("%d", timestamp)
-					val := TbzDiv(currentItem.Value, findItem.Value)
-
-					if existVal, ok := existDataMap[av]; !ok {
-						if _, existOk := existAddDataMap[av]; !existOk {
-							addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-							isAdd = true
-
-							// 实际数据的值
-							if fromEdbInfo.LatestDate == av {
-								latestValueDecimal, tmpErr := decimal.NewFromString(val)
-								if tmpErr != nil {
-									return
-								}
-								latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-							}
-						}
-						existAddDataMap[av] = av
-					} else {
-						existValDecimal, tmpErr := decimal.NewFromString(existVal)
-						if tmpErr != nil {
-							err = tmpErr
-							return
-						}
-						existStr := existValDecimal.String()
-						if existStr != val {
-							sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-							sql = fmt.Sprintf(sql, dataTableName)
-							_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-							if err != nil {
-								return
-							}
-						}
-					}
-					break
+			existValDecimal, tmpErr := decimal.NewFromString(existVal)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+			existStr := existValDecimal.String()
+			if existStr != val {
+				sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+				sql = fmt.Sprintf(sql, dataTableName)
+				_, err = to.Raw(sql, val, edbInfoId, currentDateStr).Exec()
+				if err != nil {
+					return
 				}
-			} else {
-				nextDateDay := preDate.AddDate(0, 0, 1)
-				nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-
-				preDateDay := preDate.AddDate(0, 0, -1)
-				preDateDayStr := preDateDay.Format(utils.FormatDate)
-
-				for i := 0; i < 35; i++ {
-					if i >= 1 {
-						nextDateDay = nextDateDay.AddDate(0, 0, i)
-						nextDateDayStr = nextDateDay.Format(utils.FormatDate)
-					}
-					if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
-						timestamp := currentDate.UnixNano() / 1e6
-						timestampStr := fmt.Sprintf("%d", timestamp)
-						val := TbzDiv(currentItem.Value, findItem.Value)
-
-						if existVal, ok := existDataMap[av]; !ok {
-							if _, existOk := existAddDataMap[av]; !existOk {
-								addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-								isAdd = true
-
-								// 实际数据的值
-								if fromEdbInfo.LatestDate == av {
-									latestValueDecimal, tmpErr := decimal.NewFromString(val)
-									if tmpErr != nil {
-										return
-									}
-									latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-								}
-							}
-							existAddDataMap[av] = av
-						} else {
-							existValDecimal, tmpErr := decimal.NewFromString(existVal)
-							if tmpErr != nil {
-								err = tmpErr
-								return
-							}
-							existStr := existValDecimal.String()
-							if existStr != val {
-								sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-								sql = fmt.Sprintf(sql, dataTableName)
-								_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-								if err != nil {
-									return
-								}
-							}
-						}
-						break
-					} else {
-						if i >= 1 {
-							preDateDay = preDateDay.AddDate(0, 0, -i)
-							preDateDayStr = preDateDay.Format(utils.FormatDate)
-						}
-						if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
-							timestamp := currentDate.UnixNano() / 1e6
-							timestampStr := fmt.Sprintf("%d", timestamp)
-							val := TbzDiv(currentItem.Value, findItem.Value)
-
-							if existVal, ok := existDataMap[av]; !ok {
-								if _, existOk := existAddDataMap[av]; !existOk {
-									addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, val)
-									isAdd = true
+			}
+		}
 
-									// 实际数据的值
-									if fromEdbInfo.LatestDate == av {
-										latestValueDecimal, tmpErr := decimal.NewFromString(val)
-										if tmpErr != nil {
-											return
-										}
-										latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
-									}
-								}
-								existAddDataMap[av] = av
-							} else {
-								existValDecimal, tmpErr := decimal.NewFromString(existVal)
-								if tmpErr != nil {
-									err = tmpErr
-									return
-								}
-								existStr := existValDecimal.String()
-								if existStr != val {
-									sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
-									sql = fmt.Sprintf(sql, dataTableName)
-									_, err = to.Raw(sql, val, edbInfoId, av).Exec()
-									if err != nil {
-										return
-									}
-								}
-							}
-							break
-						}
-					}
-				}
+		// 实际数据的值
+		if fromEdbInfo.LatestDate == currentDateStr {
+			latestValueDecimal, tmpErr := decimal.NewFromString(val)
+			if tmpErr != nil {
+				return
 			}
+			latestValue, _ = latestValueDecimal.Truncate(4).Float64() //保留4位小数
 		}
 	}