123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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
- }
|