variety_plant.go 4.5 KB

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