mirror of https://gitee.com/stylefeng/roses
【8.3.3】【role】更新新增和修改角色权限的接口
parent
e5d4535d2e
commit
e12b54dd93
|
@ -6,12 +6,14 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||||
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.constants.PermissionCodeConstants;
|
import cn.stylefeng.roses.kernel.sys.api.constants.PermissionCodeConstants;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
|
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleDataScopeRequest;
|
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleDataScopeRequest;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleDataScopeService;
|
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleDataScopeService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,4 +43,30 @@ public class RoleDataScopeController {
|
||||||
return new SuccessResponseData<>(pageList);
|
return new SuccessResponseData<>(pageList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增一个角色的数据权限
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/24 22:34
|
||||||
|
*/
|
||||||
|
@PostResource(name = "新增一个角色的数据权限", path = "/roleDataScope/addRoleDataScope", requiredPermission = true,
|
||||||
|
requirePermissionCode = PermissionCodeConstants.CHANGE_ROLE_DATA_SCOPE)
|
||||||
|
public ResponseData<?> addRoleDataScope(@RequestBody @Validated(BaseRequest.add.class) SysRoleDataScopeRequest roleDataScopeRequest) {
|
||||||
|
sysRoleDataScopeService.add(roleDataScopeRequest);
|
||||||
|
return new SuccessResponseData<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改角色的数据权限
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/24 22:49
|
||||||
|
*/
|
||||||
|
@PostResource(name = "修改角色的数据权限", path = "/roleDataScope/editRoleDataScope", requiredPermission = true,
|
||||||
|
requirePermissionCode = PermissionCodeConstants.CHANGE_ROLE_DATA_SCOPE)
|
||||||
|
public ResponseData<?> editRoleDataScope(@RequestBody @Validated(BaseRequest.edit.class) SysRoleDataScopeRequest roleDataScopeRequest) {
|
||||||
|
sysRoleDataScopeService.edit(roleDataScopeRequest);
|
||||||
|
return new SuccessResponseData<>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,12 @@ public enum SysRoleDataScopeExceptionEnum implements AbstractExceptionEnum {
|
||||||
/**
|
/**
|
||||||
* 查询结果不存在
|
* 查询结果不存在
|
||||||
*/
|
*/
|
||||||
SYS_ROLE_DATA_SCOPE_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
|
SYS_ROLE_DATA_SCOPE_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存在参数为空,参数名称为:{}
|
||||||
|
*/
|
||||||
|
PARAM_IS_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10002", "存在参数为空,参数名称为:{}");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误编码
|
* 错误编码
|
||||||
|
|
|
@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色数据范围封装类
|
* 角色数据范围封装类
|
||||||
*
|
*
|
||||||
|
@ -20,19 +22,41 @@ public class SysRoleDataScopeRequest extends BaseRequest {
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
@ChineseDescription("主键")
|
@ChineseDescription("主键")
|
||||||
|
@NotNull(message = "主键不能为空", groups = {edit.class, delete.class, detail.class})
|
||||||
private Long roleDataScopeId;
|
private Long roleDataScopeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色id
|
* 角色id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "角色id不能为空", groups = {page.class})
|
@NotNull(message = "角色id不能为空", groups = {page.class, add.class, edit.class})
|
||||||
@ChineseDescription("角色id")
|
@ChineseDescription("角色id")
|
||||||
private Long roleId;
|
private Long roleId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机构id
|
* 数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,31-本公司及以下数据,32-指定机构层级及以下
|
||||||
|
* <p>
|
||||||
|
* 40-指定机构集合数据,41-指定机构及以下,50-全部数据
|
||||||
*/
|
*/
|
||||||
@ChineseDescription("机构id")
|
@ChineseDescription("数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,31-本公司及以下数据,32-指定机构层级及以下,40-指定机构集合数据,41-指定机构及以下,50-全部数据")
|
||||||
private Long organizationId;
|
@NotNull(message = "数据范围类型不能为空", groups = {add.class, edit.class})
|
||||||
|
private Integer dataScopeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 层级的编码,用在类型为32-指定层级及以下,情况时使用
|
||||||
|
*/
|
||||||
|
@ChineseDescription("层级的编码,用在类型为32-指定层级及以下,情况时使用")
|
||||||
|
private String orgLevelCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定机构集合列表,用在类型为40-指定机构集合数据,情况时使用
|
||||||
|
*/
|
||||||
|
@ChineseDescription("指定机构集合列表,用在类型为40-指定机构集合数据,情况时使用")
|
||||||
|
private List<String> defineOrgList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定机构的id,用在类型为41-指定机构及以下,情况时使用
|
||||||
|
*/
|
||||||
|
@ChineseDescription("指定机构的id,用在类型为41-指定机构及以下,情况时使用")
|
||||||
|
private Long defineOrgId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.OrgLevelServiceApi;
|
import cn.stylefeng.roses.kernel.sys.api.OrgLevelServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
|
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
|
||||||
|
import cn.stylefeng.roses.kernel.sys.api.exception.SysException;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
|
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
|
||||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindDataScopeResponse;
|
import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindDataScopeResponse;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
|
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
|
||||||
|
@ -52,6 +53,10 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
public void add(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
|
||||||
|
// 先校验参数
|
||||||
|
this.validateRoleDataScopeRequest(sysRoleDataScopeRequest);
|
||||||
|
|
||||||
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
|
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
|
||||||
BeanUtil.copyProperties(sysRoleDataScopeRequest, sysRoleDataScope);
|
BeanUtil.copyProperties(sysRoleDataScopeRequest, sysRoleDataScope);
|
||||||
this.save(sysRoleDataScope);
|
this.save(sysRoleDataScope);
|
||||||
|
@ -65,8 +70,17 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void edit(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
public void edit(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
|
||||||
|
// 先校验参数
|
||||||
|
this.validateRoleDataScopeRequest(sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
// 进行赋值
|
||||||
SysRoleDataScope sysRoleDataScope = this.querySysRoleDataScope(sysRoleDataScopeRequest);
|
SysRoleDataScope sysRoleDataScope = this.querySysRoleDataScope(sysRoleDataScopeRequest);
|
||||||
BeanUtil.copyProperties(sysRoleDataScopeRequest, sysRoleDataScope);
|
sysRoleDataScope.setDataScopeType(sysRoleDataScopeRequest.getDataScopeType());
|
||||||
|
sysRoleDataScope.setOrgLevelCode(sysRoleDataScopeRequest.getOrgLevelCode());
|
||||||
|
sysRoleDataScope.setDefineOrgList(sysRoleDataScopeRequest.getDefineOrgList());
|
||||||
|
sysRoleDataScope.setDefineOrgId(sysRoleDataScopeRequest.getDefineOrgId());
|
||||||
|
|
||||||
this.updateById(sysRoleDataScope);
|
this.updateById(sysRoleDataScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,4 +238,34 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验数据范围请求的参数,一般用在新增和修改的时候
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/24 22:42
|
||||||
|
*/
|
||||||
|
private void validateRoleDataScopeRequest(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
|
||||||
|
// 如果是新增的是指定层级,则判断层级参数
|
||||||
|
if (DataScopeTypeEnum.DEFINE_ORG_LEVEL_WITH_CHILD.getCode().equals(sysRoleDataScopeRequest.getDataScopeType())) {
|
||||||
|
if (ObjectUtil.isEmpty(sysRoleDataScopeRequest.getOrgLevelCode())) {
|
||||||
|
throw new SysException(SysRoleDataScopeExceptionEnum.PARAM_IS_EMPTY, "组织机构层级编码orgLevelCode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是新增的是指定机构,则判断机构参数
|
||||||
|
else if (DataScopeTypeEnum.DEFINE.getCode().equals(sysRoleDataScopeRequest.getDataScopeType())) {
|
||||||
|
if (ObjectUtil.isEmpty(sysRoleDataScopeRequest.getDefineOrgList())) {
|
||||||
|
throw new SysException(SysRoleDataScopeExceptionEnum.PARAM_IS_EMPTY, "机构集合列表defineOrgList");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是新增的是指定机构及以下
|
||||||
|
else if (DataScopeTypeEnum.DEFINE_ORG_WITH_CHILD.getCode().equals(sysRoleDataScopeRequest.getDataScopeType())) {
|
||||||
|
if (ObjectUtil.isEmpty(sysRoleDataScopeRequest.getDefineOrgId())) {
|
||||||
|
throw new SysException(SysRoleDataScopeExceptionEnum.PARAM_IS_EMPTY, "指定机构defineOrgId");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue