diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index b23c50ee42..80885587be 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -129,6 +129,7 @@ public enum EpmetErrorCode { OPER_UPLOAD_IMG_TYPE_ERROR(8716, "请上传PNG格式的图片"), OPER_UPLOAD_IMG_SIZE_ERROR(8717, "请上传200*200的图片"), OPER_CORS_CONFIG_ERROR(8718, "跨域配置错误"), + ACCESS_CONFIG_ERROR(8719, "权限配置错误"), // 党建声音 前端提示 88段 DRAFT_CONTENT_IS_NULL(8801, "至少需要添加一个段落"), diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/AccessConfigAdd4RoletFormDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/AccessConfigAdd4RoletFormDTO.java index d2a6770d41..657cb271f0 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/AccessConfigAdd4RoletFormDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/AccessConfigAdd4RoletFormDTO.java @@ -18,10 +18,13 @@ public class AccessConfigAdd4RoletFormDTO { // 为角色添加多个操作 public interface AddMultiOperations4RoleGroup {} - @NotBlank(message = "角色Key不能为空", groups = { AddSingleOperation4RoleGroup.class }) + //为角色添加单个操作,从默认配置里面查询,而不从前端传 + public interface AddSingleOperations4RoleByDefault {} + + @NotBlank(message = "角色Key不能为空", groups = { AddSingleOperation4RoleGroup.class, AddSingleOperations4RoleByDefault.class }) private String roleKey; - @NotBlank(message = "操作Key不能为空", groups = { AddSingleOperation4RoleGroup.class }) + @NotBlank(message = "操作Key不能为空", groups = { AddSingleOperation4RoleGroup.class, AddSingleOperations4RoleByDefault.class }) private String operationKey; private List scopeKeys; diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessConfigController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessConfigController.java index 49ab6f6f9d..71ce7c3ec5 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessConfigController.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessConfigController.java @@ -135,6 +135,22 @@ public class AccessConfigController { return new Result(); } + /** + * @Description 根据默认配置,为所有客户的某角色,配置某操作及其范围 + * @return + * @author wxz + * @date 2021.07.01 16:07 + */ + @PostMapping("add-ope-and-scopes-4role/by-default-conf") + public Result addOpeAndScopes4RoleByDefaultConf(@RequestBody AccessConfigAdd4RoletFormDTO form) { + ValidatorUtils.validateEntity(form, AccessConfigAdd4RoletFormDTO.AddSingleOperations4RoleByDefault.class); + String roleKey = form.getRoleKey(); + String operationKey = form.getOperationKey(); + + accessConfigService.addOpeAndScopes4RoleByDefaultConf(roleKey, operationKey); + return new Result(); + } + /** * @Description 给角色添加单个操作权限和操作范围 * @return diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessConfigService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessConfigService.java index 4d50c59ebe..985bdda5c3 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessConfigService.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessConfigService.java @@ -29,4 +29,6 @@ public interface AccessConfigService { void addOpeAndScopes4Role(String roleKey, String operationKey, List scopeKeys); void addOpesAndScopes4Role(String roleKey, List operations); + + void addOpeAndScopes4RoleByDefaultConf(String roleKey, String operationKey); } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessConfigServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessConfigServiceImpl.java index f08125f674..9137aff983 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessConfigServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessConfigServiceImpl.java @@ -1,5 +1,6 @@ package com.epmet.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; @@ -276,4 +277,24 @@ public class AccessConfigServiceImpl implements AccessConfigService { addOpeAndScopes4Role(roleKey, operationKey, scopeKeys); } } + + @Override + public void addOpeAndScopes4RoleByDefaultConf(String roleKey, String operationKey) { + // 1.先判断该角色是否已经为该操作配做了默认配置 + LambdaQueryWrapper rodw = new LambdaQueryWrapper<>(); + rodw.eq(RoleOperationDefaultEntity::getRoleKey, roleKey); + rodw.eq(RoleOperationDefaultEntity::getOperationKey, operationKey); + rodw.eq(RoleOperationDefaultEntity::getDelFlag, 0); + Integer roleOperationCount = roleOperationDefaultDao.selectCount(rodw); + List scopes = operationScopeDefaultDao.listOpeDefaultScopesByRoleAndOpeKey(roleKey, operationKey); + if (roleOperationCount == 0 || CollectionUtils.isEmpty(scopes)) { + throw new RenException(EpmetErrorCode.ACCESS_CONFIG_ERROR.getCode(), String.format("为所有客户同步%s的%s配置权限默认失败,请先保存默认权限配置再重试", roleKey, operationKey)); + } + + // 2.开始执行同步 + List scopeKeys = scopes.stream().map(s -> s.getScopeKey()).collect(Collectors.toList()); + logger.info(String.format("为所有客户同步%s的%s配置权限,范围列表:" + scopeKeys, roleKey, operationKey)); + addOpeAndScopes4Role(roleKey, operationKey, scopeKeys); + logger.info("同步完成"); + } }