Browse Source

Merge branch 'feature/eta1.5.7_edb_replace' into debug

xyxie 10 months ago
parent
commit
59475c79c9

+ 22 - 0
cache/replace_edb_info.go

@@ -0,0 +1,22 @@
+package cache
+
+import (
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/utils"
+	"fmt"
+)
+
+// 将替换指标操作加入到队列中
+func AddReplaceEdbInfo(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) bool {
+	record := new(data_manage.ReplaceEdbInfoItem)
+	record.OldEdbInfo = oldEdbInfo
+	record.NewEdbInfo = newEdbInfo
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CACHE_KEY_REPLACE_EDB, record)
+		if err != nil {
+			fmt.Println("AdminOperateRecord LPush Err:" + err.Error())
+		}
+		return true
+	}
+	return false
+}

+ 3 - 21
controllers/data_manage/edb_info.go

@@ -2,6 +2,7 @@ package data_manage
 
 import (
 	"encoding/json"
+	"eta/eta_api/cache"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
@@ -19,7 +20,6 @@ import (
 	"eta/eta_api/services/data_stat"
 	"eta/eta_api/services/elastic"
 	etaTrialService "eta/eta_api/services/eta_trial"
-	"eta/eta_api/services/sandbox"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -3908,26 +3908,8 @@ func (this *ChartInfoController) EdbInfoReplace() {
 		return
 	}
 
-	// 替换相关性图表配置
-	//go func() {
-	_, _ = data_manage.ReplaceMultipleGraphConfigChartEdb(oldEdbInfo, newEdbInfo)
-	/*if err != nil {
-		br.Msg = "替换失败"
-		br.ErrMsg = "替换失败 replace err:" + err.Error()
-		return
-	}*/
-	//}()
-
-	// 替换拟合方程指标
-	_, _ = data_manage.ReplaceEdbInfoInLineEquationMultipleGraphConfig(oldEdbInfo, newEdbInfo)
-
-	//go func() {
-	excel2.ReplaceEdbInExcel(oldEdbInfo, newEdbInfo)
-	//}()
-
-	//go func() {
-	sandbox.ReplaceEdbInSandbox(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
-	//}()
+	//加入到缓存队列中处理
+	go cache.AddReplaceEdbInfo(oldEdbInfo, newEdbInfo)
 	br.Msg = "替换成功"
 	br.ErrMsg = "替换成功"
 	br.Ret = 200

+ 5 - 0
models/data_manage/edb_info.go

@@ -1682,3 +1682,8 @@ func getAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (
 
 	return
 }
+
+type ReplaceEdbInfoItem struct {
+	OldEdbInfo *EdbInfo
+	NewEdbInfo *EdbInfo
+}

+ 40 - 0
models/data_manage/excel/request/time_table.go

@@ -0,0 +1,40 @@
+package request
+
+// TimeTableDataConfig
+// @Description: 表格配置
+type TimeTableDataConfig struct {
+	EdbInfoIdList    []int                 `description:"指标id列表,从左至右,从上到下的顺序"`
+	Sort             int                   `description:"日期排序,0:倒序,1:正序"`
+	Data             []TimeTableManualData `description:"数据列表"`
+	Num              int                   `description:"实际数据需要列出来的期数"`
+	RemoveDate       []string              `description:"不展示的日期"`
+	ManualDate       []string              `description:"手动配置的日期(未来的日期)"`
+	TableEdbInfoList []TimeTableEdbInfo    `description:"表格内指标信息"`
+	TextRowData      [][]ManualDataReq     `description:"文本列表"`
+}
+
+// TimeTableEdbInfo
+// @Description: 表格指标信息
+type TimeTableEdbInfo struct {
+	EdbInfoId    int    `description:"指标ID"`
+	Tag          string `description:"标签"`
+	EdbName      string `description:"指标名称"`
+	EdbNameEn    string `description:"英文指标名称"`
+	EdbAliasName string `description:"指标别名"`
+	Frequency    string `description:"频度"`
+	Unit         string `description:"单位"`
+	UnitEn       string `description:"英文单位"`
+}
+
+// ManualData
+// @Description: 手工文本配置
+type TimeTableManualData struct {
+	DataType            int               `description:"数据类型,1:普通的,2:插值法,3:手动输入,4:公式计算"`
+	DataTime            string            `description:"所属日期"`
+	DataTimeType        int               `description:"日期类型,1:实际日期;2:未来日期"`
+	ShowValue           string            `description:"展示值"`
+	Value               string            `description:"实际值(计算公式)"`
+	EdbInfoId           int               `description:"指标id"`
+	Tag                 string            `description:"下标"`
+	RelationEdbInfoList []RelationEdbInfo `description:"关联指标(计算公式中关联的指标,用于计算的时候去匹配)"`
+}

+ 2 - 2
models/data_manage/multiple_graph_config.go

@@ -162,7 +162,7 @@ func ReplaceEdbInfoInLineEquationMultipleGraphConfig(oldEdbInfo, newEdbInfo *Edb
 			updateList = append(updateList, mv)
 			configIds = append(configIds, mv.MultipleGraphConfigId)
 			configIdStr = append(configIdStr, strconv.Itoa(mv.MultipleGraphConfigId))
-			if len(updateList) >= 10 {
+			if len(configIds) >= 10 {
 				numStr := utils.GetOrmInReplace(len(configIds))
 				// 准备批量更新的 SQL 语句
 				updateSQL := `UPDATE multiple_graph_config SET   
@@ -183,7 +183,7 @@ func ReplaceEdbInfoInLineEquationMultipleGraphConfig(oldEdbInfo, newEdbInfo *Edb
 				configIdStr = make([]string, 0)
 			}
 		}
-		if len(configIds) >= 0 {
+		if len(configIds) > 0 {
 			numStr := utils.GetOrmInReplace(len(configIds))
 			// 准备批量更新的 SQL 语句
 			updateSQL := `UPDATE multiple_graph_config SET   

+ 0 - 180
services/data/excel/excel_info.go

@@ -8,7 +8,6 @@ import (
 	"eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/data_manage/excel/response"
 	"eta/eta_api/models/system"
-	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/data"
 	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/utils"
@@ -528,182 +527,3 @@ func GetExcelEdbBatchRefreshKey(source string, primaryId, subId int) string {
 
 	return fmt.Sprint("batch_refresh_excel_edb:", source, ":", primaryId, ":", subId)
 }
-
-// ReplaceEdbInExcel 替换表格中的指标
-func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (err error) {
-	defer func() {
-		if err != nil {
-			go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errmsg:"+err.Error(), 3)
-		}
-	}()
-	//查询和指标相关的 表格
-	mappingList, err := excel.GetExcelEdbMappingByEdbInfoId(oldEdbInfo.EdbInfoId)
-	if err != nil {
-		err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", err.Error())
-		return
-	}
-	updateList := make([]*excel.ExcelInfo, 0)
-	// 循环列表,根据表格类型单独处理
-	for _, excelMapping := range mappingList {
-		//查询和指标相关的混合表格
-		excelInfo, tmpErr := excel.GetExcelInfoById(excelMapping.ExcelInfoId)
-		if tmpErr != nil {
-			err = fmt.Errorf("查询和指标相关的混合表格失败,错误:%s", tmpErr.Error())
-			return
-		}
-		// 清除缓存
-		key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode
-		if utils.Re == nil {
-			_ = utils.Rc.Delete(key)
-		}
-		// 根据表格类型,调用不同的处理函数
-		switch excelMapping.Source {
-		case utils.TIME_TABLE: // 时间序列表格
-			// 替换余额表格中的指标
-			newExcelInfo, e := replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo, excelInfo)
-			if e != nil {
-				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
-				return
-			}
-			updateList = append(updateList, newExcelInfo)
-		case utils.MIXED_TABLE, utils.BALANCE_TABLE:
-			// 替换余额表格中的指标
-			newExcelInfo, e := replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo, excelInfo)
-			if e != nil {
-				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
-				return
-			}
-			updateList = append(updateList, newExcelInfo)
-		default:
-			// 其他表格类型的处理逻辑
-		}
-	}
-
-	err = excel.ReplaceEdbInExcel(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, updateList)
-	if err != nil {
-		err = fmt.Errorf("替换表格中的指标失败,错误:%s", err.Error())
-		return
-	}
-
-	//todo 是否需要刷新表格中的指标数据
-	return
-}
-
-func replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excel.ExcelInfo) (newExcelInfo *excel.ExcelInfo, err error) {
-	newExcelInfo = excelInfo
-	var mixedTableReq request.MixedTableReq
-	err = json.Unmarshal([]byte(excelInfo.Content), &mixedTableReq)
-	if err != nil {
-		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
-		return
-	}
-	// 处理data
-	configList := mixedTableReq.Data
-	for ck, rowList := range configList {
-		for rk, cell := range rowList {
-			switch cell.DataType {
-			case request.EdbDT: // 指标信息
-				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
-					//更换成新指标ID
-					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
-				}
-			case request.InsertDataDT, request.PopInsertDataDT: // 插值、弹框插值
-				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
-					//更换成新指标ID
-					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
-				}
-			case request.InsertEdbCalculateDataDT: // 插入指标计算公式生成的值
-				var config request.CalculateConf
-				err = json.Unmarshal([]byte(cell.Value), &config)
-				if err != nil {
-					return
-				}
-				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
-					//更换成新指标ID
-					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
-				}
-				if config.EdbInfoId == oldEdbInfo.EdbInfoId {
-					config.EdbInfoId = newEdbInfo.EdbInfoId
-					var configStr []byte
-					configStr, err = json.Marshal(config)
-					if err != nil {
-						return
-					}
-					configList[ck][rk].Value = string(configStr)
-				}
-
-			case request.DateDT: // 日期类型
-				// 指标日期类型的单元格需要额外将指标id取出来
-				if cell.DataTimeType == request.EdbDateDT {
-					var config request.EdbDateConf
-					err = json.Unmarshal([]byte(cell.Value), &config)
-					if err != nil {
-						return
-					}
-					if config.EdbInfoId == oldEdbInfo.EdbInfoId {
-						config.EdbInfoId = newEdbInfo.EdbInfoId
-						var configStr []byte
-						configStr, err = json.Marshal(config)
-						if err != nil {
-							return
-						}
-						configList[ck][rk].Value = string(configStr)
-					}
-				}
-			}
-		}
-	}
-
-	mixedTableReq.Data = configList
-	var newContentByte []byte
-	newContentByte, err = json.Marshal(mixedTableReq)
-	if err != nil {
-		return
-	}
-	// 生成的新内容替换原先的旧内容
-	excelInfo.Content = string(newContentByte)
-	newExcelInfo = excelInfo
-	return
-}
-
-func replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excel.ExcelInfo) (newExcelInfo *excel.ExcelInfo, err error) {
-	newExcelInfo = excelInfo
-
-	var tableDataConfig TableDataConfig
-	err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
-	if err != nil {
-		err = errors.New("表格json转结构体失败,Err:" + err.Error())
-		return
-	}
-	if len(tableDataConfig.EdbInfoIdList) <= 0 {
-		return
-	}
-	// 实际期数没有的情况下,直接返回吧
-	if tableDataConfig.Num <= 0 {
-		return
-	}
-
-	// 先处理edbInfoList
-	for k, id := range tableDataConfig.EdbInfoIdList {
-		if id == oldEdbInfo.EdbInfoId {
-			tableDataConfig.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
-		}
-	}
-
-	// 先处理tableEdbInfoList
-	for k, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
-		if tableEdbInfo.EdbInfoId == oldEdbInfo.EdbInfoId {
-			tableDataConfig.TableEdbInfoList[k].EdbInfoId = newEdbInfo.EdbInfoId
-		}
-	}
-
-	var newContentByte []byte
-	newContentByte, err = json.Marshal(tableDataConfig)
-	if err != nil {
-		return
-	}
-	// 生成的新内容替换原先的旧内容
-	excelInfo.Content = string(newContentByte)
-	newExcelInfo = excelInfo
-	return
-}

