place.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 PlaceService struct {
  9. }
  10. // CreatePlace 创建Place记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (placeService *PlaceService) CreatePlace(place autocode.Place) (err error) {
  13. err = global.GVA_DB.Create(&place).Error
  14. return err
  15. }
  16. // DeletePlace 删除Place记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (placeService *PlaceService) DeletePlace(place autocode.Place) (err error) {
  19. err = global.GVA_DB.Delete(&place).Error
  20. return err
  21. }
  22. // DeletePlaceByIds 批量删除Place记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (placeService *PlaceService) DeletePlaceByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.Place{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdatePlace 更新Place记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (placeService *PlaceService) UpdatePlace(place autocode.Place) (err error) {
  31. err = global.GVA_DB.Save(&place).Error
  32. return err
  33. }
  34. func (placeService *PlaceService) FindPlaceSum(placeIds []string) (total int) {
  35. global.GVA_DB.Model(&autocode.Place{}).Select("SUM(unit_max_integral) as total").Where("id in ?", placeIds).Pluck("total", &total)
  36. return
  37. }
  38. // GetPlace 根据id获取Place记录
  39. // Author [piexlmax](https://github.com/piexlmax)
  40. func (placeService *PlaceService) GetPlace(id uint) (err error, place autocode.Place) {
  41. err = global.GVA_DB.Where("id = ?", id).First(&place).Error
  42. return
  43. }
  44. // GetPlaceInfoList 分页获取Place记录
  45. // Author [piexlmax](https://github.com/piexlmax)
  46. func (placeService *PlaceService) GetPlaceInfoList(info autoCodeReq.PlaceSearch) (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.Place{})
  51. if info.Type != nil {
  52. db.Where("type=?", info.Type)
  53. }
  54. if info.OrganCode != "" {
  55. db.Where("organ_code=?", info.OrganCode)
  56. }
  57. if info.Name != "" {
  58. db.Where("`name` LIKE ?", "%"+info.Name+"%")
  59. }
  60. var places []autocode.Place
  61. // 如果有条件搜索 下方会自动创建搜索语句
  62. err = db.Count(&total).Error
  63. err = db.Limit(limit).Offset(offset).Find(&places).Error
  64. return err, places, total
  65. }