unit_place.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 UnitPlaceService struct {
  9. }
  10. // CreateUnitPlace 创建UnitPlace记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (unitPlaceService *UnitPlaceService) CreateUnitPlace(unitPlace autocode.UnitPlace) (err error) {
  13. err = global.GVA_DB.Create(&unitPlace).Error
  14. return err
  15. }
  16. // DeleteUnitPlace 删除UnitPlace记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (unitPlaceService *UnitPlaceService) DeleteUnitPlace(unitPlace autocode.UnitPlace) (err error) {
  19. err = global.GVA_DB.Delete(&unitPlace).Error
  20. return err
  21. }
  22. // DeleteUnitPlaceByIds 批量删除UnitPlace记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (unitPlaceService *UnitPlaceService) DeleteUnitPlaceByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.UnitPlace{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdateUnitPlace 更新UnitPlace记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (unitPlaceService *UnitPlaceService) UpdateUnitPlace(unitPlace autocode.UnitPlace) (err error) {
  31. err = global.GVA_DB.Save(&unitPlace).Error
  32. return err
  33. }
  34. // GetUnitPlace 根据id获取UnitPlace记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (unitPlaceService *UnitPlaceService) GetUnitPlace(id uint) (err error, unitPlace autocode.UnitPlace) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&unitPlace).Error
  38. return
  39. }
  40. func (unitPlaceService *UnitPlaceService) GetUnitPlaces(id *int) (err error, unitPlaces []autocode.UnitPlace) {
  41. err = global.GVA_DB.Where("unit_id = ?", id).Find(&unitPlaces).Error
  42. return
  43. }
  44. // GetUnitPlaceInfoList 分页获取UnitPlace记录
  45. // Author [piexlmax](https://github.com/piexlmax)
  46. func (unitPlaceService *UnitPlaceService) GetUnitPlaceInfoList(info autoCodeReq.UnitPlaceSearch) (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.UnitPlace{})
  51. if info.UnitId != nil && *info.UnitId != 0 {
  52. db.Where("unit_id = ?", info.UnitId)
  53. }
  54. var unitPlaces []autocode.UnitPlace
  55. // 如果有条件搜索 下方会自动创建搜索语句
  56. err = db.Count(&total).Error
  57. err = db.Limit(limit).Offset(offset).Find(&unitPlaces).Error
  58. return err, unitPlaces, total
  59. }