package backend import ( "context" "fmt" "kpt-tmr-group/model" "kpt-tmr-group/pkg/xerr" operationPb "kpt-tmr-group/proto/go/backend/operation" ) // CreateSystemRoleList 添加角色 func (s *StoreEntry) CreateSystemRoleList(ctx context.Context, req []*operationPb.AddRoleRequest) error { roleList := model.NewSystemRoleList(req) if err := s.DB.Create(roleList).Error; err != nil { return xerr.WithStack(err) } return nil } // SearchSystemRoleList 查询角色列表 func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req []*operationPb.AddRoleRequest) error { roleList := model.NewSystemRoleList(req) if err := s.DB.Create(roleList).Error; err != nil { return xerr.WithStack(err) } return nil } // CreatePastureList 创建牧场 func (s *StoreEntry) CreatePastureList(ctx context.Context, req []*operationPb.AddPastureRequest) error { pastureList := model.NewGroupPastureList(req) if err := s.DB.Create(pastureList).Error; err != nil { return xerr.WithStack(err) } return nil } // SearchPastureList 查询牧场列表 func (s *StoreEntry) SearchPastureList(ctx context.Context, req *operationPb.SearchPastureRequest) (*model.GroupPastureResponse, error) { groupPasture := make([]*model.GroupPasture, 0) var count int64 = 0 pref := s.DB.Model(new(model.GroupPasture)).Where("is_show = ? ", operationPb.IsShow_OK) if req.Name != "" { pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%")) } if req.ManagerPhone != "" { pref.Where("manager_phone like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerPhone, "%")) } if req.ManagerUser != "" { pref.Where("manager_user like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerUser, "%")) } if err := pref.Order("id desc").Count(&count).Limit(int(req.GetPageSize())).Offset(int((req.GetPage() - 1) * req.GetPageSize())). Find(&groupPasture).Error; err != nil { return nil, xerr.WithStack(err) } return &model.GroupPastureResponse{ Page: req.Page, Total: int32(count), List: model.GroupPastureSlice(groupPasture).ToPB(), }, nil }