variety_edb_info.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package supply_analysis
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // VarietyEdbInfo variety_edb_info 品种指标表
  7. type VarietyEdbInfo struct {
  8. VarietyEdbId int `orm:"column(variety_edb_id);pk"`
  9. VarietyId int `description:"品种id"`
  10. EdbName string `description:"品种指标名称"`
  11. Frequency string `description:"频度"`
  12. StartDate time.Time `description:"开始日期"`
  13. EndDate time.Time `description:"结束日期"`
  14. LatestValue float64 `description:"最新值"`
  15. EdbInfoId int `description:"指标id"`
  16. EdbCode string `description:"品种编码"`
  17. Source int `description:"来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动"`
  18. ModifyTime time.Time `description:"更新时间"`
  19. CreateTime time.Time `description:"添加时间"`
  20. }
  21. // BatchCreateVarietyEdbInfo 批量插入
  22. func BatchCreateVarietyEdbInfo(list []*VarietyEdbInfo) (err error) {
  23. num := len(list)
  24. if num <= 0 {
  25. return
  26. }
  27. o := orm.NewOrmUsingDB("data")
  28. _, err = o.InsertMulti(num, list)
  29. return
  30. }
  31. // GetCountVarietyEdbByVarietyId 根据品种id获取添加到已经生成的指标数量(不管是否加入到ETA指标库)
  32. func GetCountVarietyEdbByVarietyId(varietyId int) (total int, err error) {
  33. o := orm.NewOrmUsingDB("data")
  34. sql := `SELECT count(1) total FROM variety_edb_info AS a WHERE a.variety_id = ?`
  35. err = o.Raw(sql, varietyId).QueryRow(&total)
  36. return
  37. }
  38. // GetVarietyEdbListByVarietyId 根据品种id获取添加到已经生成的指标(不管是否加入到ETA指标库)
  39. func GetVarietyEdbListByVarietyId(varietyId int) (items []*VarietyEdbInfo, err error) {
  40. o := orm.NewOrmUsingDB("data")
  41. sql := `SELECT * FROM variety_edb_info AS a WHERE a.variety_id = ?`
  42. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  43. return
  44. }
  45. // GetCountVarietyEdbInfoByVarietyId 根据品种id获取添加到ETA指标库的指标数量
  46. func GetCountVarietyEdbInfoByVarietyId(varietyId int) (total int, err error) {
  47. o := orm.NewOrmUsingDB("data")
  48. sql := `SELECT count(1) total FROM variety_edb_info AS a
  49. JOIN edb_info b on a.edb_info_id=b.edb_info_id
  50. WHERE a.variety_id = ? and a.edb_info_id >0`
  51. err = o.Raw(sql, varietyId).QueryRow(&total)
  52. return
  53. }
  54. // VarietyEdbInfoItem 品种指标表(展示使用)
  55. type VarietyEdbInfoItem struct {
  56. VarietyEdbId int `orm:"column(variety_edb_id);pk"`
  57. VarietyId int `description:"品种id"`
  58. EdbName string `description:"品种指标名称"`
  59. Frequency string `description:"频度"`
  60. StartDate string `description:"开始日期"`
  61. EndDate string `description:"结束日期"`
  62. LatestValue float64 `description:"最新值"`
  63. EdbInfoId int `description:"指标id"`
  64. UniqueCode string `description:"唯一code"`
  65. EdbCode string `description:"品种编码"`
  66. ClassifyId int `description:"上级分类id"`
  67. ClassifyName string `description:"分类名称"`
  68. Source int `description:"来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动" json:"-"`
  69. ModifyTime string `description:"最近一次更新时间"`
  70. CreateTime string `description:"添加时间"`
  71. Button VarietyEdbInfoButton `description:"操作按钮权限"`
  72. }
  73. type VarietyEdbInfoButton struct {
  74. Copy bool `description:"复制数据权限"`
  75. Show bool `description:"查看数据权限"`
  76. Add bool `description:"添加到指标库"`
  77. }
  78. // GetAllVarietyEdbInfoByVarietyId 根据品种id获取所有的指标
  79. func GetAllVarietyEdbInfoByVarietyId(varietyId int) (items []*VarietyEdbInfoItem, err error) {
  80. o := orm.NewOrmUsingDB("data")
  81. sql := `SELECT * FROM variety_edb_info AS a WHERE a.variety_id = ? ORDER BY a.variety_edb_id ASC `
  82. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  83. return
  84. }
  85. // GetVarietyEdbInfoByVarietyEdbId 根据品种指标id获取的指标
  86. func GetVarietyEdbInfoByVarietyEdbId(varietyId int) (item *VarietyEdbInfo, err error) {
  87. o := orm.NewOrmUsingDB("data")
  88. sql := `SELECT * FROM variety_edb_info AS a WHERE a.variety_edb_id = ? ORDER BY a.variety_edb_id ASC `
  89. err = o.Raw(sql, varietyId).QueryRow(&item)
  90. return
  91. }
  92. // Update 更基础信息
  93. func (varietyEdbInfo *VarietyEdbInfo) Update(cols []string) (err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. _, err = o.Update(varietyEdbInfo, cols...)
  96. return
  97. }