unit_history.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  7. )
  8. type UnitHistoryService struct {
  9. }
  10. // CreateUnitHistory 创建UnitHistory记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (unitHistoryService *UnitHistoryService) CreateUnitHistory(unitHistory autocode.UnitHistory) (err error) {
  13. err = global.GVA_DB.Create(&unitHistory).Error
  14. return err
  15. }
  16. // DeleteUnitHistory 删除UnitHistory记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (unitHistoryService *UnitHistoryService) DeleteUnitHistory(unitHistory autocode.UnitHistory) (err error) {
  19. err = global.GVA_DB.Delete(&unitHistory).Error
  20. return err
  21. }
  22. // DeleteUnitHistoryByIds 批量删除UnitHistory记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (unitHistoryService *UnitHistoryService) DeleteUnitHistoryByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.UnitHistory{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdateUnitHistory 更新UnitHistory记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (unitHistoryService *UnitHistoryService) UpdateUnitHistory(unitHistory autocode.UnitHistory) (err error) {
  31. err = global.GVA_DB.Save(&unitHistory).Error
  32. return err
  33. }
  34. // GetUnitHistory 根据id获取UnitHistory记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (unitHistoryService *UnitHistoryService) GetUnitHistory(id uint) (err error, unitHistory autocode.UnitHistory) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&unitHistory).Error
  38. return
  39. }
  40. // GetUnitHistoryInfoList 分页获取UnitHistory记录
  41. // Author [piexlmax](https://github.com/piexlmax)
  42. func (unitHistoryService *UnitHistoryService) GetUnitHistoryInfoList(info autoCodeReq.UnitHistorySearch) (err error, list interface{}, total int64) {
  43. limit := info.PageSize
  44. offset := info.PageSize * (info.Page - 1)
  45. // 创建db
  46. db := global.GVA_DB.Model(&autocode.UnitHistory{})
  47. if info.UnitName != "" {
  48. db.Where("unit_name = ?", info.UnitName)
  49. }
  50. if info.Period != "" {
  51. db.Where("period = ?", info.Period)
  52. }
  53. var unitHistorys []autocode.UnitHistory
  54. // 如果有条件搜索 下方会自动创建搜索语句
  55. err = db.Count(&total).Error
  56. err = db.Limit(limit).Offset(offset).Find(&unitHistorys).Error
  57. return err, unitHistorys, total
  58. }