+ 254 - 0
services/edb_info_global.go

@@ -0,0 +1,254 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_api/models/data_manage"
+	excelModel "eta/eta_api/models/data_manage/excel"
+	"eta/eta_api/models/data_manage/excel/request"
+	"eta/eta_api/services/alarm_msg"
+	"eta/eta_api/services/sandbox"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// 全局的指标替换
+func DealReplaceEdbCache() {
+	var err error
+	for {
+		utils.Rc.Brpop(utils.CACHE_KEY_REPLACE_EDB, func(b []byte) {
+			defer func() {
+				if err != nil {
+					utils.FileLog.Info("DealReplaceEdbCache err:" + err.Error())
+					go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errmsg:"+err.Error(), 3)
+				}
+			}()
+			record := new(data_manage.ReplaceEdbInfoItem)
+			if err = json.Unmarshal(b, &record); err != nil {
+				fmt.Println("json unmarshal wrong!")
+				return
+			}
+			oldEdbInfo := record.OldEdbInfo
+			newEdbInfo := record.NewEdbInfo
+			deleteCache := true
+			setNxKey := fmt.Sprintf("EDB_INFO_REPLACE:%d-%d", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
+			defer func() {
+				if deleteCache {
+					utils.Rc.Delete(setNxKey)
+				}
+			}()
+			if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
+				deleteCache = false
+				err = fmt.Errorf("替换表格中的指标失败旧指标:%d为新指标%d:正在处理中", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
+				return
+			}
+
+			// 替换相关性图表配置
+			_, err = data_manage.ReplaceMultipleGraphConfigChartEdb(oldEdbInfo, newEdbInfo)
+			if err != nil {
+				err = fmt.Errorf("替换相关性图表配置失败,errmsg:%s", err.Error())
+				return
+			}
+			// 替换拟合方程指标
+			_, err = data_manage.ReplaceEdbInfoInLineEquationMultipleGraphConfig(oldEdbInfo, newEdbInfo)
+			if err != nil {
+				err = fmt.Errorf("替换拟合方程指标失败,errmsg:%s", err.Error())
+				return
+			}
+
+			// 替换表格中的指标
+			err = ReplaceEdbInExcel(oldEdbInfo, newEdbInfo)
+			if err != nil {
+				err = fmt.Errorf("替换表格中的指标失败,errmsg:%s", err.Error())
+				return
+			}
+
+			//替换逻辑图中的指标
+			err = sandbox.ReplaceEdbInSandbox(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
+			if err != nil {
+				err = fmt.Errorf("替换逻辑图中的指标失败,errmsg:%s", err.Error())
+				return
+			}
+		})
+	}
+}
+
+// ReplaceEdbInExcel 替换表格中的指标
+func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (err error) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errmsg:"+err.Error(), 3)
+		}
+	}()
+	//查询和指标相关的 表格
+	mappingList, err := excelModel.GetExcelEdbMappingByEdbInfoId(oldEdbInfo.EdbInfoId)
+	if err != nil {
+		err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", err.Error())
+		return
+	}
+	updateList := make([]*excelModel.ExcelInfo, 0)
+	// 循环列表,根据表格类型单独处理
+	for _, excelMapping := range mappingList {
+		//查询和指标相关的混合表格
+		excelInfo, tmpErr := excelModel.GetExcelInfoById(excelMapping.ExcelInfoId)
+		if tmpErr != nil {
+			err = fmt.Errorf("查询和指标相关的混合表格失败,错误:%s", tmpErr.Error())
+			return
+		}
+		// 清除缓存
+		key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode
+		if utils.Re == nil {
+			_ = utils.Rc.Delete(key)
+		}
+		// 根据表格类型,调用不同的处理函数
+		switch excelMapping.Source {
+		case utils.TIME_TABLE: // 时间序列表格
+			// 替换余额表格中的指标
+			newExcelInfo, e := replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo, excelInfo)
+			if e != nil {
+				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
+				return
+			}
+			updateList = append(updateList, newExcelInfo)
+		case utils.MIXED_TABLE, utils.BALANCE_TABLE:
+			// 替换余额表格中的指标
+			newExcelInfo, e := replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo, excelInfo)
+			if e != nil {
+				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
+				return
+			}
+			updateList = append(updateList, newExcelInfo)
+		default:
+			// 其他表格类型的处理逻辑
+		}
+	}
+
+	err = excelModel.ReplaceEdbInExcel(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, updateList)
+	if err != nil {
+		err = fmt.Errorf("替换表格中的指标失败,错误:%s", err.Error())
+		return
+	}
+
+	//todo 是否需要刷新表格中的指标数据
+	return
+}
+
+func replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excelModel.ExcelInfo) (newExcelInfo *excelModel.ExcelInfo, err error) {
+	newExcelInfo = excelInfo
+	var mixedTableReq request.MixedTableReq
+	err = json.Unmarshal([]byte(excelInfo.Content), &mixedTableReq)
+	if err != nil {
+		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	// 处理data
+	configList := mixedTableReq.Data
+	for ck, rowList := range configList {
+		for rk, cell := range rowList {
+			switch cell.DataType {
+			case request.EdbDT: // 指标信息
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+			case request.InsertDataDT, request.PopInsertDataDT: // 插值、弹框插值
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+			case request.InsertEdbCalculateDataDT: // 插入指标计算公式生成的值
+				var config request.CalculateConf
+				err = json.Unmarshal([]byte(cell.Value), &config)
+				if err != nil {
+					return
+				}
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+				if config.EdbInfoId == oldEdbInfo.EdbInfoId {
+					config.EdbInfoId = newEdbInfo.EdbInfoId
+					var configStr []byte
+					configStr, err = json.Marshal(config)
+					if err != nil {
+						return
+					}
+					configList[ck][rk].Value = string(configStr)
+				}
+
+			case request.DateDT: // 日期类型
+				// 指标日期类型的单元格需要额外将指标id取出来
+				if cell.DataTimeType == request.EdbDateDT {
+					var config request.EdbDateConf
+					err = json.Unmarshal([]byte(cell.Value), &config)
+					if err != nil {
+						return
+					}
+					if config.EdbInfoId == oldEdbInfo.EdbInfoId {
+						config.EdbInfoId = newEdbInfo.EdbInfoId
+						var configStr []byte
+						configStr, err = json.Marshal(config)
+						if err != nil {
+							return
+						}
+						configList[ck][rk].Value = string(configStr)
+					}
+				}
+			}
+		}
+	}
+
+	mixedTableReq.Data = configList
+	var newContentByte []byte
+	newContentByte, err = json.Marshal(mixedTableReq)
+	if err != nil {
+		return
+	}
+	// 生成的新内容替换原先的旧内容
+	excelInfo.Content = string(newContentByte)
+	newExcelInfo = excelInfo
+	return
+}
+
+func replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excelModel.ExcelInfo) (newExcelInfo *excelModel.ExcelInfo, err error) {
+	newExcelInfo = excelInfo
+
+	var tableDataConfig request.TimeTableDataConfig
+	err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
+	if err != nil {
+		err = errors.New("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	if len(tableDataConfig.EdbInfoIdList) <= 0 {
+		return
+	}
+	// 实际期数没有的情况下,直接返回吧
+	if tableDataConfig.Num <= 0 {
+		return
+	}
+
+	// 先处理edbInfoList
+	for k, id := range tableDataConfig.EdbInfoIdList {
+		if id == oldEdbInfo.EdbInfoId {
+			tableDataConfig.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
+		}
+	}
+
+	// 先处理tableEdbInfoList
+	for k, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
+		if tableEdbInfo.EdbInfoId == oldEdbInfo.EdbInfoId {
+			tableDataConfig.TableEdbInfoList[k].EdbInfoId = newEdbInfo.EdbInfoId
+		}
+	}
+
+	var newContentByte []byte
+	newContentByte, err = json.Marshal(tableDataConfig)
+	if err != nil {
+		return
+	}
+	// 生成的新内容替换原先的旧内容
+	excelInfo.Content = string(newContentByte)
+	newExcelInfo = excelInfo
+	return
+}

