edb_info_replace.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/models/data_manage"
  6. excelModel "eta_gn/eta_api/models/data_manage/excel"
  7. "eta_gn/eta_api/models/data_manage/excel/request"
  8. "eta_gn/eta_api/services/alarm_msg"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/services/sandbox"
  11. "eta_gn/eta_api/utils"
  12. "fmt"
  13. "strconv"
  14. "time"
  15. )
  16. // 全局的指标替换
  17. func DealReplaceEdbCache() {
  18. var err error
  19. for {
  20. utils.Rc.Brpop(utils.CACHE_KEY_REPLACE_EDB, func(b []byte) {
  21. defer func() {
  22. if err != nil {
  23. utils.FileLog.Info("DealReplaceEdbCache err:" + err.Error())
  24. go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errmsg:"+err.Error(), 3)
  25. }
  26. }()
  27. record := new(data_manage.ReplaceEdbInfoItem)
  28. if err = json.Unmarshal(b, &record); err != nil {
  29. fmt.Println("json unmarshal wrong!")
  30. return
  31. }
  32. oldEdbInfo := record.OldEdbInfo
  33. newEdbInfo := record.NewEdbInfo
  34. userId := record.UserId
  35. utils.FileLog.Info(fmt.Sprintf("指标开始替换 DealReplaceEdbCache: 旧指标ID:%d,新指标ID:%d,所属用户:%d", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, userId))
  36. deleteCache := true
  37. setNxKey := fmt.Sprintf("EDB_INFO_REPLACE:%d-%d-%d", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, userId)
  38. defer func() {
  39. if deleteCache {
  40. utils.Rc.Delete(setNxKey)
  41. }
  42. }()
  43. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  44. deleteCache = false
  45. err = fmt.Errorf("替换表格中的指标失败旧指标:%d为新指标%d:正在处理中", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
  46. return
  47. }
  48. // 替换相关性图表配置
  49. _, err = data_manage.ReplaceMultipleGraphConfigChartEdb(oldEdbInfo, newEdbInfo, userId)
  50. if err != nil {
  51. err = fmt.Errorf("替换相关性图表配置失败,errmsg:%s", err.Error())
  52. return
  53. }
  54. // 替换拟合方程指标
  55. _, err = data_manage.ReplaceEdbInfoInLineEquationMultipleGraphConfig(oldEdbInfo, newEdbInfo, userId)
  56. if err != nil {
  57. err = fmt.Errorf("替换拟合方程指标失败,errmsg:%s", err.Error())
  58. return
  59. }
  60. // 替换表格中的指标
  61. err = ReplaceEdbInExcel(oldEdbInfo, newEdbInfo, userId)
  62. if err != nil {
  63. err = fmt.Errorf("替换表格中的指标失败,errmsg:%s", err.Error())
  64. return
  65. }
  66. //替换逻辑图中的指标
  67. err = sandbox.ReplaceEdbInSandbox(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, userId)
  68. if err != nil {
  69. err = fmt.Errorf("替换逻辑图中的指标失败,errmsg:%s", err.Error())
  70. return
  71. }
  72. // todo 重置指标引用表
  73. // TODO 只是替换部分指标,该怎么处理 ---- Roc
  74. ReplaceEdbInRelation(oldEdbInfo, newEdbInfo)
  75. })
  76. }
  77. }
  78. // ReplaceEdbInExcel 替换表格中的指标
  79. func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, userId int) (err error) {
  80. defer func() {
  81. if err != nil {
  82. go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errMsg:"+err.Error(), 3)
  83. }
  84. }()
  85. //查询和指标相关的时间序列表格和混合表格
  86. mappingList, err := excelModel.GetUserExcelEdbMappingByEdbInfoIdAndSource(userId, oldEdbInfo.EdbInfoId, []int{utils.TIME_TABLE, utils.MIXED_TABLE})
  87. if err != nil {
  88. err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", err.Error())
  89. return
  90. }
  91. updateList := make([]*excelModel.ExcelInfo, 0)
  92. // 循环列表,根据表格类型单独处理
  93. for _, excelMapping := range mappingList {
  94. //查询和指标相关的混合表格
  95. excelInfo, tmpErr := excelModel.GetExcelInfoById(excelMapping.ExcelInfoId)
  96. if tmpErr != nil {
  97. err = fmt.Errorf("查询和指标相关的混合表格失败,错误:%s", tmpErr.Error())
  98. return
  99. }
  100. // 清除缓存
  101. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode
  102. if utils.Re == nil {
  103. _ = utils.Rc.Delete(key)
  104. }
  105. // 根据表格类型,调用不同的处理函数
  106. switch excelMapping.Source {
  107. case utils.TIME_TABLE: // 时间序列表格
  108. // 替换余额表格中的指标
  109. newExcelInfo, e := replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo, excelInfo)
  110. if e != nil {
  111. err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
  112. return
  113. }
  114. updateList = append(updateList, newExcelInfo)
  115. case utils.MIXED_TABLE, utils.BALANCE_TABLE:
  116. // 替换余额表格中的指标
  117. newExcelInfo, e := replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo, excelInfo)
  118. if e != nil {
  119. err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
  120. return
  121. }
  122. updateList = append(updateList, newExcelInfo)
  123. default:
  124. // 其他表格类型的处理逻辑
  125. }
  126. }
  127. err = excelModel.ReplaceEdbInExcel(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, updateList)
  128. if err != nil {
  129. err = fmt.Errorf("替换表格中的指标失败,错误:%s", err.Error())
  130. return
  131. }
  132. //todo 是否需要刷新表格中的指标数据
  133. return
  134. }
  135. func replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excelModel.ExcelInfo) (newExcelInfo *excelModel.ExcelInfo, err error) {
  136. newExcelInfo = excelInfo
  137. var mixedTableReq request.MixedTableReq
  138. err = json.Unmarshal([]byte(excelInfo.Content), &mixedTableReq)
  139. if err != nil {
  140. err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
  141. return
  142. }
  143. // 处理data
  144. configList := mixedTableReq.Data
  145. for ck, rowList := range configList {
  146. for rk, cell := range rowList {
  147. switch cell.DataType {
  148. case request.EdbDT: // 指标信息
  149. if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
  150. //更换成新指标ID
  151. configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
  152. }
  153. case request.InsertDataDT, request.PopInsertDataDT: // 插值、弹框插值
  154. if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
  155. //更换成新指标ID
  156. configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
  157. }
  158. case request.InsertEdbCalculateDataDT: // 插入指标计算公式生成的值
  159. var config request.CalculateConf
  160. err = json.Unmarshal([]byte(cell.Value), &config)
  161. if err != nil {
  162. return
  163. }
  164. if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
  165. //更换成新指标ID
  166. configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
  167. }
  168. if config.EdbInfoId == oldEdbInfo.EdbInfoId {
  169. config.EdbInfoId = newEdbInfo.EdbInfoId
  170. var configStr []byte
  171. configStr, err = json.Marshal(config)
  172. if err != nil {
  173. return
  174. }
  175. configList[ck][rk].Value = string(configStr)
  176. }
  177. case request.DateDT: // 日期类型
  178. // 指标日期类型的单元格需要额外将指标id取出来
  179. if cell.DataTimeType == request.EdbDateDT {
  180. var config request.EdbDateConf
  181. err = json.Unmarshal([]byte(cell.Value), &config)
  182. if err != nil {
  183. return
  184. }
  185. if config.EdbInfoId == oldEdbInfo.EdbInfoId {
  186. config.EdbInfoId = newEdbInfo.EdbInfoId
  187. var configStr []byte
  188. configStr, err = json.Marshal(config)
  189. if err != nil {
  190. return
  191. }
  192. configList[ck][rk].Value = string(configStr)
  193. }
  194. }
  195. }
  196. }
  197. }
  198. mixedTableReq.Data = configList
  199. var newContentByte []byte
  200. newContentByte, err = json.Marshal(mixedTableReq)
  201. if err != nil {
  202. return
  203. }
  204. // 生成的新内容替换原先的旧内容
  205. excelInfo.Content = string(newContentByte)
  206. newExcelInfo = excelInfo
  207. return
  208. }
  209. func replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excelModel.ExcelInfo) (newExcelInfo *excelModel.ExcelInfo, err error) {
  210. newExcelInfo = excelInfo
  211. var tableDataConfig request.TimeTableDataConfig
  212. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  213. if err != nil {
  214. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  215. return
  216. }
  217. if len(tableDataConfig.EdbInfoIdList) <= 0 {
  218. return
  219. }
  220. // 实际期数没有的情况下,直接返回吧
  221. if tableDataConfig.Num <= 0 {
  222. return
  223. }
  224. // 先处理edbInfoList
  225. for k, id := range tableDataConfig.EdbInfoIdList {
  226. if id == oldEdbInfo.EdbInfoId {
  227. tableDataConfig.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
  228. }
  229. }
  230. // 先处理tableEdbInfoList
  231. for k, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
  232. if tableEdbInfo.EdbInfoId == oldEdbInfo.EdbInfoId {
  233. tableDataConfig.TableEdbInfoList[k].EdbInfoId = newEdbInfo.EdbInfoId
  234. }
  235. }
  236. var newContentByte []byte
  237. newContentByte, err = json.Marshal(tableDataConfig)
  238. if err != nil {
  239. return
  240. }
  241. // 生成的新内容替换原先的旧内容
  242. excelInfo.Content = string(newContentByte)
  243. newExcelInfo = excelInfo
  244. return
  245. }
  246. func ReplaceEdbInRelation(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) {
  247. var err error
  248. var logMsg string
  249. var replaceTotal int
  250. defer func() {
  251. if err != nil {
  252. msg := fmt.Sprintf(" 替换指标引用表中的指标,并修改引用时间 replaceEdbInRelation err: %v", err)
  253. utils.FileLog.Info(msg)
  254. fmt.Println(msg)
  255. go alarm_msg.SendAlarmMsg(msg, 3)
  256. }
  257. if logMsg != `` {
  258. utils.FileLog.Info(fmt.Sprintf("替换指标引用表中的指标记录 替换总数%d,旧的指标id:%d,新的指标id:%d;涉及到的引用id:%s", replaceTotal, oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
  259. }
  260. }()
  261. calculateEdbMappingListMap := make(map[int]*data_manage.EdbInfoCalculateMapping)
  262. calculateEdbMappingIdsMap := make(map[int][]int)
  263. childEdbMappingIds := make([]int, 0)
  264. //indexCodeList := make([]string, 0)
  265. //refreshIds := make([]int, 0)
  266. //分页查询,每次处理500条记录
  267. pageSize := 500
  268. // 替换直接引用中的指标
  269. if newEdbInfo.EdbType == 2 {
  270. edbInfoList := make([]*data_manage.EdbInfo, 0)
  271. edbInfoList = append(edbInfoList, newEdbInfo)
  272. calculateEdbMappingListMap, calculateEdbMappingIdsMap, err = data.GetEdbListByEdbInfoId(edbInfoList)
  273. if err != nil {
  274. err = fmt.Errorf("查询指标关联指标列表失败 Err:%s", err)
  275. return
  276. }
  277. var ok bool
  278. childEdbMappingIds, ok = calculateEdbMappingIdsMap[newEdbInfo.EdbInfoId]
  279. if !ok {
  280. err = fmt.Errorf("查询%d指标关联指标列表为空", newEdbInfo.EdbInfoId)
  281. return
  282. }
  283. }
  284. total, err := data_manage.GetReplaceEdbInfoRelationTotal(oldEdbInfo.EdbInfoId)
  285. if err != nil {
  286. err = fmt.Errorf("查询引用表中关联的指标总数失败 err: %v", err)
  287. return
  288. }
  289. totalPage := 0
  290. if total > 0 {
  291. totalPage = (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  292. //查询图表列表
  293. for i := 0; i < totalPage; i += 1 {
  294. startSize := i * pageSize
  295. list, e := data_manage.GetReplaceEdbInfoRelationList(oldEdbInfo.EdbInfoId, startSize, pageSize)
  296. if e != nil {
  297. err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
  298. return
  299. }
  300. if len(list) == 0 {
  301. break
  302. }
  303. replaceTotal1, logMsg1, e := replaceEdbInRelation(oldEdbInfo, newEdbInfo, list, childEdbMappingIds, calculateEdbMappingListMap)
  304. if e != nil {
  305. err = e
  306. return
  307. }
  308. replaceTotal += replaceTotal1
  309. logMsg += logMsg1
  310. }
  311. }
  312. // 更新间接引用中的指标
  313. //查询相关的记录总数
  314. total, err = data_manage.GetReplaceChildEdbInfoRelationTotal(oldEdbInfo.EdbInfoId)
  315. if err != nil {
  316. if utils.IsErrNoRow(err) {
  317. err = nil
  318. } else {
  319. err = fmt.Errorf("查询引用表中关联的指标总数失败 err: %v", err)
  320. return
  321. }
  322. }
  323. if total > 0 {
  324. totalPage = (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  325. //查询列表
  326. for i := 0; i < totalPage; i += 1 {
  327. startSize := i * pageSize
  328. tmpList, e := data_manage.GetReplaceChildEdbInfoRelationList(oldEdbInfo.EdbInfoId, startSize, pageSize)
  329. if e != nil {
  330. err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
  331. return
  332. }
  333. // 查询直接引用
  334. relationIds := make([]int, 0)
  335. for _, v := range tmpList {
  336. relationIds = append(relationIds, v.ParentRelationId)
  337. }
  338. if len(relationIds) > 0 {
  339. list, e := data_manage.GetEdbInfoRelationByRelationIds(relationIds)
  340. if e != nil {
  341. err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
  342. return
  343. }
  344. //查询直接引用指标关联关系
  345. edbInfoListMap := make(map[int]struct{})
  346. edbInfoIds := make([]int, 0)
  347. for _, v := range list {
  348. if _, ok := edbInfoListMap[v.EdbInfoId]; !ok {
  349. edbInfoListMap[v.EdbInfoId] = struct{}{}
  350. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  351. }
  352. }
  353. edbInfoList := make([]*data_manage.EdbInfo, 0)
  354. if len(edbInfoIds) > 0 {
  355. // 查询指标信息
  356. edbInfoList, err = data_manage.GetEdbInfoByIdList(edbInfoIds)
  357. if err != nil {
  358. err = fmt.Errorf("查询指标信息失败 Err:%s", err)
  359. return
  360. }
  361. }
  362. calculateEdbMappingListMap, calculateEdbMappingIdsMap, err = data.GetEdbListByEdbInfoId(edbInfoList)
  363. if err != nil {
  364. err = fmt.Errorf("查询指标关联指标列表失败 Err:%s", err)
  365. return
  366. }
  367. //如何过滤掉只有间接引用,没有直接引用的
  368. replaceTotal1, logMsg1, e := UpdateSecondEdbInRelation(list, calculateEdbMappingListMap, calculateEdbMappingIdsMap, edbInfoList)
  369. if e != nil {
  370. err = e
  371. return
  372. }
  373. replaceTotal += replaceTotal1
  374. logMsg += logMsg1
  375. }
  376. }
  377. }
  378. return
  379. }
  380. // 完成直接引用中的指标替换工程
  381. func replaceEdbInRelation(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, list []*data_manage.EdbInfoRelation, childEdbMappingIds []int, calculateEdbMappingListMap map[int]*data_manage.EdbInfoCalculateMapping) (replaceTotal int, logMsg string, err error) {
  382. replaceEdbIds := make([]int, 0)
  383. indexCodeList := make([]string, 0)
  384. addList := make([]*data_manage.EdbInfoRelation, 0)
  385. refreshIds := make([]int, 0)
  386. nowTime := time.Now()
  387. for _, v := range list {
  388. replaceEdbIds = append(replaceEdbIds, v.EdbInfoRelationId)
  389. if newEdbInfo.EdbType == 2 {
  390. for _, childEdbMappingId := range childEdbMappingIds {
  391. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  392. if !ok2 {
  393. continue
  394. }
  395. if childEdbMapping.FromSource == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  396. indexCodeList = append(indexCodeList, childEdbMapping.FromEdbCode)
  397. }
  398. tmp1 := &data_manage.EdbInfoRelation{
  399. ReferObjectId: v.ReferObjectId,
  400. ReferObjectType: v.ReferObjectType,
  401. ReferObjectSubType: v.ReferObjectSubType,
  402. EdbInfoId: childEdbMapping.FromEdbInfoId,
  403. EdbName: childEdbMapping.FromEdbName,
  404. Source: childEdbMapping.FromSource,
  405. EdbCode: childEdbMapping.FromEdbCode,
  406. CreateTime: nowTime,
  407. ModifyTime: nowTime,
  408. RelationTime: nowTime,
  409. RelationType: 1,
  410. RootEdbInfoId: newEdbInfo.EdbInfoId,
  411. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  412. }
  413. tmp1.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp1.RootEdbInfoId, tmp1.ReferObjectId, tmp1.ReferObjectType, tmp1.ReferObjectSubType)
  414. addList = append(addList, tmp1)
  415. refreshIds = append(refreshIds, childEdbMapping.FromEdbInfoId)
  416. // todo 防止重复
  417. }
  418. }
  419. logMsg += strconv.Itoa(v.EdbInfoRelationId) + ";"
  420. }
  421. if len(replaceEdbIds) > 0 {
  422. err = data_manage.ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo, replaceEdbIds, addList, refreshIds, indexCodeList)
  423. if err != nil {
  424. logMsg = ""
  425. err = fmt.Errorf("替换指标引用表中的指标ID失败 Err:%s", err)
  426. return
  427. }
  428. replaceTotal = len(replaceEdbIds)
  429. }
  430. return
  431. }
  432. func UpdateSecondEdbInRelation(list []*data_manage.EdbInfoRelation, calculateEdbMappingListMap map[int]*data_manage.EdbInfoCalculateMapping, calculateEdbMappingIdsMap map[int][]int, edbInfoList []*data_manage.EdbInfo) (replaceTotal int, logMsg string, err error) {
  433. nowTime := time.Now()
  434. edbInfoRelationIds := make([]int, 0)
  435. indexCodeList := make([]string, 0)
  436. addList := make([]*data_manage.EdbInfoRelation, 0)
  437. refreshIds := make([]int, 0)
  438. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  439. for _, v := range edbInfoList {
  440. edbInfoMap[v.EdbInfoId] = v
  441. }
  442. // 查询所有的直接引用,删除所有的间接引用,添加所有直接引用的间接引用
  443. for _, v := range list {
  444. if v.RelationType == 0 {
  445. edbInfoRelationIds = append(edbInfoRelationIds, v.EdbInfoRelationId)
  446. edbInfo, ok := edbInfoMap[v.EdbInfoId]
  447. if !ok {
  448. err = fmt.Errorf("查询指标信息失败 EdbInfoId:%d", v.EdbInfoId)
  449. return
  450. }
  451. if edbInfo.EdbType == 2 { //计算指标
  452. childEdbMappingIds, ok := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  453. if !ok {
  454. err = fmt.Errorf("查询%d指标关联指标列表为空", edbInfo.EdbInfoId)
  455. return
  456. }
  457. for _, childEdbMappingId := range childEdbMappingIds {
  458. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  459. if !ok2 {
  460. continue
  461. }
  462. if childEdbMapping.FromSource == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  463. indexCodeList = append(indexCodeList, childEdbMapping.FromEdbCode)
  464. }
  465. tmp1 := &data_manage.EdbInfoRelation{
  466. ReferObjectId: v.ReferObjectId,
  467. ReferObjectType: v.ReferObjectType,
  468. ReferObjectSubType: v.ReferObjectSubType,
  469. EdbInfoId: childEdbMapping.FromEdbInfoId,
  470. EdbName: childEdbMapping.FromEdbName,
  471. Source: childEdbMapping.FromSource,
  472. EdbCode: childEdbMapping.FromEdbCode,
  473. CreateTime: nowTime,
  474. ModifyTime: nowTime,
  475. RelationTime: nowTime,
  476. RelationType: 1,
  477. RootEdbInfoId: edbInfo.EdbInfoId,
  478. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  479. }
  480. tmp1.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp1.RootEdbInfoId, tmp1.ReferObjectId, tmp1.ReferObjectType, tmp1.ReferObjectSubType)
  481. addList = append(addList, tmp1)
  482. refreshIds = append(refreshIds, childEdbMapping.FromEdbInfoId)
  483. }
  484. }
  485. logMsg += strconv.Itoa(v.EdbInfoRelationId) + ";"
  486. }
  487. }
  488. if len(edbInfoRelationIds) > 0 {
  489. err = data_manage.UpdateSecondRelationEdbInfoId(edbInfoRelationIds, addList, refreshIds, indexCodeList)
  490. if err != nil {
  491. logMsg = ""
  492. err = fmt.Errorf("替换指标引用表中的指标ID失败 Err:%s", err)
  493. return
  494. }
  495. replaceTotal = len(edbInfoRelationIds)
  496. }
  497. return
  498. }