variety_plant.go 5.4 KB

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