瀏覽代碼

Merge branch 'bug/4556' into debug

# Conflicts:
#	models/edb_data_base.go
Roc 10 月之前
父節點
當前提交
91682c6266
共有 3 個文件被更改,包括 52 次插入0 次删除
  1. 13 0
      models/edb_data_base.go
  2. 20 0
      models/edb_data_calculate_time_shift.go
  3. 19 0
      models/predict_edb_data_calculate_time_shift.go

+ 13 - 0
models/edb_data_base.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_index_lib/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"strings"
 	"time"
 )
 
@@ -236,3 +237,15 @@ type EditEdbBaseInfoReq struct {
 	UnitEn          string `description:"英文单位"`
 	ClassifyId      int    `description:"分类id"`
 }
+
+func DelEdbDataByMysql(to orm.TxOrmer, edbInfoId int, tableName string, removeDateList []string) (err error) {
+	if len(removeDateList) <= 0 {
+		return
+	}
+	// 移除不存在的日期数据
+	removeDateStr := strings.Join(removeDateList, `","`)
+	removeDateStr = `"` + removeDateStr + `"`
+	sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
+	_, err = to.Raw(sql, edbInfoId).Exec()
+	return
+}

+ 20 - 0
models/edb_data_calculate_time_shift.go

@@ -269,9 +269,12 @@ func refreshAllCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subSource,
 	if err != nil {
 		return err
 	}
+
 	existDataMap := make(map[string]string)
+	removeDateMap := make(map[string]string)
 	for _, v := range existDataList {
 		existDataMap[v.DataTime] = v.Value
+		removeDateMap[v.DataTime] = ``
 	}
 	fmt.Println("existDataMap:", existDataMap)
 	addSql := ` INSERT INTO edb_data_calculate_time_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
@@ -305,6 +308,9 @@ func refreshAllCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subSource,
 					}
 				}
 			}
+
+			// 指标已存在,那么就移除该日期
+			delete(removeDateMap, newDate.Format(utils.FormatDate))
 		}
 		existMap[existKey] = currentItem.DataTime
 	}
@@ -316,5 +322,19 @@ func refreshAllCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subSource,
 			return err
 		}
 	}
+
+	// 移除不存在的日期数据
+	if len(removeDateMap) > 0 {
+		removeDateList := make([]string, 0) //需要移除的日期
+		for k := range removeDateMap {
+			removeDateList = append(removeDateList, k)
+		}
+		err = DelEdbDataByMysql(to, edbInfoId, dataTableName, removeDateList)
+		if err != nil {
+			err = fmt.Errorf("删除年化指标数据失败,Err:" + err.Error())
+			return
+		}
+	}
+
 	return
 }

+ 19 - 0
models/predict_edb_data_calculate_time_shift.go

@@ -241,7 +241,9 @@ func refreshAllPredictCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subS
 	if err != nil {
 		return
 	}
+
 	existDataMap := make(map[string]string)
+	removeDateMap := make(map[string]string)
 	for _, v := range existDataList {
 		existDataMap[v.DataTime] = v.Value
 	}
@@ -284,6 +286,9 @@ func refreshAllPredictCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subS
 					}
 				}
 			}
+
+			// 指标已存在,那么就移除该日期
+			delete(removeDateMap, newDate.Format(utils.FormatDate))
 		}
 		existMap[existKey] = currentItem.DataTime
 	}
@@ -295,5 +300,19 @@ func refreshAllPredictCalculateTimeShift(to orm.TxOrmer, edbInfoId, source, subS
 			return
 		}
 	}
+	
+	// 移除不存在的日期数据
+	if len(removeDateMap) > 0 {
+		removeDateList := make([]string, 0) //需要移除的日期
+		for k := range removeDateMap {
+			removeDateList = append(removeDateList, k)
+		}
+		err = DelEdbDataByMysql(to, edbInfoId, dataTableName, removeDateList)
+		if err != nil {
+			err = fmt.Errorf("删除年化指标数据失败,Err:" + err.Error())
+			return
+		}
+	}
+
 	return
 }