edb_info_relation.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type EdbInfoRelation struct {
  9. EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk"`
  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 `
  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"`
  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. err = o.Raw(sql, pars, startSize, pageSize).Scan(&items).Error
  269. return
  270. }
  271. // GetEdbInfoRelationDetailList 查询指标引用详情列表
  272. func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total int, items []*EdbInfoRelation, err error) {
  273. o := global.DmSQL["data"]
  274. // 数量汇总
  275. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=?`
  276. err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
  277. if err != nil {
  278. return
  279. }
  280. // 列表数据
  281. sql := ` SELECT * FROM edb_info_relation where edb_info_id=? ORDER BY relation_time desc, edb_info_id ASC `
  282. sql += ` LIMIT ?,? `
  283. err = o.Raw(sql, edbInfoId, startSize, pageSize).Find(&items).Error
  284. return
  285. }
  286. // 查询相关的指标记录总数
  287. func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  288. o := global.DmSQL["data"]
  289. // 数量汇总
  290. 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`
  291. err = o.Raw(totalSql, edbInfoId, edbInfoId).Scan(&total).Error
  292. if err != nil {
  293. return
  294. }
  295. return
  296. }
  297. // 查询相关的指标记录列表
  298. func GetReplaceChildEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  299. o := global.DmSQL["data"]
  300. // 列表数据
  301. 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 ?,? `
  302. err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).Scan(&items).Error
  303. return
  304. }
  305. // 查询相关的指标记录总数
  306. func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  307. o := global.DmSQL["data"]
  308. // 数量汇总
  309. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=? and relation_type = 0`
  310. err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
  311. if err != nil {
  312. return
  313. }
  314. return
  315. }
  316. // 查询相关的指标记录列表
  317. func GetReplaceEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  318. o := global.DmSQL["data"]
  319. // 列表数据
  320. sql := ` SELECT * FROM edb_info_relation where edb_info_id=? and relation_type = 0 ORDER BY edb_info_relation_id ASC LIMIT ?,? `
  321. err = o.Raw(sql, edbInfoId, startSize, pageSize).Scan(&items).Error
  322. return
  323. }
  324. // 替换指标引用表中直接引用的指标
  325. func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  326. o := global.DmSQL["data"].Begin()
  327. defer func() {
  328. if err != nil {
  329. _ = o.Rollback()
  330. return
  331. }
  332. _ = o.Commit()
  333. }()
  334. now := time.Now()
  335. // 删除相关的间接引用
  336. sql := ` DELETE FROM edb_info_relation WHERE root_edb_info_id=? and relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  337. err = o.Exec(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Error
  338. if err != nil {
  339. return
  340. }
  341. sourceWhere := ` and (refer_object_type in (1,2 ) or (refer_object_type=4 and refer_object_sub_type !=5) )` //平衡表和事件日历中的直接引用无需替换,
  342. // 替换edb_info_id
  343. 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)) + `)`
  344. err = o.Exec(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Error
  345. if err != nil {
  346. return
  347. }
  348. // 更新code值
  349. 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)) + `)`
  350. err = o.Exec(sql, edbRelationIds).Error
  351. if err != nil {
  352. return
  353. }
  354. // 新增间接引用
  355. relationCodesMap := make(map[string]struct{}, 0)
  356. if len(relationList) > 0 {
  357. for _, relation := range relationList {
  358. if relation.RelationType == 1 {
  359. relationCodesMap[relation.RelationCode] = struct{}{}
  360. }
  361. }
  362. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  363. if err != nil {
  364. return
  365. }
  366. }
  367. if len(refreshEdbInfoIds) > 0 {
  368. // todo 更新指标的刷新状态
  369. sql := ` UPDATE edb_info SET no_update = 0 WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
  370. err = o.Exec(sql, refreshEdbInfoIds).Error
  371. if err != nil {
  372. return
  373. }
  374. }
  375. //更新数据源钢联化工指标
  376. if len(indexCodeList) > 0 {
  377. // 更改数据源的更新状态
  378. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  379. err = o.Exec(sql, indexCodeList).Error
  380. if err != nil {
  381. return
  382. }
  383. }
  384. if len(relationList) > 0 {
  385. // 更新间接引用指标的关联ID
  386. relationCodes := make([]string, 0)
  387. for relationCode := range relationCodesMap {
  388. relationCodes = append(relationCodes, relationCode)
  389. }
  390. if len(relationCodes) > 0 {
  391. sql := ` UPDATE edb_info_relation e1
  392. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  393. SET e1.parent_relation_id = e2.edb_info_relation_id
  394. WHERE
  395. e1.relation_type = 1
  396. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  397. err = o.Exec(sql, relationCodes).Error
  398. if err != nil {
  399. return
  400. }
  401. }
  402. }
  403. return
  404. }
  405. // UpdateSecondRelationEdbInfoId 更新指标替换后的间接引用记录
  406. func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  407. o := global.DmSQL["data"].Begin()
  408. defer func() {
  409. if err != nil {
  410. _ = o.Rollback()
  411. return
  412. }
  413. _ = o.Commit()
  414. }()
  415. // 删除相关的间接引用
  416. sql := ` DELETE FROM edb_info_relation WHERE relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  417. err = o.Exec(sql, edbRelationIds).Error
  418. if err != nil {
  419. return
  420. }
  421. // 新增间接引用
  422. relationCodesMap := make(map[string]struct{}, 0)
  423. if len(relationList) > 0 {
  424. for _, relation := range relationList {
  425. if relation.RelationType == 1 {
  426. relationCodesMap[relation.RelationCode] = struct{}{}
  427. }
  428. }
  429. err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
  430. if err != nil {
  431. return
  432. }
  433. }
  434. if len(refreshEdbInfoIds) > 0 {
  435. // todo 更新指标的刷新状态
  436. sql := ` UPDATE edb_info SET no_update = 0 WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
  437. err = o.Exec(sql, refreshEdbInfoIds).Error
  438. if err != nil {
  439. return
  440. }
  441. }
  442. //更新数据源钢联化工指标
  443. if len(indexCodeList) > 0 {
  444. // 更改数据源的更新状态
  445. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  446. err = o.Exec(sql, indexCodeList).Error
  447. if err != nil {
  448. return
  449. }
  450. }
  451. if len(relationList) > 0 {
  452. // 更新间接引用指标的关联ID
  453. relationCodes := make([]string, 0)
  454. for relationCode := range relationCodesMap {
  455. relationCodes = append(relationCodes, relationCode)
  456. }
  457. if len(relationCodes) > 0 {
  458. sql := ` UPDATE edb_info_relation e1
  459. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  460. SET e1.parent_relation_id = e2.edb_info_relation_id
  461. WHERE
  462. e1.relation_type = 1
  463. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  464. err = o.Exec(sql, relationCodes).Error
  465. if err != nil {
  466. return
  467. }
  468. }
  469. }
  470. return
  471. }