edb_relation.go 37 KB

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