edb_info_calculate_mapping.go 5.8 KB

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