variety_plant.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package supply_analysis
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // VarietyPlant variety_plant 品种装置表
  7. type VarietyPlant struct {
  8. VarietyPlantId int `orm:"column(variety_plant_id);pk"`
  9. VarietyId int `description:"品种id"`
  10. Province string `description:"所属省份"`
  11. City string `description:"所属城市"`
  12. FactoryName string `description:"工厂名称"`
  13. PlantName string `description:"装置/产线名称"`
  14. MaintenanceDate time.Time `description:"检修日期"`
  15. ResumptionDate time.Time `description:"复产日期"`
  16. AnnualCapacity float64 `description:"年产能"`
  17. Coefficient float64 `description:"降负系数"`
  18. AverageDailyCapacityReduction float64 `description:"日均产量减量"`
  19. IsStop int `description:"是否停产,0:未停产;1:停产;默认未停产"`
  20. Sort int `description:"排序字段,越小越靠前"`
  21. SysUserId int `description:"添加人id"`
  22. SysUserRealName string `description:"添加人真实姓名"`
  23. ModifyTime time.Time `description:"最近一次更新时间"`
  24. CreateTime time.Time `description:"添加时间"`
  25. }
  26. // GetAllVarietyPlantByVarietyId 根据品种id获取所有的装置
  27. func GetAllVarietyPlantByVarietyId(varietyId int) (items []*VarietyPlant, err error) {
  28. o := orm.NewOrm()
  29. sql := `SELECT * FROM variety_plant a WHERE variety_id = ? ORDER BY variety_plant_id desc `
  30. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  31. return
  32. }
  33. // AddVarietyPlant 添加future_good_chart分类
  34. func AddVarietyPlant(item *VarietyPlant) (err error) {
  35. o := orm.NewOrm()
  36. lastId, err := o.Insert(item)
  37. if err != nil {
  38. return
  39. }
  40. item.VarietyPlantId = int(lastId)
  41. return
  42. }
  43. // Update 更新基础信息
  44. func (varietyPlant *VarietyPlant) Update(cols []string) (err error) {
  45. o := orm.NewOrm()
  46. _, err = o.Update(varietyPlant, cols...)
  47. return
  48. }
  49. // GetVarietyPlantById 根据品种装置id获取品种装置详情
  50. func GetVarietyPlantById(id int) (item *VarietyPlant, err error) {
  51. o := orm.NewOrm()
  52. sql := `SELECT * FROM variety_plant WHERE variety_plant_id = ?`
  53. err = o.Raw(sql, id).QueryRow(&item)
  54. return
  55. }
  56. // VarietyPlantItem 品种装置数据(展示使用)
  57. type VarietyPlantItem struct {
  58. VarietyPlantId int `orm:"column(variety_plant_id);pk"`
  59. VarietyId int `description:"品种id"`
  60. Province string `description:"所属省份"`
  61. City string `description:"所属城市"`
  62. FactoryName string `description:"工厂名称"`
  63. PlantName string `description:"装置/产线名称"`
  64. MaintenanceDate string `description:"检修日期"`
  65. ResumptionDate string `description:"复产日期"`
  66. AnnualCapacity float64 `description:"年产能"`
  67. Coefficient float64 `description:"降负系数"`
  68. AverageDailyCapacityReduction float64 `description:"日均产量减量"`
  69. IsStop int `description:"是否停产,0:未停产;1:停产;默认未停产"`
  70. Sort int `description:"排序字段,越小越靠前"`
  71. SysUserId int `description:"添加人id"`
  72. SysUserRealName string `description:"添加人真实姓名"`
  73. ModifyTime string `description:"最近一次更新时间"`
  74. CreateTime string `description:"添加时间"`
  75. Button VarietyPlantButton `description:"操作按钮权限"`
  76. }
  77. type VarietyPlantButton struct {
  78. Edit bool `description:"操作权限"`
  79. Delete bool `description:"删除权限"`
  80. }
  81. // GetAllVarietyPlantItemByVarietyId 根据品种id获取所有的装置
  82. func GetAllVarietyPlantItemByVarietyId(varietyId int) (items []*VarietyPlantItem, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT * FROM variety_plant a WHERE variety_id = ? ORDER BY variety_plant_id desc `
  85. _, err = o.Raw(sql, varietyId).QueryRows(&items)
  86. return
  87. }
  88. // GetCountVarietyPlantByVarietyId 根据品种id获取所有的装置数量
  89. func GetCountVarietyPlantByVarietyId(varietyId int) (total int, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT count(1) total FROM variety_plant a WHERE variety_id = ? `
  92. err = o.Raw(sql, varietyId).QueryRow(&total)
  93. return
  94. }
  95. // DeleteVarietyPlantById 根据装置id删除
  96. func DeleteVarietyPlantById(id int) (err error) {
  97. o := orm.NewOrm()
  98. sql := `DELETE FROM variety_plant WHERE variety_plant_id = ?`
  99. _, err = o.Raw(sql, id).Exec()
  100. return
  101. }