+ 7 - 3
services/sandbox/sandbox.go

@@ -856,11 +856,16 @@ func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *s
 }
 
 func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
+	updateTotal := 0
+	logMsg := ""
 	//分页处理沙盘表
 	defer func() {
 		if err != nil {
 			go alarm_msg.SendAlarmMsg("替换沙盘中的指标记录失败提醒,errmsg:"+err.Error(), 3)
 		}
+		if logMsg != "" {
+			utils.FileLog.Info(fmt.Sprintf("替换ETA逻辑的指标记录,替换总数:%d,旧的指标id:%d,新的指标id:%d;%s", updateTotal, oldEdbInfoId, newEdbInfoId, logMsg))
+		}
 	}()
 	//查询沙盘总数
 	total, err := sandbox.GetSandboxListCountByCondition("", []interface{}{})
@@ -873,8 +878,7 @@ func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
 	// 计算总页数
 	totalPage := (total + 99) / 100 // 使用整数除法,并添加一页以防有余数
 	updateSandBox := make([]sandbox.Sandbox, 0)
-	updateTotal := 0
-	logMsg := ""
+
 	//查询沙盘列表
 	for i := 0; i < totalPage; i += 1 {
 		startSize := i * 100
@@ -910,6 +914,6 @@ func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
 		}
 		updateTotal += len(updateSandBox)
 	}
-	utils.FileLog.Info(fmt.Sprintf("替换ETA逻辑的指标记录,替换总数:%d,旧的指标id:%d,新的指标id:%d;%s", updateTotal, oldEdbInfoId, newEdbInfoId, logMsg))
+
 	return
 }

+ 3 - 0
services/task.go

@@ -43,6 +43,9 @@ func Task() {
 	// 指标刷新
 	go data.HandleEdbRefreshQueue()
 
+	// 进行指标替换操作
+	go DealReplaceEdbCache()
+
 	// TODO:修复权限
 	//FixEnCompanyPermission()
 	fmt.Println("task end")

+ 2 - 0
utils/constants.go

@@ -232,6 +232,8 @@ const (
 
 	CACHE_CREATE_REPORT_IMGPDF_QUEUE = "eta_report:report_img_pdf_queue" // 生成报告长图PDF队列
 	CACHE_EDB_TERMINAL_CODE_URL      = "edb:terminal_code:edb_code:"     // 指标与终端关系的缓存
+
+	CACHE_KEY_REPLACE_EDB = "eta:replace_edb" //系统用户操作日志队列
 )
 
 // 模板消息推送类型