edb_info_relation.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  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 := orm.NewOrmUsingDB("data")
  32. msql := ` SELECT * FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
  33. _, err = o.Raw(msql, ids).QueryRows(&items)
  34. return
  35. }
  36. // GetEdbInfoRelationByReferObjectId 查询直接引用的指标ID
  37. func GetEdbInfoRelationByReferObjectId(referObjectId int, referObjectType int) (items []*EdbInfoRelation, err error) {
  38. o := orm.NewOrmUsingDB("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).QueryRows(&items)
  41. return
  42. }
  43. // GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
  44. func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
  45. o := orm.NewOrmUsingDB("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).QueryRows(&items)
  48. return
  49. }
  50. // GetEdbInfoRelationAllByReferObjectIds 查询引用的指标ID
  51. func GetEdbInfoRelationAllByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
  52. o := orm.NewOrmUsingDB("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).QueryRows(&items)
  55. return
  56. }
  57. // 新增记录
  58. func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInfoRelation, deleteEdbInfoIds []int, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  59. o, err := orm.NewOrmUsingDB("data").Begin()
  60. if err != nil {
  61. return
  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.Raw(sql, objectId, objectType, deleteEdbInfoIds).Exec()
  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.Raw(sql, objectId, objectType, deleteEdbInfoIds).Exec()
  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.InsertMulti(len(relationList), relationList)
  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.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
  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.Raw(sql, indexCodeList).Exec()
  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.Raw(sql, relationCodes).Exec()
  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, err := orm.NewOrmUsingDB("data").Begin()
  136. if err != nil {
  137. return
  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.InsertMulti(len(relationList), relationList)
  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.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
  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.Raw(sql, indexCodeList).Exec()
  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.Raw(sql, relationCodes).Exec()
  189. if err != nil {
  190. return
  191. }
  192. }
  193. }
  194. return
  195. }
  196. // 删除指标引用内容
  197. func DeleteEdbRelationByObjectIds(referObjectIds []int, referObjectType int) (err error) {
  198. o := orm.NewOrmUsingDB("data")
  199. sql := ` DELETE FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
  200. _, err = o.Raw(sql, referObjectIds, referObjectType).Exec()
  201. return
  202. }
  203. // DeleteEdbRelationByObjectId 删除指标引用内容
  204. func DeleteEdbRelationByObjectId(referObjectId int, referObjectType int) (err error) {
  205. o := orm.NewOrmUsingDB("data")
  206. sql := ` DELETE FROM edb_info_relation WHERE refer_object_id =? AND refer_object_type=?`
  207. _, err = o.Raw(sql, referObjectId, referObjectType).Exec()
  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"`
  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 := orm.NewOrmUsingDB("data")
  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).QueryRow(&total)
  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. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  276. return
  277. }
  278. // GetEdbInfoRelationDetailList 查询指标引用详情列表
  279. func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total int, items []*EdbInfoRelation, err error) {
  280. o := orm.NewOrmUsingDB("data")
  281. // 数量汇总
  282. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=?`
  283. err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
  284. if err != nil {
  285. return
  286. }
  287. // 列表数据
  288. sql := ` SELECT *FROM edb_info_relation where edb_info_id=? ORDER BY relation_time desc, edb_info_id ASC `
  289. sql += ` LIMIT ?,? `
  290. _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
  291. return
  292. }
  293. // 查询相关的指标记录总数
  294. func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  295. o := orm.NewOrmUsingDB("data")
  296. // 数量汇总
  297. 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`
  298. err = o.Raw(totalSql, edbInfoId, edbInfoId).QueryRow(&total)
  299. if err != nil {
  300. return
  301. }
  302. return
  303. }
  304. // 查询相关的指标记录列表
  305. func GetReplaceChildEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  306. o := orm.NewOrmUsingDB("data")
  307. // 列表数据
  308. 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 ?,? `
  309. _, err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).QueryRows(&items)
  310. return
  311. }
  312. // 查询相关的指标记录总数
  313. func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
  314. o := orm.NewOrmUsingDB("data")
  315. // 数量汇总
  316. totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=? and relation_type = 0`
  317. err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
  318. if err != nil {
  319. return
  320. }
  321. return
  322. }
  323. // 查询相关的指标记录列表
  324. func GetReplaceEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
  325. o := orm.NewOrmUsingDB("data")
  326. // 列表数据
  327. sql := ` SELECT * FROM edb_info_relation where edb_info_id=? and relation_type = 0 ORDER BY edb_info_relation_id ASC LIMIT ?,? `
  328. _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
  329. return
  330. }
  331. // 替换指标引用表中直接引用的指标
  332. func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  333. o, err := orm.NewOrmUsingDB("data").Begin()
  334. if err != nil {
  335. return
  336. }
  337. defer func() {
  338. if err != nil {
  339. _ = o.Rollback()
  340. return
  341. }
  342. _ = o.Commit()
  343. }()
  344. now := time.Now()
  345. // 删除相关的间接引用
  346. sql := ` DELETE FROM edb_info_relation WHERE root_edb_info_id=? and relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  347. _, err = o.Raw(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
  348. if err != nil {
  349. return
  350. }
  351. sourceWhere := ` and (refer_object_type in (1,2,5) or (refer_object_type=4 and refer_object_sub_type !=5) )` //平衡表和事件日历中的直接引用无需替换,
  352. // 替换edb_info_id
  353. 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)) + `)`
  354. _, err = o.Raw(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
  355. if err != nil {
  356. return
  357. }
  358. // 更新code值
  359. 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)) + `)`
  360. _, err = o.Raw(sql, edbRelationIds).Exec()
  361. if err != nil {
  362. return
  363. }
  364. // 新增间接引用
  365. relationCodesMap := make(map[string]struct{}, 0)
  366. if len(relationList) > 0 {
  367. for _, relation := range relationList {
  368. if relation.RelationType == 1 {
  369. relationCodesMap[relation.RelationCode] = struct{}{}
  370. }
  371. }
  372. _, err = o.InsertMulti(len(relationList), relationList)
  373. if err != nil {
  374. return
  375. }
  376. }
  377. if len(refreshEdbInfoIds) > 0 {
  378. // todo 更新指标的刷新状态
  379. sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  380. _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
  381. if err != nil {
  382. return
  383. }
  384. }
  385. //更新数据源钢联化工指标
  386. if len(indexCodeList) > 0 {
  387. // 更改数据源的更新状态
  388. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  389. _, err = o.Raw(sql, indexCodeList).Exec()
  390. if err != nil {
  391. return
  392. }
  393. }
  394. if len(relationList) > 0 {
  395. // 更新间接引用指标的关联ID
  396. relationCodes := make([]string, 0)
  397. for relationCode := range relationCodesMap {
  398. relationCodes = append(relationCodes, relationCode)
  399. }
  400. if len(relationCodes) > 0 {
  401. sql := ` UPDATE edb_info_relation e1
  402. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  403. SET e1.parent_relation_id = e2.edb_info_relation_id
  404. WHERE
  405. e1.relation_type = 1
  406. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  407. _, err = o.Raw(sql, relationCodes).Exec()
  408. if err != nil {
  409. return
  410. }
  411. }
  412. }
  413. return
  414. }
  415. // UpdateSecondRelationEdbInfoId 更新指标替换后的间接引用记录
  416. func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
  417. o, err := orm.NewOrmUsingDB("data").Begin()
  418. if err != nil {
  419. return
  420. }
  421. defer func() {
  422. if err != nil {
  423. _ = o.Rollback()
  424. return
  425. }
  426. _ = o.Commit()
  427. }()
  428. // 删除相关的间接引用
  429. sql := ` DELETE FROM edb_info_relation WHERE relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
  430. _, err = o.Raw(sql, edbRelationIds).Exec()
  431. if err != nil {
  432. return
  433. }
  434. // 新增间接引用
  435. relationCodesMap := make(map[string]struct{}, 0)
  436. if len(relationList) > 0 {
  437. for _, relation := range relationList {
  438. if relation.RelationType == 1 {
  439. relationCodesMap[relation.RelationCode] = struct{}{}
  440. }
  441. }
  442. _, err = o.InsertMulti(len(relationList), relationList)
  443. if err != nil {
  444. return
  445. }
  446. }
  447. if len(refreshEdbInfoIds) > 0 {
  448. // todo 更新指标的刷新状态
  449. sql = ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
  450. _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
  451. if err != nil {
  452. return
  453. }
  454. }
  455. //更新数据源钢联化工指标
  456. if len(indexCodeList) > 0 {
  457. // 更改数据源的更新状态
  458. sql = ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  459. _, err = o.Raw(sql, indexCodeList).Exec()
  460. if err != nil {
  461. return
  462. }
  463. }
  464. if len(relationList) > 0 {
  465. // 更新间接引用指标的关联ID
  466. relationCodes := make([]string, 0)
  467. for relationCode := range relationCodesMap {
  468. relationCodes = append(relationCodes, relationCode)
  469. }
  470. if len(relationCodes) > 0 {
  471. sql = ` UPDATE edb_info_relation e1
  472. JOIN edb_info_relation e2 ON e1.relation_code = e2.relation_code
  473. SET e1.parent_relation_id = e2.edb_info_relation_id
  474. WHERE
  475. e1.relation_type = 1
  476. AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
  477. _, err = o.Raw(sql, relationCodes).Exec()
  478. if err != nil {
  479. return
  480. }
  481. }
  482. }
  483. return
  484. }