edb_info_relation.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package data_manage
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. type EdbInfoRelation struct {
  10. EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk" gorm:"primaryKey"`
  11. EdbInfoId int `description:"指标id"`
  12. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"`
  13. EdbName string `description:"指标名称"`
  14. EdbCode string `description:"指标编码"`
  15. ReferObjectId int `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
  16. ReferObjectType int `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
  17. ReferObjectSubType int `description:"引用对象子类"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. RelationTime time.Time `description:"引用时间"`
  21. RelationType int `description:"引用类型,0:直接饮用,1间接引用"`
  22. RootEdbInfoId int `description:"间接引用时,关联的直接引用的指标ID"`
  23. ChildEdbInfoId int `description:"间接引用时,关联的计算指标ID"`
  24. RelationCode string `description:"引用标识"`
  25. ParentRelationId int `description:"间接引用关联的直接引用的ID"`
  26. }
  27. func (e *EdbInfoRelation) TableName() string {
  28. return "edb_info_relation"
  29. }
  30. // GetEdbInfoRelationByRelationIds 查询引用的指标ID
  31. func GetEdbInfoRelationByRelationIds(ids []int) (items []*EdbInfoRelation, err error) {
  32. o := global.DbMap[utils.DbNameIndex]
  33. msql := ` SELECT * FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
  34. err = o.Raw(msql, ids).Find(&items).Error
  35. return
  36. }
  37. // GetEdbInfoRelationByReferObjectId 查询直接引用的指标ID
  38. func GetEdbInfoRelationByReferObjectId(referObjectId int, referObjectType int) (items []*EdbInfoRelation, err error) {
  39. o := global.DbMap[utils.DbNameIndex]
  40. msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id =? and relation_type=0 AND refer_object_type=? GROUP BY edb_info_id `
  41. err = o.Raw(msql, referObjectId, referObjectType).Find(&items).Error
  42. return
  43. }
  44. // GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
  45. func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
  46. o := global.DbMap[utils.DbNameIndex]
  47. msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=? and relation_type=0`
  48. err = o.Raw(msql, referObjectIds, referObjectType).Find(&items).Error
  49. return
  50. }
  51. // GetEdbInfoRelationAllByReferObjectIds 查询引用的指标ID
  52. func GetEdbInfoRelationAllByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
  53. o := global.DbMap[utils.DbNameIndex]
  54. msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
  55. err = o.Raw(msql, referObjectIds, referObjectType).Find(&items).Error
  56. return
  57. }
  58. // 新增记录
  59. func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInfoRelation, deleteEdbInfoIds []int, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  60. o := global.DbMap[utils.DbNameIndex].Begin()
  61. if o.Error != nil {
  62. return o.Error
  63. }
  64. defer func() {
  65. if err != nil {
  66. _ = o.Rollback()
  67. return
  68. }
  69. _ = o.Commit()
  70. }()
  71. if len(deleteEdbInfoIds) > 0 {
  72. sql := ` DELETE FROM edb_info_relation WHERE refer_object_id = ? AND refer_object_type=? AND edb_info_id in (` + utils.GetOrmInReplace(len(deleteEdbInfoIds)) + `) AND relation_type=0`
  73. err = o.Exec(sql, objectId, objectType, deleteEdbInfoIds).Error
  74. if err != nil {
  75. return
  76. }
  77. // 同时删除相关连的间接引用的指标ID
  78. sql = ` DELETE FROM edb_info_relation WHERE refer_object_id = ? AND refer_object_type=? AND root_edb_info_id in (` + utils.GetOrmInReplace(len(deleteEdbInfoIds)) + `) AND relation_type=1 `
  79. err = o.Exec(sql, objectId, objectType, deleteEdbInfoIds).Error
  80. if err != nil {
  81. return
  82. }
  83. }
  84. relationCodesMap := make(map[string]struct{}, 0)
  85. if len(relationList) > 0 {
  86. for _, relation := range relationList {
  87. if relation.RelationType == 1 {
  88. relationCodesMap[relation.RelationCode] = struct{}{}
  89. }
  90. }
  91. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  92. if err != nil {
  93. return
  94. }
  95. }
  96. if len(refreshEdbInfoIds) > 0 {
  97. //todo 是否需要所有指标的刷新状态
  98. sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  99. err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
  100. if err != nil {
  101. return
  102. }
  103. }
  104. //更新数据源钢联化工指标
  105. if len(indexCodeList) > 0 {
  106. // 更改数据源的更新状态
  107. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  108. err = o.Exec(sql, indexCodeList).Error
  109. if err != nil {
  110. return
  111. }
  112. }
  113. if len(relationList) > 0 {
  114. // 更新间接引用指标的关联ID
  115. relationCodes := make([]string, 0)
  116. for relationCode := range relationCodesMap {
  117. relationCodes = append(relationCodes, relationCode)
  118. }
  119. if len(relationCodes) > 0 {
  120. sql := ` UPDATE edb_info_relation e1
  121. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  122. SET e1.parent_relation_id = e2.edb_info_relation_id
  123. WHERE
  124. e1.relation_type = 1
  125. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  126. err = o.Exec(sql, relationCodes).Error
  127. if err != nil {
  128. return
  129. }
  130. }
  131. }
  132. return
  133. }
  134. // 新增记录
  135. func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  136. o := global.DbMap[utils.DbNameIndex].Begin()
  137. if o.Error != nil {
  138. return o.Error
  139. }
  140. defer func() {
  141. if err != nil {
  142. _ = o.Rollback()
  143. return
  144. }
  145. _ = o.Commit()
  146. }()
  147. relationCodesMap := make(map[string]struct{}, 0)
  148. if len(relationList) > 0 {
  149. for _, relation := range relationList {
  150. if relation.RelationType == 1 {
  151. relationCodesMap[relation.RelationCode] = struct{}{}
  152. }
  153. }
  154. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  155. if err != nil {
  156. return
  157. }
  158. }
  159. if len(refreshEdbInfoIds) > 0 {
  160. // todo 更新指标的刷新状态
  161. sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  162. err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
  163. if err != nil {
  164. return
  165. }
  166. }
  167. //更新数据源钢联化工指标
  168. if len(indexCodeList) > 0 {
  169. // 更改数据源的更新状态
  170. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  171. err = o.Exec(sql, indexCodeList).Error
  172. if err != nil {
  173. return
  174. }
  175. }
  176. if len(relationList) > 0 {
  177. // 更新间接引用指标的关联ID
  178. relationCodes := make([]string, 0)
  179. for relationCode := range relationCodesMap {
  180. relationCodes = append(relationCodes, relationCode)
  181. }
  182. if len(relationCodes) > 0 {
  183. sql := ` UPDATE edb_info_relation e1
  184. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  185. SET e1.parent_relation_id = e2.edb_info_relation_id
  186. WHERE
  187. e1.relation_type = 1
  188. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  189. err = o.Exec(sql, relationCodes).Error
  190. if err != nil {
  191. return
  192. }
  193. }
  194. }
  195. return
  196. }
  197. // 删除指标引用内容
  198. func DeleteEdbRelationByObjectIds(referObjectIds []int, referObjectType int) (err error) {
  199. o := global.DbMap[utils.DbNameIndex]
  200. sql := ` DELETE FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
  201. err = o.Exec(sql, referObjectIds, referObjectType).Error
  202. return
  203. }
  204. // DeleteEdbRelationByObjectId 删除指标引用内容
  205. func DeleteEdbRelationByObjectId(referObjectId int, referObjectType int) (err error) {
  206. o := global.DbMap[utils.DbNameIndex]
  207. sql := ` DELETE FROM edb_info_relation WHERE refer_object_id =? AND refer_object_type=?`
  208. err = o.Exec(sql, referObjectId, referObjectType).Error
  209. return
  210. }
  211. type BaseRelationEdbInfo struct {
  212. EdbInfoId int
  213. ClassifyId int `description:"指标分类id"`
  214. EdbName string `description:"指标名称"`
  215. EdbCode string `description:"指标编码"`
  216. SysUserId int `description:"创建人id"`
  217. SysUserRealName string `description:"创建人姓名"`
  218. Frequency string `description:"频度"`
  219. IsStop int `description:"是否停更:1:停更,0:未停更"`
  220. IsSupplierStop int `description:"是否供应商停更:1:停更,0:未停更"`
  221. RelationNum int `description:"引用次数"`
  222. RelationTime string `description:"引用时间"`
  223. }
  224. func (e *BaseRelationEdbInfo) AfterFind(db *gorm.DB) (err error) {
  225. e.RelationTime = utils.GormDateStrToDateTimeStr(e.RelationTime)
  226. return
  227. }
  228. type BaseRelationEdbInfoResp struct {
  229. Paging *paging.PagingItem
  230. List []*BaseRelationEdbInfo
  231. }
  232. type EdbInfoRelationDetail struct {
  233. EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk" gorm:"primaryKey"`
  234. EdbInfoId int `description:"指标id"`
  235. ReferObjectId int `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
  236. ReferObjectTypeName string `description:"引用对象类型"`
  237. ReferObjectType int `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
  238. ReferObjectSubType int `description:"引用对象子类"`
  239. RelationTime string `description:"引用时间"`
  240. ReferObjectName string `description:"引用对象名称"`
  241. }
  242. type BaseRelationEdbInfoDetailResp struct {
  243. Paging *paging.PagingItem
  244. List []*EdbInfoRelationDetail
  245. }
  246. // 查询指标引用列表
  247. func GetEdbInfoRelationList(condition string, pars []interface{}, addFieldStr, joinTableStr, orderBy string, startSize, pageSize int) (total int, items []*BaseRelationEdbInfo, err error) {
  248. o := global.DbMap[utils.DbNameIndex]
  249. // 数量汇总
  250. totalSql := ` SELECT count(1) FROM edb_info e LEFT JOIN (
  251. SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id `
  252. if joinTableStr != "" {
  253. totalSql += joinTableStr
  254. }
  255. totalSql += ` WHERE 1=1 `
  256. if condition != "" {
  257. totalSql += condition
  258. }
  259. err = o.Raw(totalSql, pars...).Scan(&total).Error
  260. if err != nil {
  261. return
  262. }
  263. fieldStr := ` e.edb_info_id, e.classify_id,e.edb_code,e.edb_name,e.sys_user_id,e.sys_user_real_name,e.frequency,e.no_update as is_stop, r.relation_num, r.relation_time ` + addFieldStr
  264. // 列表数据
  265. sql := ` SELECT ` + fieldStr + ` from edb_info e LEFT JOIN (
  266. SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id `
  267. if joinTableStr != "" {
  268. sql += joinTableStr
  269. }
  270. sql += ` WHERE 1=1 `
  271. if condition != "" {
  272. sql += condition
  273. }
  274. if orderBy != "" {
  275. sql += ` ORDER BY ` + orderBy
  276. } else {
  277. sql += ` ORDER BY edb_info_id ASC `
  278. }
  279. sql += ` LIMIT ?,? `
  280. pars = append(pars, startSize, pageSize)
  281. err = o.Raw(sql, pars...).Find(&items).Error
  282. return
  283. }
  284. // GetEdbInfoRelationDetailList 查询指标引用详情列表
  285. func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total int, items []*EdbInfoRelation, err error) {
  286. o := global.DbMap[utils.DbNameIndex]
  287. // 数量汇总
  288. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=?`
  289. err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
  290. if err != nil {
  291. return
  292. }
  293. // 列表数据
  294. sql := ` SELECT *FROM edb_info_relation where edb_info_id=? ORDER BY relation_time desc, edb_info_id ASC `
  295. sql += ` LIMIT ?,? `
  296. err = o.Raw(sql, edbInfoId, startSize, pageSize).Find(&items).Error
  297. return
  298. }
  299. // 查询相关的指标记录总数
  300. func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  301. o := global.DbMap[utils.DbNameIndex]
  302. // 数量汇总
  303. totalSql := ` SELECT count(*) FROM edb_info_relation where relation_type=1 and (child_edb_info_id=? or edb_info_id=? ) group by parent_relation_id`
  304. err = o.Raw(totalSql, edbInfoId, edbInfoId).Scan(&total).Error
  305. if err != nil {
  306. return
  307. }
  308. return
  309. }
  310. // 查询相关的指标记录列表
  311. func GetReplaceChildEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  312. o := global.DbMap[utils.DbNameIndex]
  313. // 列表数据
  314. sql := ` SELECT * FROM edb_info_relation where relation_type=1 and (child_edb_info_id=? or edb_info_id=? ) group by parent_relation_id ORDER BY edb_info_relation_id ASC LIMIT ?,? `
  315. err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).Find(&items).Error
  316. return
  317. }
  318. // 查询相关的指标记录总数
  319. func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  320. o := global.DbMap[utils.DbNameIndex]
  321. // 数量汇总
  322. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=? and relation_type = 0`
  323. err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
  324. if err != nil {
  325. return
  326. }
  327. return
  328. }
  329. // 查询相关的指标记录列表
  330. func GetReplaceEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  331. o := global.DbMap[utils.DbNameIndex]
  332. // 列表数据
  333. sql := ` SELECT * FROM edb_info_relation where edb_info_id=? and relation_type = 0 ORDER BY edb_info_relation_id ASC LIMIT ?,? `
  334. err = o.Raw(sql, edbInfoId, startSize, pageSize).Find(&items).Error
  335. return
  336. }
  337. // 替换指标引用表中直接引用的指标
  338. func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  339. o := global.DbMap[utils.DbNameIndex].Begin()
  340. if o.Error != nil {
  341. return o.Error
  342. }
  343. defer func() {
  344. if err != nil {
  345. _ = o.Rollback()
  346. return
  347. }
  348. _ = o.Commit()
  349. }()
  350. now := time.Now()
  351. // 删除相关的间接引用
  352. sql := ` DELETE FROM edb_info_relation WHERE root_edb_info_id=? and relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  353. err = o.Exec(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Error
  354. if err != nil {
  355. return
  356. }
  357. sourceWhere := ` and (refer_object_type in (1,2,5) or (refer_object_type=4 and refer_object_sub_type !=5) )` //平衡表和事件日历中的直接引用无需替换,
  358. // 替换edb_info_id
  359. sql = ` UPDATE edb_info_relation SET edb_info_id=?, source=?, edb_name=?, edb_code=?, modify_time=?, relation_time=? WHERE edb_info_id=? ` + sourceWhere + ` and relation_type=0 and edb_info_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  360. err = o.Exec(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Error
  361. if err != nil {
  362. return
  363. }
  364. // 更新code值
  365. sql = ` UPDATE edb_info_relation SET relation_code=CONCAT_WS("_", edb_info_id,refer_object_id,refer_object_type,refer_object_sub_type) WHERE relation_type=0 ` + sourceWhere + ` and edb_info_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  366. err = o.Exec(sql, edbRelationIds).Error
  367. if err != nil {
  368. return
  369. }
  370. // 新增间接引用
  371. relationCodesMap := make(map[string]struct{}, 0)
  372. if len(relationList) > 0 {
  373. for _, relation := range relationList {
  374. if relation.RelationType == 1 {
  375. relationCodesMap[relation.RelationCode] = struct{}{}
  376. }
  377. }
  378. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  379. if err != nil {
  380. return
  381. }
  382. }
  383. if len(refreshEdbInfoIds) > 0 {
  384. // todo 更新指标的刷新状态
  385. sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  386. err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
  387. if err != nil {
  388. return
  389. }
  390. }
  391. //更新数据源钢联化工指标
  392. if len(indexCodeList) > 0 {
  393. // 更改数据源的更新状态
  394. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  395. err = o.Exec(sql, indexCodeList).Error
  396. if err != nil {
  397. return
  398. }
  399. }
  400. if len(relationList) > 0 {
  401. // 更新间接引用指标的关联ID
  402. relationCodes := make([]string, 0)
  403. for relationCode := range relationCodesMap {
  404. relationCodes = append(relationCodes, relationCode)
  405. }
  406. if len(relationCodes) > 0 {
  407. sql := ` UPDATE edb_info_relation e1
  408. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  409. SET e1.parent_relation_id = e2.edb_info_relation_id
  410. WHERE
  411. e1.relation_type = 1
  412. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  413. err = o.Exec(sql, relationCodes).Error
  414. if err != nil {
  415. return
  416. }
  417. }
  418. }
  419. return
  420. }
  421. // UpdateSecondRelationEdbInfoId 更新指标替换后的间接引用记录
  422. func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  423. o := global.DbMap[utils.DbNameIndex].Begin()
  424. if o.Error != nil {
  425. return o.Error
  426. }
  427. defer func() {
  428. if err != nil {
  429. _ = o.Rollback()
  430. return
  431. }
  432. _ = o.Commit()
  433. }()
  434. // 删除相关的间接引用
  435. sql := ` DELETE FROM edb_info_relation WHERE relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  436. err = o.Exec(sql, edbRelationIds).Error
  437. if err != nil {
  438. return
  439. }
  440. // 新增间接引用
  441. relationCodesMap := make(map[string]struct{}, 0)
  442. if len(relationList) > 0 {
  443. for _, relation := range relationList {
  444. if relation.RelationType == 1 {
  445. relationCodesMap[relation.RelationCode] = struct{}{}
  446. }
  447. }
  448. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  449. if err != nil {
  450. return
  451. }
  452. }
  453. if len(refreshEdbInfoIds) > 0 {
  454. // todo 更新指标的刷新状态
  455. sql = ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  456. err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
  457. if err != nil {
  458. return
  459. }
  460. }
  461. //更新数据源钢联化工指标
  462. if len(indexCodeList) > 0 {
  463. // 更改数据源的更新状态
  464. sql = ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  465. err = o.Exec(sql, indexCodeList).Error
  466. if err != nil {
  467. return
  468. }
  469. }
  470. if len(relationList) > 0 {
  471. // 更新间接引用指标的关联ID
  472. relationCodes := make([]string, 0)
  473. for relationCode := range relationCodesMap {
  474. relationCodes = append(relationCodes, relationCode)
  475. }
  476. if len(relationCodes) > 0 {
  477. sql = ` UPDATE edb_info_relation e1
  478. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  479. SET e1.parent_relation_id = e2.edb_info_relation_id
  480. WHERE
  481. e1.relation_type = 1
  482. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  483. err = o.Exec(sql, relationCodes).Error
  484. if err != nil {
  485. return
  486. }
  487. }
  488. }
  489. return
  490. }