variety_plant.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package supply_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type VarietyPlant struct {
  8. VarietyPlantId int `orm:"column(variety_plant_id);pk" gorm:"primaryKey" `
  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. func AddVarietyPlant(item *VarietyPlant) (err error) {
  27. err = global.DmSQL["data"].Create(item).Error
  28. return
  29. }
  30. func MultiAddVarietyPlant(items []*VarietyPlant) (err error) {
  31. err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
  32. return
  33. }
  34. func (varietyPlant *VarietyPlant) Update(cols []string) (err error) {
  35. err = global.DmSQL["data"].Select(cols).Updates(varietyPlant).Error
  36. return
  37. }
  38. func GetVarietyPlantById(id int) (item *VarietyPlant, err error) {
  39. sql := `SELECT * FROM variety_plant WHERE variety_plant_id = ?`
  40. err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
  41. return
  42. }
  43. func GetVarietyPlantByIdList(idList []int) (items []*VarietyPlant, err error) {
  44. num := len(idList)
  45. if num <= 0 {
  46. return
  47. }
  48. sql := `SELECT * FROM variety_plant WHERE variety_plant_id in (` + utils.GetOrmInReplace(num) + `)`
  49. err = global.DmSQL["data"].Raw(sql, idList).Scan(&items).Error
  50. return
  51. }
  52. type VarietyPlantItem struct {
  53. VarietyPlantId int `orm:"column(variety_plant_id);pk" gorm:"primaryKey" `
  54. VarietyId int `description:"品种id"`
  55. Province string `description:"所属省份"`
  56. City string `description:"所属城市"`
  57. FactoryName string `description:"工厂名称"`
  58. PlantName string `description:"装置/产线名称"`
  59. MaintenanceDate string `description:"检修日期"`
  60. ResumptionDate string `description:"复产日期"`
  61. AnnualCapacity float64 `description:"年产能"`
  62. Coefficient float64 `description:"降负系数"`
  63. AverageDailyCapacityReduction float64 `description:"日均产量减量"`
  64. Day int `description:"时长"`
  65. CapacityReduction float64 `description:"期间减量"`
  66. IsStop int `description:"是否停产,0:未停产;1:停产;默认未停产"`
  67. Sort int `description:"排序字段,越小越靠前"`
  68. SysUserId int `description:"添加人id"`
  69. SysUserRealName string `description:"添加人真实姓名"`
  70. ModifyTime string `description:"最近一次更新时间"`
  71. CreateTime string `description:"添加时间"`
  72. Button VarietyPlantButton `gorm:"-" description:"操作按钮权限"`
  73. }
  74. type VarietyPlantButton struct {
  75. Edit bool `description:"操作权限"`
  76. Delete bool `description:"删除权限"`
  77. }
  78. func GetAllVarietyPlantByVarietyId(varietyId int) (items []*VarietyPlantItem, err error) {
  79. sql := `SELECT * FROM variety_plant a WHERE variety_id = ? ORDER BY sort ASC, variety_plant_id ASC `
  80. err = global.DmSQL["data"].Raw(sql, varietyId).Scan(&items).Error
  81. return
  82. }
  83. func GetCountVarietyPlantByVarietyId(varietyId int) (total int, err error) {
  84. sql := `SELECT count(1) total FROM variety_plant a WHERE variety_id = ? `
  85. err = global.DmSQL["data"].Raw(sql, varietyId).Scan(&total).Error
  86. return
  87. }
  88. func DeleteVarietyPlantById(id int) (err error) {
  89. sql := `DELETE FROM variety_plant WHERE variety_plant_id = ?`
  90. err = global.DmSQL["data"].Exec(sql, id).Error
  91. return
  92. }
  93. func UpdateEdbInfoSortByPrevId(varietyId, prevVarietyId, nowSort int, updateSort string) (err error) {
  94. sql := `UPDATE variety_plant set sort = ` + updateSort + ` WHERE variety_id=? AND `
  95. if prevVarietyId > 0 {
  96. sql += ` ( sort > ? or ( sort=? AND variety_plant_id > ?)) `
  97. }
  98. err = global.DmSQL["data"].Exec(sql, varietyId, nowSort, nowSort, prevVarietyId).Error
  99. return
  100. }
  101. func UpdateEdbInfoSortByNextId(varietyId, prevVarietyId, nowSort int, updateSort string) (err error) {
  102. sql := `UPDATE variety_plant set sort = ` + updateSort + ` WHERE variety_id=? AND `
  103. if prevVarietyId > 0 {
  104. sql += ` ( sort < ? or ( sort=? AND variety_plant_id < ? )) `
  105. }
  106. err = global.DmSQL["data"].Exec(sql, varietyId, nowSort, nowSort, prevVarietyId).Error
  107. return
  108. }
  109. func (m *VarietyPlantItem) ConvertToResp() {
  110. m.CreateTime = utils.GormDateStrToDateStr(m.CreateTime)
  111. m.ModifyTime = utils.GormDateStrToDateStr(m.ModifyTime)
  112. m.MaintenanceDate = utils.GormDateStrToDateStr(m.MaintenanceDate)
  113. m.ResumptionDate = utils.GormDateStrToDateStr(m.ResumptionDate)
  114. return
  115. }