|  | @@ -7,7 +7,6 @@ import (
 | 
	
		
			
				|  |  |  	"kpt-pasture/model"
 | 
	
		
			
				|  |  |  	"kpt-pasture/util"
 | 
	
		
			
				|  |  |  	"net/http"
 | 
	
		
			
				|  |  | -	"strconv"
 | 
	
		
			
				|  |  |  	"strings"
 | 
	
		
			
				|  |  |  	"time"
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -46,7 +45,9 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 | 
	
		
			
				|  |  |  		return nil, xerr.Customf("该账号已被删除,请联系管理员")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	zaplog.Info("Login", zap.Any("systemUser", systemUser))
 | 
	
		
			
				|  |  | +	if len(systemUser.PastureIds) <= 0 {
 | 
	
		
			
				|  |  | +		return nil, xerr.Custom("当前用户未配置相关牧场数据,请联系管理员!")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.SystemRole)).
 | 
	
	
		
			
				|  | @@ -71,7 +72,7 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	expires := time.Now().Local().Add(time.Duration(s.Cfg.JwtExpireTime) * time.Second).Format(util.LayoutTime)
 | 
	
		
			
				|  |  | -	farmList, err := s.FindPastureList(ctx, systemUser.PastureIds)
 | 
	
		
			
				|  |  | +	farmList, err := s.FindPastureListByIds(ctx, systemUser.GetPastureIds())
 | 
	
		
			
				|  |  |  	if err != nil || len(farmList) == 0 {
 | 
	
		
			
				|  |  |  		return nil, xerr.Custom("牧场信息错误")
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -100,10 +101,10 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	systemUserList := make([]*model.SystemUser, 0)
 | 
	
		
			
				|  |  |  	var count int64 = 0
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	pref := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  |  		Where("is_delete = ?", operationPb.IsShow_OK).
 | 
	
		
			
				|  |  |  		Where("FIND_IN_SET(?, pasture_ids) > ?", userModel.AppPasture.Id, 0)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	if req.Name != "" {
 | 
	
		
			
				|  |  |  		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -112,18 +113,12 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  		pref.Where("mobile = ?", req.Mobile)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if req.DepthId > 0 {
 | 
	
		
			
				|  |  | -		systemDept := &model.SystemDept{}
 | 
	
		
			
				|  |  | -		if err = s.DB.Model(new(model.SystemDept)).Where("id = ?", req.DepthId).
 | 
	
		
			
				|  |  | -			Where("is_delete = ?", operationPb.IsShow_OK).
 | 
	
		
			
				|  |  | -			First(systemDept).Error; err != nil {
 | 
	
		
			
				|  |  | -			return nil, xerr.Custom("部门信息错误")
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		pref.Where("pasture_id = ?", systemDept.PastureId)
 | 
	
		
			
				|  |  | -		if systemDept.DeptType == pasturePb.Depth_Department {
 | 
	
		
			
				|  |  | -			pref.Where("dept_id = ?", req.DepthId)
 | 
	
		
			
				|  |  | +	if len(req.DepthId) > 0 {
 | 
	
		
			
				|  |  | +		depthIds := ""
 | 
	
		
			
				|  |  | +		for _, v := range req.DepthId {
 | 
	
		
			
				|  |  | +			depthIds += fmt.Sprintf("%d,", v)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		pref.Where("dept_ids = ?", strings.TrimRight(depthIds, ","))
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	if req.IsShow > 0 {
 | 
	
	
		
			
				|  | @@ -138,12 +133,17 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	roleList, err := s.SearchSystemRoleListByIds(ctx, []int64{})
 | 
	
		
			
				|  |  | +	roleList, err := s.SearchSystemRoleListByIds(ctx, userModel.AppPasture.Id, []int64{})
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	deptList, err := s.SearchSystemDeptListByIds(ctx, userModel.AppPasture.Id, []int64{})
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	deptList, err := s.SearchSystemDeptListByIds(ctx, []int64{})
 | 
	
		
			
				|  |  | +	appPastureList, err := s.FindPastureList(ctx)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -152,7 +152,7 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  		Code: http.StatusOK,
 | 
	
		
			
				|  |  |  		Msg:  "ok",
 | 
	
		
			
				|  |  |  		Data: &pasturePb.SearchUserData{
 | 
	
		
			
				|  |  | -			List:     model.SystemUserSlice(systemUserList).ToPB(deptList, roleList),
 | 
	
		
			
				|  |  | +			List:     model.SystemUserSlice(systemUserList).ToPB(deptList, roleList, appPastureList),
 | 
	
		
			
				|  |  |  			Total:    int32(count),
 | 
	
		
			
				|  |  |  			PageSize: pagination.PageSize,
 | 
	
		
			
				|  |  |  			Page:     pagination.Page,
 | 
	
	
		
			
				|  | @@ -160,9 +160,11 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  	}, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (s *StoreEntry) SystemUserList(ctx context.Context) ([]*model.SystemUser, error) {
 | 
	
		
			
				|  |  | +func (s *StoreEntry) SystemUserList(ctx context.Context, pastureId int64) ([]*model.SystemUser, error) {
 | 
	
		
			
				|  |  |  	systemUserList := make([]*model.SystemUser, 0)
 | 
	
		
			
				|  |  | -	if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", pastureId).
 | 
	
		
			
				|  |  | +		Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  |  		Where("is_show = ? ", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  |  		Find(&systemUserList).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
	
		
			
				|  | @@ -172,9 +174,7 @@ func (s *StoreEntry) SystemUserList(ctx context.Context) ([]*model.SystemUser, e
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // DeleteSystemUser 删除系统用户
 | 
	
		
			
				|  |  |  func (s *StoreEntry) DeleteSystemUser(ctx context.Context, userId int64) error {
 | 
	
		
			
				|  |  | -	systemUser := &model.SystemUser{
 | 
	
		
			
				|  |  | -		Id: userId,
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +	systemUser := &model.SystemUser{Id: userId}
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.SystemUser)).First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return xerr.Custom("该用户不存在")
 | 
	
	
		
			
				|  | @@ -203,7 +203,8 @@ func (s *StoreEntry) IsShowSystemUser(ctx context.Context, userId int64) error {
 | 
	
		
			
				|  |  |  		isShow = pasturePb.IsShow_Ok
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(systemUser).Update("is_show", isShow).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(systemUser).
 | 
	
		
			
				|  |  | +		Update("is_show", isShow).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 | 
	
	
		
			
				|  | @@ -211,67 +212,81 @@ func (s *StoreEntry) IsShowSystemUser(ctx context.Context, userId int64) error {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // SystemUserCreateOrUpdate 创建或者更新系统用户
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SystemUserCreateOrUpdate(ctx context.Context, req *pasturePb.SearchUserRequest) error {
 | 
	
		
			
				|  |  | +	deptIds, pastureIds := "", ""
 | 
	
		
			
				|  |  | +	for _, pasture := range req.PastureDepthList {
 | 
	
		
			
				|  |  | +		appPasture, err := s.GetAppPastureListByFarmId(ctx, pasture.FarmId)
 | 
	
		
			
				|  |  | +		if err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		pastureIds += fmt.Sprintf("%d,", appPasture.Id)
 | 
	
		
			
				|  |  | +		if len(pasture.DepthList) > 0 {
 | 
	
		
			
				|  |  | +			for _, dept := range pasture.DepthList {
 | 
	
		
			
				|  |  | +				deptIds += fmt.Sprintf("%d,", dept.Id)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if len(pastureIds) > 0 {
 | 
	
		
			
				|  |  | +			pastureIds = strings.TrimSuffix(pastureIds, ",")
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if len(deptIds) > 0 {
 | 
	
		
			
				|  |  | +			deptIds = strings.TrimSuffix(deptIds, ",")
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	systemUser := &model.SystemUser{}
 | 
	
		
			
				|  |  |  	if req.Id > 0 {
 | 
	
		
			
				|  |  |  		systemUser.Id = int64(req.Id)
 | 
	
		
			
				|  |  | -		if err := s.DB.Model(new(model.SystemUser)).First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +		if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +			First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  |  			return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		req.Password = systemUser.Password
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		systemUser.UserUpdate(req, deptIds, pastureIds)
 | 
	
		
			
				|  |  | +		if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +			Select("name", "nick_name", "mobile", "gender", "dept_ids", "pasture_ids", "remarks", "is_show").
 | 
	
		
			
				|  |  | +			Where("id = ?", systemUser.Id).
 | 
	
		
			
				|  |  | +			Updates(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	} else {
 | 
	
		
			
				|  |  | +		var count int64
 | 
	
		
			
				|  |  |  		if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  |  			Where("name = ?", req.Name).
 | 
	
		
			
				|  |  | -			First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | -			if !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  | -				return xerr.WithStack(err)
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -		} else if systemUser.Id > 0 {
 | 
	
		
			
				|  |  | -			return xerr.Custom("该用户名称已经存在")
 | 
	
		
			
				|  |  | +			Where("mobile = ?", req.Mobile).
 | 
	
		
			
				|  |  | +			Where("is_show = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +			Count(&count).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	deptIds := ""
 | 
	
		
			
				|  |  | -	if len(req.DepthList) > 0 {
 | 
	
		
			
				|  |  | -		for _, dept := range req.DepthList {
 | 
	
		
			
				|  |  | -			deptIds += fmt.Sprintf("%d,", dept.Id)
 | 
	
		
			
				|  |  | +		if count > 0 {
 | 
	
		
			
				|  |  | +			return xerr.Customf("系统中该用户名称已经存在: %s_%s", req.Name, req.Mobile)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		newSystemUser := model.NewSystemUser(req, deptIds, pastureIds, req.PastureDepthList)
 | 
	
		
			
				|  |  | +		if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +			Create(newSystemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	if len(deptIds) > 0 {
 | 
	
		
			
				|  |  | -		deptIds = strings.TrimRight(deptIds, ",")
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(&model.SystemUser{}).
 | 
	
		
			
				|  |  | -		Where(map[string]interface{}{
 | 
	
		
			
				|  |  | -			"id": req.Id,
 | 
	
		
			
				|  |  | -		}).Assign(map[string]interface{}{
 | 
	
		
			
				|  |  | -		"name":      req.Name,
 | 
	
		
			
				|  |  | -		"nick_name": req.NickName,
 | 
	
		
			
				|  |  | -		"mobile":    req.Mobile,
 | 
	
		
			
				|  |  | -		"gender":    req.Gender,
 | 
	
		
			
				|  |  | -		"password":  req.Password,
 | 
	
		
			
				|  |  | -		"dept_ids":  deptIds,
 | 
	
		
			
				|  |  | -		"remarks":   req.Remarks,
 | 
	
		
			
				|  |  | -		"is_delete": operationPb.IsShow_OK,
 | 
	
		
			
				|  |  | -		"is_show":   req.IsShow,
 | 
	
		
			
				|  |  | -	}).FirstOrCreate(&model.SystemUser{}).Error; err != nil {
 | 
	
		
			
				|  |  | -		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // ResetPasswordSystemUser 重置系统用户密码
 | 
	
		
			
				|  |  |  func (s *StoreEntry) ResetPasswordSystemUser(ctx context.Context, req *pasturePb.ResetUserPasswordRequest) error {
 | 
	
		
			
				|  |  | -	systemUser := &model.SystemUser{
 | 
	
		
			
				|  |  | -		Id: int64(req.Id),
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +	systemUser := &model.SystemUser{}
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +		Where("id = ?", req.Id).
 | 
	
		
			
				|  |  | +		First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return xerr.Custom("该用户不存在")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(systemUser).Update("password", req.Password).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(systemUser).
 | 
	
		
			
				|  |  | +		Update("password", req.Password).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 | 
	
	
		
			
				|  | @@ -279,50 +294,63 @@ func (s *StoreEntry) ResetPasswordSystemUser(ctx context.Context, req *pasturePb
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SystemUserRole(ctx context.Context, userId int64) (*pasturePb.SystemUserRoleResponse, error) {
 | 
	
		
			
				|  |  |  	systemUser := &model.SystemUser{Id: userId}
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +		First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return nil, xerr.Custom("该用户不存在")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	roleIds := make([]int32, 0)
 | 
	
		
			
				|  |  | -	if len(systemUser.RoleIds) > 0 {
 | 
	
		
			
				|  |  | -		roleIdsString := strings.Split(systemUser.RoleIds, ",")
 | 
	
		
			
				|  |  | -		for _, r := range roleIdsString {
 | 
	
		
			
				|  |  | -			r1, _ := strconv.Atoi(r)
 | 
	
		
			
				|  |  | -			roleIds = append(roleIds, int32(r1))
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | +	if systemUser.IsDelete == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +		return nil, xerr.Custom("该用户已删除")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return &pasturePb.SystemUserRoleResponse{
 | 
	
		
			
				|  |  |  		Code: http.StatusOK,
 | 
	
		
			
				|  |  |  		Msg:  "ok",
 | 
	
		
			
				|  |  |  		Data: &pasturePb.UserRoleData{
 | 
	
		
			
				|  |  | -			RoleIds: roleIds,
 | 
	
		
			
				|  |  | +			RoleIds: systemUser.GetRoleIds(),
 | 
	
		
			
				|  |  |  		},
 | 
	
		
			
				|  |  |  	}, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SystemUserRoleSave(ctx context.Context, req *pasturePb.SystemUserRoleRequest) error {
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	systemUser := &model.SystemUser{Id: int64(req.UserId)}
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemUser)).
 | 
	
		
			
				|  |  | +		First(systemUser).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return xerr.Custom("该用户不存在")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	if systemUser.IsDelete == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +		return xerr.Custom("该用户已删除")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if systemUser.IsShow == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +		return xerr.Custom("该用户已禁用")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  |  		Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  |  		Where("id IN ?", req.RoleIds).
 | 
	
		
			
				|  |  |  		Find(&systemRoleList).Error; err != nil {
 | 
	
		
			
				|  |  | -		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  | -			return xerr.Custom("该角色不存在")
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	if len(systemRoleList) <= 0 {
 | 
	
		
			
				|  |  | +		return xerr.Custom("该用户没有角色")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	roleIdsStr := ""
 | 
	
		
			
				|  |  |  	for _, systemRole := range systemRoleList {
 | 
	
		
			
				|  |  |  		roleIdsStr += fmt.Sprintf("%d,", systemRole.Id)
 | 
	
	
		
			
				|  | @@ -332,7 +360,7 @@ func (s *StoreEntry) SystemUserRoleSave(ctx context.Context, req *pasturePb.Syst
 | 
	
		
			
				|  |  |  		roleIdsStr = strings.TrimRight(roleIdsStr, ",")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(systemUser).
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(systemUser).
 | 
	
		
			
				|  |  |  		Update("role_ids", roleIdsStr).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -350,10 +378,9 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
 | 
	
		
			
				|  |  |  		return nil, xerr.Custom("该用户没有角色")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	roleIds := strings.Split(systemUser.RoleIds, ",")
 | 
	
		
			
				|  |  |  	// 获取用户角色数据
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  | -	if err = s.DB.Where("id IN ?", roleIds).
 | 
	
		
			
				|  |  | +	if err = s.DB.Where("id IN ?", systemUser.GetRoleIds()).
 | 
	
		
			
				|  |  |  		Find(&systemRoleList).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return nil, xerr.Custom("该用户角色不存在")
 | 
	
	
		
			
				|  | @@ -365,7 +392,7 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
 | 
	
		
			
				|  |  |  	if err = s.DB.Table(fmt.Sprintf("%s as a", new(model.SystemRoleMenu).TableName())).
 | 
	
		
			
				|  |  |  		Select("b.*").
 | 
	
		
			
				|  |  |  		Joins("LEFT JOIN system_menu AS b ON a.menu_id = b.id").
 | 
	
		
			
				|  |  | -		Where("a.role_id IN ? and b.is_delete = ?", roleIds, pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +		Where("a.role_id IN ? and b.is_delete = ?", systemUser.GetRoleIds(), pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  |  		Find(&systemMenuList).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -380,37 +407,60 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // SystemRoleCreateOrUpdate 添加角色
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SystemRoleCreateOrUpdate(ctx context.Context, req *pasturePb.SearchRoleRequest) error {
 | 
	
		
			
				|  |  | -	isShow := pasturePb.IsShow_Ok
 | 
	
		
			
				|  |  | -	if req.Id > 0 {
 | 
	
		
			
				|  |  | -		isShow = req.IsShow
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(&model.SystemRole{}).Where(map[string]interface{}{
 | 
	
		
			
				|  |  | -		"id": req.Id,
 | 
	
		
			
				|  |  | -	}).Assign(map[string]interface{}{
 | 
	
		
			
				|  |  | -		"name":      req.Name,
 | 
	
		
			
				|  |  | -		"remarks":   req.Remarks,
 | 
	
		
			
				|  |  | -		"is_delete": operationPb.IsShow_OK,
 | 
	
		
			
				|  |  | -		"is_show":   isShow,
 | 
	
		
			
				|  |  | -	}).FirstOrCreate(&model.SystemRole{}).Error; err != nil {
 | 
	
		
			
				|  |  | -		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	if req.Id > 0 {
 | 
	
		
			
				|  |  | +		systemRole := &model.SystemRole{}
 | 
	
		
			
				|  |  | +		if err = s.DB.Model(systemRole).
 | 
	
		
			
				|  |  | +			Where("id = ?", req.Id).
 | 
	
		
			
				|  |  | +			Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +			First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if systemRole.IsDelete == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +			return xerr.Custom("角色已删除")
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		systemRole.RoleUpdate(req)
 | 
	
		
			
				|  |  | +		if err = s.DB.Model(systemRole).
 | 
	
		
			
				|  |  | +			Select("name", "remarks", "is_show", "is_delete").
 | 
	
		
			
				|  |  | +			Where("id = ?", req.Id).
 | 
	
		
			
				|  |  | +			Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +			Updates(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	} else {
 | 
	
		
			
				|  |  | +		newSystemRole := model.NewSystemRole(userModel.AppPasture.Id, req)
 | 
	
		
			
				|  |  | +		if err = s.DB.Model(new(model.SystemRole)).Create(newSystemRole).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // DeleteSystemRole 删除系统角色
 | 
	
		
			
				|  |  |  func (s *StoreEntry) DeleteSystemRole(ctx context.Context, roleId int64) error {
 | 
	
		
			
				|  |  | -	systemRole := &model.SystemRole{
 | 
	
		
			
				|  |  | -		Id: roleId,
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  | -		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  | -			return xerr.Custom("该数据不存在")
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | +	systemRole := &model.SystemRole{}
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("id = ? ", roleId).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +		Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +		First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(systemRole).Update("is_delete", pasturePb.IsShow_No).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(systemRole).
 | 
	
		
			
				|  |  | +		Update("is_delete", pasturePb.IsShow_No).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 | 
	
	
		
			
				|  | @@ -418,21 +468,28 @@ func (s *StoreEntry) DeleteSystemRole(ctx context.Context, roleId int64) error {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // IsShowSystemRole 角色是否启用
 | 
	
		
			
				|  |  |  func (s *StoreEntry) IsShowSystemRole(ctx context.Context, roleId int64) error {
 | 
	
		
			
				|  |  | -	systemRole := &model.SystemRole{
 | 
	
		
			
				|  |  | -		Id: roleId,
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  | +	systemRole := &model.SystemRole{}
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("id = ?", roleId).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +		Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +		First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return xerr.Custom("该角色不存在")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	isShow := pasturePb.IsShow_No
 | 
	
		
			
				|  |  |  	if systemRole.IsShow == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  |  		isShow = pasturePb.IsShow_Ok
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(systemRole).Update("is_show", isShow).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(systemRole).Update("is_show", isShow).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 | 
	
	
		
			
				|  | @@ -440,10 +497,17 @@ func (s *StoreEntry) IsShowSystemRole(ctx context.Context, roleId int64) error {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // SearchSystemRoleList 查询系统角色
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.SearchRoleRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchRoleResponse, error) {
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  |  	var count int64 = 0
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	pref := s.DB.Model(new(model.SystemRole)).Where("is_delete = ?", operationPb.IsShow_OK)
 | 
	
		
			
				|  |  | +	pref := s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +		Where("is_delete = ?", operationPb.IsShow_OK)
 | 
	
		
			
				|  |  |  	if req.Name != "" {
 | 
	
		
			
				|  |  |  		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -452,8 +516,11 @@ func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  		pref.Where("is_show = ?", req.IsShow)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).
 | 
	
		
			
				|  |  | -		Offset(int(pagination.PageOffset)).Find(&systemRoleList).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err = pref.Order("is_show asc,id desc").
 | 
	
		
			
				|  |  | +		Count(&count).
 | 
	
		
			
				|  |  | +		Limit(int(pagination.PageSize)).
 | 
	
		
			
				|  |  | +		Offset(int(pagination.PageOffset)).
 | 
	
		
			
				|  |  | +		Find(&systemRoleList).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -470,9 +537,10 @@ func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.Se
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // SearchSystemRoleListByIds 根据id查询角色列表
 | 
	
		
			
				|  |  | -func (s *StoreEntry) SearchSystemRoleListByIds(ctx context.Context, ids []int64) ([]*model.SystemRole, error) {
 | 
	
		
			
				|  |  | +func (s *StoreEntry) SearchSystemRoleListByIds(ctx context.Context, pastureId int64, ids []int64) ([]*model.SystemRole, error) {
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", pastureId).
 | 
	
		
			
				|  |  |  		Where("is_show = ?", operationPb.IsShow_OK).
 | 
	
		
			
				|  |  |  		Find(&systemRoleList, ids).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
	
		
			
				|  | @@ -511,29 +579,47 @@ func (s *StoreEntry) GetRoleMenuList(ctx context.Context, roleId int64) (*pastur
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // RoleMenuSave 保存系统角色对应的菜单数据
 | 
	
		
			
				|  |  |  func (s *StoreEntry) RoleMenuSave(ctx context.Context, res *pasturePb.SystemRoleMenuRequest) error {
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	if len(res.MenuIds) <= 0 {
 | 
	
		
			
				|  |  |  		return xerr.Custom("请选择菜单")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	systemRole := &model.SystemRole{
 | 
	
		
			
				|  |  | -		Id: int64(res.RoleId),
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  | +	systemRole := &model.SystemRole{}
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("id = ?", res.RoleId).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | +		First(systemRole).Error; err != nil {
 | 
	
		
			
				|  |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
	
		
			
				|  |  |  			return xerr.Custom("该数据不存在")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	if err := s.DB.Transaction(func(tx *gorm.DB) error {
 | 
	
		
			
				|  |  | -		if err := tx.Model(new(model.SystemRoleMenu)).Where("role_id = ?", systemRole.Id).Delete(&model.SystemRoleMenu{}).Error; err != nil {
 | 
	
		
			
				|  |  | +	if systemRole.IsDelete == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +		return xerr.Custom("该数据已删除")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if systemRole.IsShow == pasturePb.IsShow_No {
 | 
	
		
			
				|  |  | +		return xerr.Custom("该数据已禁用")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 | 
	
		
			
				|  |  | +		if err = tx.Model(new(model.SystemRoleMenu)).
 | 
	
		
			
				|  |  | +			Where("role_id = ?", systemRole.Id).
 | 
	
		
			
				|  |  | +			Delete(&model.SystemRoleMenu{}).
 | 
	
		
			
				|  |  | +			Error; err != nil {
 | 
	
		
			
				|  |  |  			return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		for _, menuId := range res.MenuIds {
 | 
	
		
			
				|  |  | -			if err := tx.Create(&model.SystemRoleMenu{
 | 
	
		
			
				|  |  | -				RoleId: systemRole.Id,
 | 
	
		
			
				|  |  | -				MenuId: int64(menuId),
 | 
	
		
			
				|  |  | -			}).Error; err != nil {
 | 
	
		
			
				|  |  | +			if err = tx.Model(new(model.SystemRoleMenu)).
 | 
	
		
			
				|  |  | +				Create(&model.SystemRoleMenu{
 | 
	
		
			
				|  |  | +					RoleId: systemRole.Id,
 | 
	
		
			
				|  |  | +					MenuId: int64(menuId),
 | 
	
		
			
				|  |  | +				}).Error; err != nil {
 | 
	
		
			
				|  |  |  				return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
	
		
			
				|  | @@ -545,9 +631,15 @@ func (s *StoreEntry) RoleMenuSave(ctx context.Context, res *pasturePb.SystemRole
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (s *StoreEntry) SystemRoleList(ctx context.Context) (*pasturePb.GetRoleListResponse, error) {
 | 
	
		
			
				|  |  | +	userModel, err := s.GetUserModel(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	systemRoleList := make([]*model.SystemRole, 0)
 | 
	
		
			
				|  |  | -	if err := s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | -		Where("is_delete = ? and is_show = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +	if err = s.DB.Model(new(model.SystemRole)).
 | 
	
		
			
				|  |  | +		Where("is_delete = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  |  		Find(&systemRoleList).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 |