From dc0f0adc65099b2695e2ecfd55c8585aa00cb9aa Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 1 Jul 2021 16:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=BA=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=AE=A2=E6=88=B7=E5=90=8C=E6=AD=A5=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E8=A7=92=E8=89=B2=EF=BC=8C=E6=8C=87=E5=AE=9A=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=8C(=E4=BB=8E=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=8F=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/exception/EpmetErrorCode.java | 1 + .../form/AccessConfigAdd4RoletFormDTO.java | 7 +++++-- .../controller/AccessConfigController.java | 16 ++++++++++++++ .../epmet/service/AccessConfigService.java | 2 ++ .../service/impl/AccessConfigServiceImpl.java | 21 +++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) 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 2538492bb8..cef713e4b7 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("同步完成"); + } }