unit.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  6. autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  7. )
  8. type UnitService struct {
  9. }
  10. // CreateUnit 创建Unit记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (unitService *UnitService) CreateUnit(unit autocode.Unit) (err error) {
  13. err = global.GVA_DB.Create(&unit).Error
  14. return err
  15. }
  16. // DeleteUnit 删除Unit记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (unitService *UnitService)DeleteUnit(unit autocode.Unit) (err error) {
  19. err = global.GVA_DB.Delete(&unit).Error
  20. return err
  21. }
  22. // DeleteUnitByIds 批量删除Unit记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (unitService *UnitService)DeleteUnitByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.Unit{},"id in ?",ids.Ids).Error
  26. return err
  27. }
  28. // UpdateUnit 更新Unit记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (unitService *UnitService)UpdateUnit(unit autocode.Unit) (err error) {
  31. err = global.GVA_DB.Save(&unit).Error
  32. return err
  33. }
  34. // GetUnit 根据id获取Unit记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (unitService *UnitService)GetUnit(id uint) (err error, unit autocode.Unit) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&unit).Error
  38. return
  39. }
  40. // GetUnitInfoList 分页获取Unit记录
  41. // Author [piexlmax](https://github.com/piexlmax)
  42. func (unitService *UnitService)GetUnitInfoList(info autoCodeReq.UnitSearch) (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.Unit{})
  47. var units []autocode.Unit
  48. // 如果有条件搜索 下方会自动创建搜索语句
  49. err = db.Count(&total).Error
  50. err = db.Limit(limit).Offset(offset).Find(&units).Error
  51. return err, units, total
  52. }