edb_info_relation.go 19 KB

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