edb_info_calculate_mapping.go 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // Seal 计算指标于基础指标,关系表
  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. type EdbInfoCalculateMappingInfo struct {
  65. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  66. EdbInfoId int `description:"计算指标id"`
  67. Source int `description:"计算指标来源"`
  68. SourceName string `description:"计算指标来源名称"`
  69. EdbCode string `description:"计算指标编码"`
  70. FromEdbInfoId int `description:"基础指标id"`
  71. FromEdbCode string `description:"基础指标编码"`
  72. FromEdbName string `description:"基础指标名称"`
  73. FromSource int `description:"基础指标来源"`
  74. FromSourceName string `description:"基础指标来源名称"`
  75. MoveValue int `description:"领先值"`
  76. FromTag string `description:"来源指标标签"`
  77. Sort int `description:"计算指标名称排序"`
  78. CreateTime time.Time `description:"创建时间"`
  79. ModifyTime time.Time `description:"修改时间"`
  80. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  81. }
  82. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  83. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT a.*,b.edb_type FROM edb_info_calculate_mapping AS a
  86. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  87. WHERE a.edb_info_id=? `
  88. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  89. return
  90. }