edb_info_calculate_mapping.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. // EdbInfoCalculateMapping 计算指标于基础指标,关系表
  8. type EdbInfoCalculateMapping struct {
  9. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  10. EdbInfoId int `description:"计算指标id"`
  11. Source int `description:"计算指标来源"`
  12. SourceName string `description:"计算指标来源名称"`
  13. EdbCode string `description:"计算指标编码"`
  14. FromEdbInfoId int `description:"基础指标id"`
  15. FromEdbCode string `description:"基础指标编码"`
  16. FromEdbName string `description:"基础指标名称"`
  17. FromSource int `description:"基础指标来源"`
  18. FromSourceName string `description:"基础指标来源名称"`
  19. FromTag string `description:"来源指标标签"`
  20. Sort int `description:"计算指标名称排序"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. }
  24. func (e *EdbInfoCalculateMapping) Insert() (err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. _, err = o.Insert(e)
  27. return
  28. }
  29. func AddEdbInfoCalculateMappingMulti(items []*EdbInfoCalculateMapping) (err error) {
  30. o := orm.NewOrmUsingDB("data")
  31. _, err = o.InsertMulti(1, items)
  32. return
  33. }
  34. func GetEdbInfoCalculateMappingCount(edbInfoId int) (count int, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE from_edb_info_id=? `
  37. err = o.Raw(sql, edbInfoId).QueryRow(&count)
  38. return
  39. }
  40. type EdbInfoCalculateMappingView struct {
  41. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  42. EdbInfoId int `description:"计算指标id"`
  43. Source int `description:"计算指标来源"`
  44. SourceName string `description:"计算指标来源名称"`
  45. EdbCode string `description:"计算指标编码"`
  46. FromEdbInfoId int `description:"基础指标id"`
  47. FromEdbCode string `description:"基础指标编码"`
  48. FromEdbName string `description:"基础指标名称"`
  49. FromSource int `description:"基础指标来源"`
  50. FromSourceName string `description:"基础指标来源名称"`
  51. FromTag string `description:"来源指标标签"`
  52. Sort int `description:"计算指标名称排序"`
  53. CreateTime time.Time `description:"创建时间"`
  54. ModifyTime time.Time `description:"修改时间"`
  55. StartDate string `description:"开始日期"`
  56. EndDate string `description:"结束日期"`
  57. CalculateFormula string `description:"N值"`
  58. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  59. MoveFrequency string `description:"移动频度"`
  60. }
  61. func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
  62. o := orm.NewOrmUsingDB("data")
  63. sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
  64. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  65. WHERE a.edb_info_id=? `
  66. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  67. return
  68. }
  69. // EdbInfoCalculateMappingInfo
  70. // @Description: 计算指标与基础指标关系表
  71. type EdbInfoCalculateMappingInfo struct {
  72. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  73. EdbInfoId int `description:"计算指标id"`
  74. Source int `description:"计算指标来源"`
  75. SourceName string `description:"计算指标来源名称"`
  76. EdbCode string `description:"计算指标编码"`
  77. FromEdbInfoId int `description:"基础指标id"`
  78. FromEdbCode string `description:"基础指标编码"`
  79. FromEdbName string `description:"基础指标名称"`
  80. FromSource int `description:"基础指标来源"`
  81. FromSourceName string `description:"基础指标来源名称"`
  82. MoveValue int `description:"领先值"`
  83. FromTag string `description:"来源指标标签"`
  84. Sort int `description:"计算指标名称排序"`
  85. CreateTime time.Time `description:"创建时间"`
  86. ModifyTime time.Time `description:"修改时间"`
  87. FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
  88. FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
  89. FromClassifyId int `description:"来源指标分类ID"`
  90. FromUniqueCode string `description:"来源指标唯一编码"`
  91. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  92. }
  93. func (e *EdbInfoCalculateMappingInfo) Insert() (err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. _, err = o.Insert(e)
  96. return
  97. }
  98. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  99. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  100. o := orm.NewOrmUsingDB("data")
  101. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  102. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  103. WHERE a.edb_info_id=? `
  104. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  105. return
  106. }
  107. // GetEdbInfoCalculateMappingListByEdbInfoIds 根据生成的指标id获取来源的指标id列表
  108. func GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds []int) (items []*EdbInfoCalculateMappingInfo, err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  111. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  112. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  113. _, err = o.Raw(sql, edbInfoIds).QueryRows(&items)
  114. return
  115. }