edb_relation.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_task/models/data_manage"
  5. "eta_gn/eta_task/models/data_manage/cross_variety"
  6. "eta_gn/eta_task/models/data_manage/excel"
  7. "eta_gn/eta_task/models/fe_calendar"
  8. "eta_gn/eta_task/models/sandbox"
  9. "eta_gn/eta_task/services/alarm_msg"
  10. "eta_gn/eta_task/utils"
  11. "fmt"
  12. "time"
  13. )
  14. func InitChartEdbRelation() {
  15. fmt.Println("开始处理图表中的指标引用")
  16. var err error
  17. var addNum int
  18. defer func() {
  19. if err != nil {
  20. msg := fmt.Sprintf("初始化指标在图表中的引用失败 InitChartEdbRelation err: %v", err)
  21. utils.FileLog.Info(msg)
  22. fmt.Println(msg)
  23. go alarm_msg.SendAlarmMsg(msg, 3)
  24. }
  25. }()
  26. total, err := data_manage.GetChartEdbMappingTotal()
  27. if err != nil {
  28. err = fmt.Errorf("查询图表关联指标失败 err: %v", err)
  29. return
  30. }
  31. if total == 0 {
  32. return
  33. }
  34. pageSize := 500
  35. totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  36. addList := make([]*data_manage.EdbInfoRelation, 0)
  37. for i := 0; i < totalPage; i += 1 {
  38. startSize := i * pageSize
  39. list, e := data_manage.GetChartEdbMappingList(startSize, pageSize)
  40. if e != nil {
  41. err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
  42. return
  43. }
  44. if len(list) == 0 {
  45. break
  46. }
  47. edbInfoIds := make([]int, 0)
  48. for _, v := range list {
  49. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  50. }
  51. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  52. if e != nil {
  53. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  54. return
  55. }
  56. if len(edbInfoList) == 0 {
  57. continue
  58. }
  59. calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := GetEdbListByEdbInfoId(edbInfoList)
  60. if e != nil {
  61. err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
  62. return
  63. }
  64. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  65. for _, v := range edbInfoList {
  66. edbInfoMap[v.EdbInfoId] = v
  67. }
  68. finalList := make([]*data_manage.ChartEdbMapping, 0)
  69. chartIds := make([]int, 0)
  70. for _, v := range list {
  71. if _, ok2 := edbInfoMap[v.EdbInfoId]; !ok2 {
  72. continue
  73. }
  74. finalList = append(finalList, v)
  75. chartIds = append(chartIds, v.ChartInfoId)
  76. }
  77. if len(chartIds) == 0 {
  78. continue
  79. }
  80. chartInfoList, e := data_manage.GetChartInfoByChartInfoIds(chartIds)
  81. if e != nil {
  82. err = fmt.Errorf("查询图表信息列表失败 Err:%s", e)
  83. return
  84. }
  85. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  86. for _, v := range chartInfoList {
  87. chartInfoMap[v.ChartInfoId] = v
  88. }
  89. chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(chartIds, utils.EDB_RELATION_CHART)
  90. if e != nil {
  91. err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
  92. return
  93. }
  94. existRelationMap := make(map[string]struct{})
  95. for _, v := range chartEdbRelationList {
  96. name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
  97. existRelationMap[name] = struct{}{}
  98. }
  99. for _, v := range finalList {
  100. nowTime := time.Now()
  101. name := fmt.Sprintf("%d-%d", v.ChartInfoId, v.EdbInfoId)
  102. if _, ok := existRelationMap[name]; !ok {
  103. chartInfo, ok1 := chartInfoMap[v.ChartInfoId]
  104. if !ok1 {
  105. continue
  106. }
  107. if chartInfo.Source == utils.CHART_SOURCE_CROSS_HEDGING { //过滤掉跨品种分析的图表
  108. continue
  109. }
  110. edbInfo, ok2 := edbInfoMap[v.EdbInfoId]
  111. if !ok2 {
  112. continue
  113. }
  114. if edbInfo.EdbInfoType == 1 {
  115. continue
  116. }
  117. tmp := &data_manage.EdbInfoRelation{
  118. ReferObjectId: v.ChartInfoId,
  119. ReferObjectType: utils.EDB_RELATION_CHART,
  120. ReferObjectSubType: chartInfo.Source,
  121. EdbInfoId: v.EdbInfoId,
  122. EdbName: edbInfo.EdbName,
  123. Source: edbInfo.Source,
  124. EdbCode: edbInfo.EdbCode,
  125. CreateTime: nowTime,
  126. ModifyTime: nowTime,
  127. RelationTime: v.CreateTime,
  128. }
  129. tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
  130. addList = append(addList, tmp)
  131. existRelationMap[name] = struct{}{}
  132. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  133. childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  134. if !ok1 {
  135. continue
  136. }
  137. for _, childEdbMappingId := range childEdbMappingIds {
  138. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  139. if !ok2 {
  140. continue
  141. }
  142. name1 := fmt.Sprintf("%d-%d", v.ChartInfoId, childEdbMapping.FromEdbInfoId)
  143. if _, ok2 := existRelationMap[name1]; ok2 { //如果已经被直接引用了,则无需添加到间接引用记录中
  144. continue
  145. }
  146. tmp1 := &data_manage.EdbInfoRelation{
  147. ReferObjectId: v.ChartInfoId,
  148. ReferObjectType: utils.EDB_RELATION_CHART,
  149. ReferObjectSubType: chartInfo.Source,
  150. EdbInfoId: childEdbMapping.FromEdbInfoId,
  151. EdbName: childEdbMapping.FromEdbName,
  152. Source: childEdbMapping.FromSource,
  153. EdbCode: childEdbMapping.FromEdbCode,
  154. CreateTime: nowTime,
  155. ModifyTime: nowTime,
  156. RelationTime: v.CreateTime,
  157. RelationType: 1,
  158. RootEdbInfoId: edbInfo.EdbInfoId,
  159. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  160. RelationCode: tmp.RelationCode,
  161. }
  162. addList = append(addList, tmp1)
  163. }
  164. }
  165. if len(addList) > pageSize {
  166. err = data_manage.AddEdbInfoRelationMulti(addList)
  167. if err != nil {
  168. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  169. return
  170. }
  171. addNum += len(addList)
  172. addList = make([]*data_manage.EdbInfoRelation, 0)
  173. }
  174. }
  175. }
  176. }
  177. if len(addList) > 0 {
  178. err = data_manage.AddEdbInfoRelationMulti(addList)
  179. if err != nil {
  180. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  181. return
  182. }
  183. addNum += len(addList)
  184. }
  185. fmt.Printf("图表指标引用记录处理完成, 新增%d条记录\n", addNum)
  186. return
  187. }
  188. func InitChartCrossVariety() {
  189. fmt.Println("开始跨品种分析图表中的指标引用")
  190. var addNum int
  191. var err error
  192. defer func() {
  193. if err != nil {
  194. msg := fmt.Sprintf("初始化指标在跨品种分析图表中的引用失败 InitChartCrossVariety err: %v", err)
  195. utils.FileLog.Info(msg)
  196. fmt.Println(msg)
  197. go alarm_msg.SendAlarmMsg(msg, 3)
  198. }
  199. }()
  200. total, err := cross_variety.GetChartInfoCrossVarietyTotal()
  201. if err != nil {
  202. err = fmt.Errorf("查询图表关联指标失败 err: %v", err)
  203. return
  204. }
  205. if total == 0 {
  206. return
  207. }
  208. pageSize := 500
  209. totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  210. addList := make([]*data_manage.EdbInfoRelation, 0)
  211. for i := 0; i < totalPage; i += 1 {
  212. startSize := i * pageSize
  213. list, e := cross_variety.GetChartInfoCrossVarietyList(startSize, pageSize)
  214. if e != nil {
  215. err = fmt.Errorf("查询图表关联指标列表失败 Err:%s", e)
  216. return
  217. }
  218. if len(list) == 0 {
  219. break
  220. }
  221. chartIds := make([]int, 0)
  222. chartIdMap := make(map[int]struct{})
  223. tagIds := make([]int, 0)
  224. tagIdsMap := make(map[int]struct{})
  225. tagChartMap := make(map[int][]*cross_variety.ChartInfoCrossVariety)
  226. for _, v := range list {
  227. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  228. chartIdMap[v.ChartInfoId] = struct{}{}
  229. chartIds = append(chartIds, v.ChartInfoId)
  230. }
  231. if _, ok := tagIdsMap[v.ChartXTagId]; !ok {
  232. tagIds = append(tagIds, v.ChartXTagId)
  233. tagIdsMap[v.ChartXTagId] = struct{}{}
  234. }
  235. if _, ok := tagIdsMap[v.ChartYTagId]; !ok {
  236. tagIds = append(tagIds, v.ChartYTagId)
  237. tagIdsMap[v.ChartYTagId] = struct{}{}
  238. }
  239. if chartCross, ok := tagChartMap[v.ChartXTagId]; ok {
  240. chartCross = append(chartCross, v)
  241. tagChartMap[v.ChartXTagId] = chartCross
  242. } else {
  243. chartCross = make([]*cross_variety.ChartInfoCrossVariety, 0)
  244. chartCross = append(chartCross, v)
  245. tagChartMap[v.ChartXTagId] = chartCross
  246. }
  247. if chartCross, ok := tagChartMap[v.ChartYTagId]; ok {
  248. chartCross = append(chartCross, v)
  249. tagChartMap[v.ChartYTagId] = chartCross
  250. } else {
  251. chartCross = make([]*cross_variety.ChartInfoCrossVariety, 0)
  252. chartCross = append(chartCross, v)
  253. tagChartMap[v.ChartYTagId] = chartCross
  254. }
  255. }
  256. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  257. if len(chartIds) > 0 {
  258. chartInfoList, e := data_manage.GetChartInfoByChartInfoIds(chartIds)
  259. if e != nil {
  260. err = fmt.Errorf("查询图表信息列表失败 Err:%s", e)
  261. return
  262. }
  263. for _, v := range chartInfoList {
  264. chartInfoMap[v.ChartInfoId] = v
  265. }
  266. }
  267. chartTagVarietyList, e := cross_variety.GetChartTagVarietyEdbInfoIdsByTagIds(tagIds)
  268. if e != nil {
  269. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  270. return
  271. }
  272. edbInfoIds := make([]int, 0)
  273. chartTagVarietyMap := make(map[int][]*cross_variety.ChartTagVariety)
  274. for _, v := range chartTagVarietyList {
  275. if tagList, ok := chartTagVarietyMap[v.EdbInfoId]; ok {
  276. tagList = append(tagList, v)
  277. chartTagVarietyMap[v.EdbInfoId] = tagList
  278. } else {
  279. tagList = make([]*cross_variety.ChartTagVariety, 0)
  280. tagList = append(tagList, v)
  281. chartTagVarietyMap[v.EdbInfoId] = tagList
  282. }
  283. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  284. }
  285. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  286. if e != nil {
  287. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  288. return
  289. }
  290. if len(edbInfoList) == 0 {
  291. continue
  292. }
  293. calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := GetEdbListByEdbInfoId(edbInfoList)
  294. if e != nil {
  295. err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
  296. return
  297. }
  298. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  299. chartInfoCrossMap := make(map[int]struct{})
  300. chartInfoCrossList := make([]*cross_variety.ChartInfoCrossVariety, 0)
  301. edbCrossMap := make(map[int][]*cross_variety.ChartInfoCrossVariety)
  302. for _, v := range edbInfoList {
  303. edbInfoMap[v.EdbInfoId] = v
  304. if tagList, ok := chartTagVarietyMap[v.EdbInfoId]; ok {
  305. for _, tag := range tagList {
  306. if chartCross, ok2 := tagChartMap[tag.ChartTagId]; ok2 {
  307. for _, crossItem := range chartCross {
  308. if _, ok3 := chartInfoCrossMap[crossItem.ChartInfoId]; !ok3 {
  309. chartInfo, chartOk := chartInfoMap[crossItem.ChartInfoId]
  310. if !chartOk { //表示图表不存在
  311. continue
  312. }
  313. var config cross_variety.ChartConfigReq
  314. e := json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  315. if e != nil {
  316. continue
  317. }
  318. if utils.InArrayByInt(config.VarietyList, tag.ChartVarietyId) {
  319. chartInfoCrossMap[crossItem.ChartInfoId] = struct{}{}
  320. chartInfoCrossList = append(chartInfoCrossList, crossItem)
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. edbCrossMap[v.EdbInfoId] = chartInfoCrossList
  328. chartInfoCrossMap = make(map[int]struct{})
  329. chartInfoCrossList = make([]*cross_variety.ChartInfoCrossVariety, 0)
  330. }
  331. chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(chartIds, utils.EDB_RELATION_CHART)
  332. if e != nil {
  333. err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
  334. return
  335. }
  336. existRelationMap := make(map[string]struct{})
  337. for _, v := range chartEdbRelationList {
  338. name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
  339. existRelationMap[name] = struct{}{}
  340. }
  341. for edbInfoId, chartCrossList := range edbCrossMap {
  342. nowTime := time.Now()
  343. for _, item := range chartCrossList {
  344. name := fmt.Sprintf("%d-%d", item.ChartInfoId, edbInfoId)
  345. if _, ok1 := existRelationMap[name]; !ok1 {
  346. edbInfo, ok2 := edbInfoMap[edbInfoId]
  347. if !ok2 {
  348. continue
  349. }
  350. if edbInfo.EdbInfoType == 1 {
  351. continue
  352. }
  353. tmp := &data_manage.EdbInfoRelation{
  354. ReferObjectId: item.ChartInfoId,
  355. ReferObjectType: utils.EDB_RELATION_CHART,
  356. ReferObjectSubType: utils.CHART_SOURCE_CROSS_HEDGING,
  357. EdbInfoId: edbInfoId,
  358. EdbName: edbInfo.EdbName,
  359. Source: edbInfo.Source,
  360. EdbCode: edbInfo.EdbCode,
  361. CreateTime: nowTime,
  362. ModifyTime: nowTime,
  363. RelationTime: item.CreateTime,
  364. }
  365. tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
  366. addList = append(addList, tmp)
  367. existRelationMap[name] = struct{}{}
  368. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  369. childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  370. if !ok1 {
  371. continue
  372. }
  373. for _, childEdbMappingId := range childEdbMappingIds {
  374. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  375. if !ok2 {
  376. continue
  377. }
  378. name1 := fmt.Sprintf("%d-%d", item.ChartInfoId, childEdbMapping.FromEdbInfoId)
  379. if _, ok2 := existRelationMap[name1]; ok2 { //如果已经被直接引用了,则无需添加到间接引用记录中
  380. continue
  381. }
  382. tmp1 := &data_manage.EdbInfoRelation{
  383. ReferObjectId: item.ChartInfoId,
  384. ReferObjectType: utils.EDB_RELATION_CHART,
  385. ReferObjectSubType: utils.CHART_SOURCE_CROSS_HEDGING,
  386. EdbInfoId: childEdbMapping.FromEdbInfoId,
  387. EdbName: childEdbMapping.FromEdbName,
  388. Source: childEdbMapping.FromSource,
  389. EdbCode: childEdbMapping.FromEdbCode,
  390. CreateTime: nowTime,
  391. ModifyTime: nowTime,
  392. RelationTime: item.CreateTime,
  393. RelationType: 1,
  394. RootEdbInfoId: edbInfo.EdbInfoId,
  395. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  396. RelationCode: tmp.RelationCode,
  397. }
  398. addList = append(addList, tmp1)
  399. }
  400. }
  401. if len(addList) > pageSize {
  402. err = data_manage.AddEdbInfoRelationMulti(addList)
  403. if err != nil {
  404. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  405. return
  406. }
  407. addNum += len(addList)
  408. addList = make([]*data_manage.EdbInfoRelation, 0)
  409. }
  410. }
  411. }
  412. }
  413. }
  414. if len(addList) > 0 {
  415. err = data_manage.AddEdbInfoRelationMulti(addList)
  416. if err != nil {
  417. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  418. return
  419. }
  420. addNum += len(addList)
  421. }
  422. fmt.Printf("跨品种分析图表指标引用记录处理完成, 新增%d条记录\n", addNum)
  423. return
  424. }
  425. func InitCalendarIndicatorRelation() {
  426. fmt.Println("开始处理事件日历中的指标引用")
  427. var addNum int
  428. var err error
  429. defer func() {
  430. if err != nil {
  431. msg := fmt.Sprintf("初始化指标在事件日历中的引用失败 initCalendarIndicatorRelation err: %v", err)
  432. utils.FileLog.Info(msg)
  433. fmt.Println(msg)
  434. go alarm_msg.SendAlarmMsg(msg, 3)
  435. }
  436. }()
  437. obj := new(fe_calendar.FeCalendarMatter)
  438. condition := " AND edb_info_id > 0"
  439. total, err := obj.GetCountByCondition(condition, []interface{}{})
  440. if err != nil {
  441. err = fmt.Errorf("查询事件日历关联指标失败 err: %v", err)
  442. return
  443. }
  444. if total == 0 {
  445. return
  446. }
  447. pageSize := 500
  448. totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  449. addList := make([]*data_manage.EdbInfoRelation, 0)
  450. for i := 0; i < totalPage; i += 1 {
  451. startSize := i * pageSize
  452. list, e := obj.GetPageItemsByCondition(condition, []interface{}{}, []string{}, "", startSize, pageSize)
  453. if e != nil {
  454. err = fmt.Errorf("查询事件日历关联指标列表失败 Err:%s", e)
  455. return
  456. }
  457. if len(list) == 0 {
  458. break
  459. }
  460. edbInfoIds := make([]int, 0)
  461. edbInfoMatterMap := make(map[int][]*fe_calendar.FeCalendarMatter)
  462. for _, v := range list {
  463. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  464. items, ok := edbInfoMatterMap[v.EdbInfoId]
  465. if ok {
  466. items = append(items, v)
  467. edbInfoMatterMap[v.EdbInfoId] = items
  468. } else {
  469. items = make([]*fe_calendar.FeCalendarMatter, 0)
  470. items = append(items, v)
  471. edbInfoMatterMap[v.EdbInfoId] = items
  472. }
  473. }
  474. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  475. if e != nil {
  476. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  477. return
  478. }
  479. if len(edbInfoList) == 0 {
  480. continue
  481. }
  482. calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := GetEdbListByEdbInfoId(edbInfoList)
  483. if e != nil {
  484. err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
  485. return
  486. }
  487. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  488. matterIds := make([]int, 0)
  489. for _, v := range edbInfoList {
  490. edbInfoMap[v.EdbInfoId] = v
  491. items, ok := edbInfoMatterMap[v.EdbInfoId]
  492. if ok {
  493. for _, item := range items {
  494. matterIds = append(matterIds, item.FeCalendarMatterId)
  495. }
  496. }
  497. }
  498. chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(matterIds, utils.EDB_RELATION_CALENDAR)
  499. if e != nil {
  500. err = fmt.Errorf("查询图表引用关系列表失败 Err:%s", e)
  501. return
  502. }
  503. existRelationMap := make(map[string]struct{})
  504. for _, v := range chartEdbRelationList {
  505. name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
  506. existRelationMap[name] = struct{}{}
  507. }
  508. for edbInfoId, edbInfo := range edbInfoMap {
  509. if edbInfo.EdbInfoType == 1 {
  510. continue
  511. }
  512. nowTime := time.Now()
  513. items, ok := edbInfoMatterMap[edbInfoId]
  514. if ok {
  515. for _, v := range items {
  516. name := fmt.Sprintf("%d-%d", v.FeCalendarMatterId, v.EdbInfoId)
  517. if _, ok1 := existRelationMap[name]; !ok1 {
  518. tmp := &data_manage.EdbInfoRelation{
  519. ReferObjectId: v.FeCalendarMatterId,
  520. ReferObjectType: utils.EDB_RELATION_CALENDAR,
  521. EdbInfoId: v.EdbInfoId,
  522. EdbName: edbInfo.EdbName,
  523. Source: edbInfo.Source,
  524. EdbCode: edbInfo.EdbCode,
  525. CreateTime: nowTime,
  526. ModifyTime: nowTime,
  527. RelationTime: v.CreateTime,
  528. }
  529. tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
  530. addList = append(addList, tmp)
  531. existRelationMap[name] = struct{}{}
  532. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  533. childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  534. if !ok1 {
  535. continue
  536. }
  537. for _, childEdbMappingId := range childEdbMappingIds {
  538. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  539. if !ok2 {
  540. continue
  541. }
  542. name1 := fmt.Sprintf("%d-%d", v.FeCalendarMatterId, childEdbMapping.FromEdbInfoId)
  543. if _, ok2 := existRelationMap[name1]; ok2 { //如果已经被直接引用了,则无需添加到间接引用记录中
  544. continue
  545. }
  546. tmp1 := &data_manage.EdbInfoRelation{
  547. ReferObjectId: v.FeCalendarMatterId,
  548. ReferObjectType: utils.EDB_RELATION_CALENDAR,
  549. EdbInfoId: childEdbMapping.FromEdbInfoId,
  550. EdbName: childEdbMapping.FromEdbName,
  551. Source: childEdbMapping.FromSource,
  552. EdbCode: childEdbMapping.FromEdbCode,
  553. CreateTime: nowTime,
  554. ModifyTime: nowTime,
  555. RelationTime: v.CreateTime,
  556. RelationType: 1,
  557. RootEdbInfoId: edbInfo.EdbInfoId,
  558. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  559. RelationCode: tmp.RelationCode,
  560. }
  561. addList = append(addList, tmp1)
  562. }
  563. }
  564. if len(addList) > pageSize {
  565. err = data_manage.AddEdbInfoRelationMulti(addList)
  566. if err != nil {
  567. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  568. return
  569. }
  570. addNum += len(addList)
  571. addList = make([]*data_manage.EdbInfoRelation, 0)
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. if len(addList) > 0 {
  579. err = data_manage.AddEdbInfoRelationMulti(addList)
  580. if err != nil {
  581. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  582. return
  583. }
  584. addNum += len(addList)
  585. }
  586. fmt.Printf("事件日历指标引用记录处理完成, 新增%d条记录\n", addNum)
  587. return
  588. }
  589. func InitExcelEdbRelation() {
  590. fmt.Println("开始处理表格中的指标引用")
  591. var err error
  592. var addNum int
  593. defer func() {
  594. if err != nil {
  595. msg := fmt.Sprintf("初始化指标在表格中的引用失败 InitChartEdbRelation err: %v", err)
  596. utils.FileLog.Info(msg)
  597. fmt.Println(msg)
  598. go alarm_msg.SendAlarmMsg(msg, 3)
  599. }
  600. }()
  601. sources := []int{utils.TIME_TABLE, utils.MIXED_TABLE, utils.BALANCE_TABLE}
  602. total, err := excel.GetExcelEdbMappingTotalBySource(sources)
  603. if err != nil {
  604. err = fmt.Errorf("查询表格关联指标失败 err: %v", err)
  605. return
  606. }
  607. if total == 0 {
  608. return
  609. }
  610. pageSize := 100
  611. totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  612. addList := make([]*data_manage.EdbInfoRelation, 0)
  613. for i := 0; i < totalPage; i += 1 {
  614. startSize := i * pageSize
  615. list, e := excel.GetExcelEdbMappingListBySource(sources, startSize, pageSize)
  616. if e != nil {
  617. err = fmt.Errorf("查询表格关联指标列表失败 Err:%s", e)
  618. return
  619. }
  620. if len(list) == 0 {
  621. break
  622. }
  623. edbInfoIds := make([]int, 0)
  624. for _, v := range list {
  625. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  626. }
  627. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  628. if e != nil {
  629. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  630. return
  631. }
  632. if len(edbInfoList) == 0 {
  633. continue
  634. }
  635. calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := GetEdbListByEdbInfoId(edbInfoList)
  636. if e != nil {
  637. err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
  638. return
  639. }
  640. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  641. for _, v := range edbInfoList {
  642. edbInfoMap[v.EdbInfoId] = v
  643. }
  644. excelIds := make([]int, 0)
  645. for _, v := range list {
  646. excelIds = append(excelIds, v.ExcelInfoId)
  647. }
  648. chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(excelIds, utils.EDB_RELATION_TABLE)
  649. if e != nil {
  650. err = fmt.Errorf("查询表格引用关系列表失败 Err:%s", e)
  651. return
  652. }
  653. existRelationMap := make(map[string]struct{})
  654. for _, v := range chartEdbRelationList {
  655. name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
  656. existRelationMap[name] = struct{}{}
  657. }
  658. for _, v := range list {
  659. nowTime := time.Now()
  660. name := fmt.Sprintf("%d-%d", v.ExcelInfoId, v.EdbInfoId)
  661. if _, ok := existRelationMap[name]; !ok {
  662. edbInfo, ok2 := edbInfoMap[v.EdbInfoId]
  663. if !ok2 {
  664. continue
  665. }
  666. if edbInfo.EdbInfoType == 1 {
  667. continue
  668. }
  669. tmp := &data_manage.EdbInfoRelation{
  670. ReferObjectId: v.ExcelInfoId,
  671. ReferObjectType: utils.EDB_RELATION_TABLE,
  672. ReferObjectSubType: v.Source,
  673. EdbInfoId: v.EdbInfoId,
  674. EdbName: edbInfo.EdbName,
  675. Source: edbInfo.Source,
  676. EdbCode: edbInfo.EdbCode,
  677. CreateTime: nowTime,
  678. ModifyTime: nowTime,
  679. RelationTime: v.CreateTime,
  680. }
  681. tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
  682. addList = append(addList, tmp)
  683. existRelationMap[name] = struct{}{}
  684. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  685. childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  686. if !ok1 {
  687. continue
  688. }
  689. for _, childEdbMappingId := range childEdbMappingIds {
  690. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  691. if !ok2 {
  692. continue
  693. }
  694. name1 := fmt.Sprintf("%d-%d", v.ExcelInfoId, childEdbMapping.FromEdbInfoId)
  695. if _, ok2 := existRelationMap[name1]; ok2 { //如果已经被直接引用了,则无需添加到间接引用记录中
  696. continue
  697. }
  698. tmp1 := &data_manage.EdbInfoRelation{
  699. ReferObjectId: v.ExcelInfoId,
  700. ReferObjectType: utils.EDB_RELATION_TABLE,
  701. ReferObjectSubType: v.Source,
  702. EdbInfoId: childEdbMapping.FromEdbInfoId,
  703. EdbName: childEdbMapping.FromEdbName,
  704. Source: childEdbMapping.FromSource,
  705. EdbCode: childEdbMapping.FromEdbCode,
  706. CreateTime: nowTime,
  707. ModifyTime: nowTime,
  708. RelationTime: v.CreateTime,
  709. RelationType: 1,
  710. RootEdbInfoId: edbInfo.EdbInfoId,
  711. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  712. RelationCode: tmp.RelationCode,
  713. }
  714. addList = append(addList, tmp1)
  715. }
  716. }
  717. if len(addList) > pageSize {
  718. err = data_manage.AddEdbInfoRelationMulti(addList)
  719. if err != nil {
  720. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  721. return
  722. }
  723. addNum += len(addList)
  724. addList = make([]*data_manage.EdbInfoRelation, 0)
  725. }
  726. }
  727. }
  728. }
  729. if len(addList) > 0 {
  730. err = data_manage.AddEdbInfoRelationMulti(addList)
  731. if err != nil {
  732. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  733. return
  734. }
  735. addNum += len(addList)
  736. }
  737. fmt.Printf("表格指标引用记录处理完成, 新增%d条记录\n", addNum)
  738. return
  739. }
  740. func InitSandBoxEdbRelation() {
  741. fmt.Println("开始处理逻辑图中的指标引用")
  742. var err error
  743. var addNum int
  744. defer func() {
  745. if err != nil {
  746. msg := fmt.Sprintf("初始化指标在逻辑图中的引用失败 initSandBoxEdbRelation err: %v", err)
  747. utils.FileLog.Info(msg)
  748. fmt.Println(msg)
  749. go alarm_msg.SendAlarmMsg(msg, 3)
  750. }
  751. }()
  752. condition := " AND is_delete = 0"
  753. total, err := sandbox.GetSandboxListCountByCondition(condition, []interface{}{})
  754. if err != nil {
  755. err = fmt.Errorf("查询逻辑图总数失败 err: %v", err)
  756. return
  757. }
  758. if total == 0 {
  759. return
  760. }
  761. pageSize := 100
  762. totalPage := (total + pageSize - 1) / pageSize // 使用整数除法,并添加一页以防有余数
  763. addList := make([]*data_manage.EdbInfoRelation, 0)
  764. for i := 0; i < totalPage; i += 1 {
  765. startSize := i * pageSize
  766. list, e := sandbox.GetSandboxListByCondition(condition, []interface{}{}, startSize, pageSize)
  767. if e != nil {
  768. err = fmt.Errorf("查询逻辑图列表失败 Err:%s", e)
  769. return
  770. }
  771. if len(list) == 0 {
  772. break
  773. }
  774. edbInfoIds := make([]int, 0)
  775. edbSandboxMap := make(map[int][]*sandbox.Sandbox)
  776. for _, v := range list {
  777. if v.Content == "" {
  778. continue
  779. }
  780. edbInfoIdsTmp, e := getSandBoxEdbIdsByContent(v.Content)
  781. if e != nil {
  782. continue
  783. }
  784. for _, edbId := range edbInfoIdsTmp {
  785. edbInfoIds = append(edbInfoIds, edbId)
  786. edbSandboxMap[edbId] = append(edbSandboxMap[edbId], v)
  787. }
  788. }
  789. if len(edbInfoIds) <= 0 {
  790. continue
  791. }
  792. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  793. if e != nil {
  794. err = fmt.Errorf("查询指标信息列表失败 Err:%s", e)
  795. return
  796. }
  797. if len(edbInfoList) == 0 {
  798. continue
  799. }
  800. calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := GetEdbListByEdbInfoId(edbInfoList)
  801. if e != nil {
  802. err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
  803. return
  804. }
  805. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  806. sandboxIds := make([]int, 0)
  807. for _, v := range edbInfoList {
  808. edbInfoMap[v.EdbInfoId] = v
  809. if items, ok := edbSandboxMap[v.EdbInfoId]; ok {
  810. for _, item := range items {
  811. sandboxIds = append(sandboxIds, item.SandboxId)
  812. }
  813. }
  814. }
  815. chartEdbRelationList, e := data_manage.GetEdbInfoRelationByReferObjectIds(sandboxIds, utils.EDB_RELATION_SANDBOX)
  816. if e != nil {
  817. err = fmt.Errorf("查询逻辑图引用关系列表失败 Err:%s", e)
  818. return
  819. }
  820. existRelationMap := make(map[string]struct{})
  821. for _, v := range chartEdbRelationList {
  822. name := fmt.Sprintf("%d-%d", v.ReferObjectId, v.EdbInfoId)
  823. existRelationMap[name] = struct{}{}
  824. }
  825. for edbInfoId, sandboxList := range edbSandboxMap {
  826. nowTime := time.Now()
  827. for _, v := range sandboxList {
  828. name := fmt.Sprintf("%d-%d", v.SandboxId, edbInfoId)
  829. if _, ok := existRelationMap[name]; !ok {
  830. edbInfo, ok2 := edbInfoMap[edbInfoId]
  831. if !ok2 {
  832. continue
  833. }
  834. if edbInfo.EdbInfoType == 1 {
  835. continue
  836. }
  837. tmp := &data_manage.EdbInfoRelation{
  838. ReferObjectId: v.SandboxId,
  839. ReferObjectType: utils.EDB_RELATION_SANDBOX,
  840. EdbInfoId: edbInfoId,
  841. EdbName: edbInfo.EdbName,
  842. Source: edbInfo.Source,
  843. EdbCode: edbInfo.EdbCode,
  844. CreateTime: nowTime,
  845. ModifyTime: nowTime,
  846. RelationTime: v.CreateTime,
  847. }
  848. tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
  849. addList = append(addList, tmp)
  850. existRelationMap[name] = struct{}{}
  851. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  852. childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
  853. if !ok1 {
  854. continue
  855. }
  856. for _, childEdbMappingId := range childEdbMappingIds {
  857. childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
  858. if !ok2 {
  859. continue
  860. }
  861. name1 := fmt.Sprintf("%d-%d", v.SandboxId, childEdbMapping.FromEdbInfoId)
  862. if _, ok2 := existRelationMap[name1]; ok2 { //如果已经被直接引用了,则无需添加到间接引用记录中
  863. continue
  864. }
  865. tmp1 := &data_manage.EdbInfoRelation{
  866. ReferObjectId: v.SandboxId,
  867. ReferObjectType: utils.EDB_RELATION_SANDBOX,
  868. EdbInfoId: childEdbMapping.FromEdbInfoId,
  869. EdbName: childEdbMapping.FromEdbName,
  870. Source: childEdbMapping.FromSource,
  871. EdbCode: childEdbMapping.FromEdbCode,
  872. CreateTime: nowTime,
  873. ModifyTime: nowTime,
  874. RelationTime: v.CreateTime,
  875. RelationType: 1,
  876. RootEdbInfoId: edbInfo.EdbInfoId,
  877. ChildEdbInfoId: childEdbMapping.EdbInfoId,
  878. RelationCode: tmp.RelationCode,
  879. }
  880. addList = append(addList, tmp1)
  881. }
  882. }
  883. if len(addList) > pageSize {
  884. err = data_manage.AddEdbInfoRelationMulti(addList)
  885. if err != nil {
  886. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  887. return
  888. }
  889. addNum += len(addList)
  890. addList = make([]*data_manage.EdbInfoRelation, 0)
  891. }
  892. }
  893. }
  894. }
  895. }
  896. if len(addList) > 0 {
  897. err = data_manage.AddEdbInfoRelationMulti(addList)
  898. if err != nil {
  899. err = fmt.Errorf("新增引用记录失败 Err:%s", err)
  900. return
  901. }
  902. addNum += len(addList)
  903. }
  904. fmt.Printf("逻辑图指标引用记录处理完成, 新增%d条记录\n", addNum)
  905. return
  906. }
  907. func getSandBoxEdbIdsByContent(content string) (edbInfoIds []int, err error) {
  908. var contentInfo sandbox.ContentDataStruct
  909. err = json.Unmarshal([]byte(content), &contentInfo)
  910. if err != nil {
  911. err = fmt.Errorf("json.Unmarshal err:%s", err.Error())
  912. return
  913. }
  914. for _, node := range contentInfo.Cells {
  915. if node.Data == nil {
  916. continue
  917. }
  918. for _, v := range node.Data.LinkData {
  919. if v.Type == 1 {
  920. edbInfoIds = append(edbInfoIds, v.Id)
  921. }
  922. }
  923. }
  924. return
  925. }
  926. func GetEdbListByEdbInfoId(edbInfoList []*data_manage.EdbInfo) (edbMappingListMap map[int]*data_manage.EdbInfoCalculateMapping, edbInfoMappingRootIdsMap map[int][]int, err error) {
  927. if len(edbInfoList) == 0 {
  928. return
  929. }
  930. edbInfoIds := make([]int, 0)
  931. for _, v := range edbInfoList {
  932. if v.EdbType == 2 && v.EdbInfoType == 0 { //普通计算指标,排除预算指标
  933. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  934. }
  935. }
  936. if len(edbInfoIds) == 0 {
  937. return
  938. }
  939. allEdbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo, 0)
  940. allMappingList, e := data_manage.GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds)
  941. if e != nil {
  942. err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoIds err: %s", e.Error())
  943. return
  944. }
  945. for _, v := range allMappingList {
  946. if _, ok := allEdbMappingMap[v.EdbInfoId]; !ok {
  947. allEdbMappingMap[v.EdbInfoId] = make([]*data_manage.EdbInfoCalculateMappingInfo, 0)
  948. }
  949. allEdbMappingMap[v.EdbInfoId] = append(allEdbMappingMap[v.EdbInfoId], v)
  950. }
  951. hasFindMap := make(map[int]struct{})
  952. edbInfoIdMap := make(map[int]struct{})
  953. edbMappingList := make([]*data_manage.EdbInfoCalculateMapping, 0)
  954. edbInfoMappingRootIdsMap = make(map[int][]int, 0)
  955. edbMappingMap := make(map[int]struct{})
  956. for _, edbInfo := range edbInfoList {
  957. if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
  958. edbInfoId := edbInfo.EdbInfoId
  959. edbMappingList, err = getCalculateEdbInfoByEdbInfoId(allEdbMappingMap, edbInfoId, hasFindMap, edbInfoIdMap, edbMappingList, edbMappingMap, edbInfoMappingRootIdsMap, edbInfoId)
  960. if err != nil {
  961. err = fmt.Errorf(" GetCalculateEdbInfoByEdbInfoId err: %s", err.Error())
  962. return
  963. }
  964. }
  965. }
  966. if len(edbMappingList) == 0 {
  967. return
  968. }
  969. edbInfoIdList := make([]int, 0)
  970. for k, _ := range edbInfoIdMap {
  971. edbInfoIdList = append(edbInfoIdList, k)
  972. }
  973. edbMappingListMap = make(map[int]*data_manage.EdbInfoCalculateMapping)
  974. if len(edbMappingList) > 0 {
  975. for _, v := range edbMappingList {
  976. edbMappingListMap[v.EdbInfoCalculateMappingId] = v
  977. }
  978. }
  979. return
  980. }
  981. func getCalculateEdbInfoByEdbInfoId(allEdbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo, edbInfoId int, hasFindMap map[int]struct{}, edbInfoIdMap map[int]struct{}, edbMappingList []*data_manage.EdbInfoCalculateMapping, edbMappingMap map[int]struct{}, edbInfoMappingRootIdsMap map[int][]int, rootEdbInfoId int) (newEdbMappingList []*data_manage.EdbInfoCalculateMapping, err error) {
  982. newEdbMappingList = edbMappingList
  983. _, ok := hasFindMap[edbInfoId]
  984. if ok {
  985. return
  986. }
  987. if _, ok1 := edbInfoIdMap[edbInfoId]; !ok1 {
  988. edbInfoIdMap[edbInfoId] = struct{}{}
  989. }
  990. edbInfoMappingList := make([]*data_manage.EdbInfoCalculateMappingInfo, 0)
  991. edbInfoMappingList, ok = allEdbMappingMap[edbInfoId]
  992. if !ok {
  993. edbInfoMappingList, err = data_manage.GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId)
  994. if err != nil {
  995. err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoId err: %s", err.Error())
  996. return
  997. }
  998. }
  999. hasFindMap[edbInfoId] = struct{}{}
  1000. if len(edbInfoMappingList) > 0 {
  1001. fromEdbInfoIdList := make([]int, 0)
  1002. edbInfoMappingIdList := make([]int, 0)
  1003. for _, v := range edbInfoMappingList {
  1004. fromEdbInfoIdList = append(fromEdbInfoIdList, v.FromEdbInfoId)
  1005. edbInfoMappingIdList = append(edbInfoMappingIdList, v.EdbInfoCalculateMappingId)
  1006. if _, ok1 := edbInfoIdMap[v.FromEdbInfoId]; !ok1 {
  1007. edbInfoIdMap[v.FromEdbInfoId] = struct{}{}
  1008. }
  1009. if _, ok2 := edbMappingMap[v.EdbInfoCalculateMappingId]; !ok2 {
  1010. edbMappingMap[v.EdbInfoCalculateMappingId] = struct{}{}
  1011. tmp := &data_manage.EdbInfoCalculateMapping{
  1012. EdbInfoCalculateMappingId: v.EdbInfoCalculateMappingId,
  1013. EdbInfoId: v.EdbInfoId,
  1014. Source: v.Source,
  1015. SourceName: v.SourceName,
  1016. EdbCode: v.EdbCode,
  1017. FromEdbInfoId: v.FromEdbInfoId,
  1018. FromEdbCode: v.FromEdbCode,
  1019. FromEdbName: v.FromEdbName,
  1020. FromSource: v.FromSource,
  1021. FromSourceName: v.FromSourceName,
  1022. FromTag: v.FromTag,
  1023. Sort: v.Sort,
  1024. CreateTime: v.CreateTime,
  1025. ModifyTime: v.ModifyTime,
  1026. }
  1027. newEdbMappingList = append(newEdbMappingList, tmp)
  1028. }
  1029. if edbInfoId != v.FromEdbInfoId && (v.FromEdbType == 2 || v.FromEdbInfoType == 1) {
  1030. if _, ok2 := hasFindMap[v.FromEdbInfoId]; !ok2 {
  1031. newEdbMappingList, err = getCalculateEdbInfoByEdbInfoId(allEdbMappingMap, v.FromEdbInfoId, hasFindMap, edbInfoIdMap, newEdbMappingList, edbMappingMap, edbInfoMappingRootIdsMap, rootEdbInfoId)
  1032. if err != nil {
  1033. err = fmt.Errorf("traceEdbInfoByEdbInfoId err: %s", err.Error())
  1034. return
  1035. }
  1036. }
  1037. }
  1038. hasFindMap[v.FromEdbInfoId] = struct{}{}
  1039. }
  1040. edbInfoMappingRootIdsMap[rootEdbInfoId] = append(edbInfoMappingRootIdsMap[rootEdbInfoId], edbInfoMappingIdList...)
  1041. }
  1042. return
  1043. }