edb_info_calculate_mapping.go 5.6 KB

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