variety_edb_info.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // GetAllVarietyEdbInfoByVarietyId 根据品种id获取所有的指标
  22. func GetAllVarietyEdbInfoByVarietyId(varietyId int) (items []*VarietyEdbInfo, err error) {
  23. o := orm.NewOrm()
  24. sql := `SELECT * FROM variety_edb_info AS a WHERE a.variety_id = ? ORDER BY a.variety_edb_id ASC `
  25. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  26. return
  27. }
  28. // GetVarietyEdbInfoByEdbInfoId 根据ETA指标库中的指标id获取指标
  29. func GetVarietyEdbInfoByEdbInfoId(varietyId int) (item *VarietyEdbInfo, err error) {
  30. o := orm.NewOrm()
  31. sql := `SELECT * FROM variety_edb_info AS a WHERE a.edb_info_id = ? ORDER BY a.variety_edb_id ASC `
  32. err = o.Raw(sql, varietyId).QueryRow(&item)
  33. return
  34. }
  35. // BatchCreateVarietyEdbInfo 批量插入
  36. func BatchCreateVarietyEdbInfo(list []*VarietyEdbInfo) (err error) {
  37. num := len(list)
  38. if num <= 0 {
  39. return
  40. }
  41. o := orm.NewOrm()
  42. _, err = o.InsertMulti(num, list)
  43. return
  44. }
  45. // GetCountVarietyEdbByVarietyId 根据品种id获取添加到已经生成的指标数量(不管是否加入到ETA指标库)
  46. func GetCountVarietyEdbByVarietyId(varietyId int) (total int, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT count(1) total FROM variety_edb_info AS a WHERE a.variety_id = ?`
  49. err = o.Raw(sql, varietyId).QueryRow(&total)
  50. return
  51. }
  52. // GetCountVarietyEdbInfoByVarietyId 根据品种id获取添加到ETA指标库的指标数量
  53. func GetCountVarietyEdbInfoByVarietyId(varietyId int) (total int, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT count(1) total FROM variety_edb_info AS a
  56. JOIN edb_info b on a.edb_info_id=b.edb_info_id
  57. WHERE a.variety_id = ? and a.edb_info_id >0`
  58. err = o.Raw(sql, varietyId).QueryRow(&total)
  59. return
  60. }
  61. // VarietyEdbInfoItem 品种指标表(展示使用)
  62. type VarietyEdbInfoItem struct {
  63. VarietyEdbId int `orm:"column(variety_edb_id);pk"`
  64. VarietyId int `description:"品种id"`
  65. EdbName string `description:"品种指标名称"`
  66. Frequency string `description:"频度"`
  67. StartDate string `description:"开始日期"`
  68. EndDate string `description:"结束日期"`
  69. EdbInfoId int `description:"指标id" json:"-"`
  70. EdbCode string `description:"品种编码"`
  71. ClassifyName string `description:"分类名称"`
  72. Source int `description:"来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动" json:"-"`
  73. ModifyTime string `description:"最近一次更新时间"`
  74. CreateTime string `description:"添加时间"`
  75. Button VarietyEdbInfoButton `description:"操作按钮权限"`
  76. }
  77. type VarietyEdbInfoButton struct {
  78. Copy bool `description:"复制数据权限"`
  79. Show bool `description:"查看数据权限"`
  80. Add bool `description:"添加到指标库"`
  81. }
  82. // GetAllVarietyEdbInfoItemByVarietyId 根据品种id获取所有的指标
  83. func GetAllVarietyEdbInfoItemByVarietyId(varietyId int) (items []*VarietyEdbInfoItem, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT * FROM variety_edb_info AS a WHERE a.variety_id = ? ORDER BY a.variety_edb_id ASC `
  86. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  87. return
  88. }