variety_plant.go 6.4 KB

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