edb_info_relation.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package data_manage
  2. import (
  3. "eta/eta_task/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. func AddEdbInfoRelationMulti(items []*EdbInfoRelation) (err error) {
  27. o := orm.NewOrmUsingDB("data")
  28. _, err = o.InsertMulti(len(items), items)
  29. return
  30. }
  31. // GetEdbInfoRelationByEdbInfoIds 查询引用的指标ID
  32. func GetEdbInfoRelationByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error) {
  33. o := orm.NewOrmUsingDB("data")
  34. msql := ` SELECT edb_info_id FROM edb_info_relation WHERE edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) GROUP BY edb_info_id `
  35. _, err = o.Raw(msql, edbInfoIds).QueryRows(&edbIds)
  36. if err != nil {
  37. return
  38. }
  39. return
  40. }
  41. // GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
  42. func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=? AND relation_type=0`
  45. _, err = o.Raw(msql, referObjectIds, referObjectType).QueryRows(&items)
  46. return
  47. }