edb_info_relation.go 19 KB

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