edb_info_relation.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "eta/eta_index_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbInfoRelation struct {
  8. EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk"`
  9. EdbInfoId int `description:"指标id"`
  10. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"`
  11. EdbName string `description:"指标名称"`
  12. EdbCode string `description:"指标编码"`
  13. ReferObjectId int `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
  14. ReferObjectType int `description:"引用对象ID类型(1.图表,2.ETA逻辑)"`
  15. ReferObjectSubType int `description:"引用对象子类"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. RelationTime time.Time `description:"引用时间"`
  19. RelationType int `description:"引用类型,0:直接饮用,1间接引用"`
  20. RootEdbInfoId int `description:"间接引用时,关联的直接引用的指标ID"`
  21. ChildEdbInfoId int `description:"间接引用时,计算指标直接关联的指标ID"`
  22. }
  23. func (e *EdbInfoRelation) TableName() string {
  24. return "edb_info_relation"
  25. }
  26. // GetEdbInfoRelationByChildEdbInfoId 查询引用的指标ID
  27. func GetEdbInfoRelationByChildEdbInfoId(edbInfoId int) (item *EdbInfoRelation, err error) {
  28. o := orm.NewOrm()
  29. msql := ` SELECT * FROM edb_info_relation WHERE child_edb_info_id = ?`
  30. err = o.Raw(msql, edbInfoId).QueryRow(&item)
  31. return
  32. }
  33. // GetEdbInfoRelationListByChildEdbInfoId 根据间接引用中的的计算指标ID查询引用列表
  34. func GetEdbInfoRelationListByChildEdbInfoId(edbInfoId int) (items []*EdbInfoRelation, err error) {
  35. o := orm.NewOrm()
  36. msql := ` SELECT * FROM edb_info_relation WHERE relation_type=1 AND child_edb_info_id=? `
  37. _, err = o.Raw(msql, edbInfoId).QueryRows(&items)
  38. return
  39. }
  40. // 新增记录
  41. func AddOrUpdateEdbInfoRelationByChildEdbInfoId(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string, deleteRelationIds []int) (err error) {
  42. o, err := orm.NewOrm().Begin()
  43. if err != nil {
  44. return
  45. }
  46. defer func() {
  47. if err != nil {
  48. _ = o.Rollback()
  49. return
  50. }
  51. _ = o.Commit()
  52. }()
  53. if len(relationList) > 0 {
  54. _, err = o.InsertMulti(len(relationList), relationList)
  55. if err != nil {
  56. return
  57. }
  58. }
  59. if len(deleteRelationIds) > 0 {
  60. // 删除对应的记录
  61. sql := ` DELETE FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(deleteRelationIds)) + `)`
  62. _, err = o.Raw(sql, deleteRelationIds).Exec()
  63. if err != nil {
  64. return
  65. }
  66. }
  67. if len(refreshEdbInfoIds) > 0 {
  68. // todo 更新指标的刷新状态
  69. sql := ` UPDATE edb_info SET no_update = 0 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
  70. _, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, refreshEdbInfoIds).Exec()
  71. if err != nil {
  72. return
  73. }
  74. }
  75. //更新数据源钢联化工指标
  76. if len(indexCodeList) > 0 {
  77. // 更改数据源的更新状态
  78. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
  79. _, err = o.Raw(sql, indexCodeList).Exec()
  80. if err != nil {
  81. return
  82. }
  83. }
  84. // todo 由此被禁用的计算指标是否能恢复刷新
  85. return
  86. }