variety_plant.go 6.5 KB

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