ops_service.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-tmr-group/model"
  6. "kpt-tmr-group/pkg/xerr"
  7. operationPb "kpt-tmr-group/proto/go/backend/operation"
  8. )
  9. // CreateSystemRoleList 添加角色
  10. func (s *StoreEntry) CreateSystemRoleList(ctx context.Context, req []*operationPb.AddRoleRequest) error {
  11. roleList := model.NewSystemRoleList(req)
  12. if err := s.DB.Create(roleList).Error; err != nil {
  13. return xerr.WithStack(err)
  14. }
  15. return nil
  16. }
  17. // SearchSystemRoleList 查询角色列表
  18. func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req []*operationPb.AddRoleRequest) error {
  19. roleList := model.NewSystemRoleList(req)
  20. if err := s.DB.Create(roleList).Error; err != nil {
  21. return xerr.WithStack(err)
  22. }
  23. return nil
  24. }
  25. // CreatePastureList 创建牧场
  26. func (s *StoreEntry) CreatePastureList(ctx context.Context, req []*operationPb.AddPastureRequest) error {
  27. pastureList := model.NewGroupPastureList(req)
  28. if err := s.DB.Create(pastureList).Error; err != nil {
  29. return xerr.WithStack(err)
  30. }
  31. return nil
  32. }
  33. // SearchPastureList 查询牧场列表
  34. func (s *StoreEntry) SearchPastureList(ctx context.Context, req *operationPb.SearchPastureRequest) (*model.GroupPastureResponse, error) {
  35. groupPasture := make([]*model.GroupPasture, 0)
  36. var count int64 = 0
  37. pref := s.DB.Model(new(model.GroupPasture)).Where("is_show = ? ", operationPb.IsShow_OK)
  38. if req.Name != "" {
  39. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  40. }
  41. if req.ManagerPhone != "" {
  42. pref.Where("manager_phone like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerPhone, "%"))
  43. }
  44. if req.ManagerUser != "" {
  45. pref.Where("manager_user like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerUser, "%"))
  46. }
  47. if err := pref.Order("id desc").Count(&count).Limit(int(req.GetPageSize())).Offset(int((req.GetPage() - 1) * req.GetPageSize())).
  48. Find(&groupPasture).Error; err != nil {
  49. return nil, xerr.WithStack(err)
  50. }
  51. return &model.GroupPastureResponse{
  52. Page: req.Page,
  53. Total: int32(count),
  54. List: model.GroupPastureSlice(groupPasture).ToPB(),
  55. }, nil
  56. }