unit_user.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 UnitUserService struct {
  9. }
  10. // CreateUnitUser 创建UnitUser记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (unitUserService *UnitUserService) CreateUnitUser(unitUser autocode.UnitUser) (err error) {
  13. err = global.GVA_DB.Create(&unitUser).Error
  14. return err
  15. }
  16. // DeleteUnitUser 删除UnitUser记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (unitUserService *UnitUserService) DeleteUnitUser(unitUser autocode.UnitUser) (err error) {
  19. err = global.GVA_DB.Delete(&unitUser).Error
  20. return err
  21. }
  22. // DeleteUnitUserByIds 批量删除UnitUser记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (unitUserService *UnitUserService) DeleteUnitUserByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.UnitUser{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdateUnitUser 更新UnitUser记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (unitUserService *UnitUserService) UpdateUnitUser(unitUser autocode.UnitUser) (err error) {
  31. err = global.GVA_DB.Save(&unitUser).Error
  32. return err
  33. }
  34. // GetUnitUser 根据id获取UnitUser记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (unitUserService *UnitUserService) GetUnitUser(id uint) (err error, unitUser autocode.UnitUser) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&unitUser).Error
  38. return
  39. }
  40. func (unitUserService *UnitUserService) GetUnitUsers(id *int) (err error, unitUser []autocode.UnitUser) {
  41. err = global.GVA_DB.Where("unit_id = ?", id).Find(&unitUser).Error
  42. return
  43. }
  44. // GetUnitUserInfoList 分页获取UnitUser记录
  45. // Author [piexlmax](https://github.com/piexlmax)
  46. func (unitUserService *UnitUserService) GetUnitUserInfoList(info autoCodeReq.UnitUserSearch) (err error, list interface{}, total int64) {
  47. limit := info.PageSize
  48. offset := info.PageSize * (info.Page - 1)
  49. // 创建db
  50. db := global.GVA_DB.Model(&autocode.UnitUser{})
  51. var unitUsers []autocode.UnitUser
  52. // 如果有条件搜索 下方会自动创建搜索语句
  53. err = db.Count(&total).Error
  54. err = db.Limit(limit).Offset(offset).Find(&unitUsers).Error
  55. return err, unitUsers, total
  56. }