edb_info_calculate_mapping.go 6.3 KB

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