From c70704336ebe26d1ae310241f97e241b8787b5f1 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 2 Dec 2020 17:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BA=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E8=A7=92=E8=89=B2=EF=BC=8C=E6=89=B9=E9=87=8F=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=93=8D=E4=BD=9C=E6=9D=83=E9=99=90=E5=92=8C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=8C=83=E5=9B=B4=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/AccessConfigAdd4RoletFormDTO.java | 50 ++++++++++++++++++- .../controller/AccessConfigController.java | 17 ++++++- .../epmet/service/AccessConfigService.java | 4 +- .../service/impl/AccessConfigServiceImpl.java | 10 ++++ 4 files changed, 76 insertions(+), 5 deletions(-) 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 85b9e9d68d..d2a6770d41 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 @@ -2,16 +2,62 @@ package com.epmet.dto.form; import lombok.Data; +import javax.validation.Valid; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.ArrayList; import java.util.List; @Data public class AccessConfigAdd4RoletFormDTO { - @NotBlank(message = "角色Key不能为空") + + // 为角色添加单个操作 + public interface AddSingleOperation4RoleGroup {} + + // 为角色添加多个操作 + public interface AddMultiOperations4RoleGroup {} + + @NotBlank(message = "角色Key不能为空", groups = { AddSingleOperation4RoleGroup.class }) private String roleKey; - @NotBlank(message = "操作Key不能为空") + @NotBlank(message = "操作Key不能为空", groups = { AddSingleOperation4RoleGroup.class }) private String operationKey; private List scopeKeys; + + // 操作列表,及其范围 + @Valid + @NotEmpty(message = "操作列表及其范围不能为空", groups = { AddMultiOperations4RoleGroup.class }) + private List operationsAndScopes = new ArrayList<>(); + + /** + * 操作及其范围封装类 + */ + public static class OperationsAndScopes { + + // 操作key + @NotBlank(message = "角色Key不能为空", groups = { AddMultiOperations4RoleGroup.class }) + private String operationKey; + + // 范围key列表 + @NotEmpty(message = "操作Key列表不能为空", groups = { AddMultiOperations4RoleGroup.class }) + private List scopeKeys; + + public String getOperationKey() { + return operationKey; + } + + public void setOperationKey(String operationKey) { + this.operationKey = operationKey; + } + + public List getScopeKeys() { + return scopeKeys; + } + + public void setScopeKeys(List scopeKeys) { + this.scopeKeys = 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 76a7886947..0983ca46a4 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 @@ -118,14 +118,14 @@ public class AccessConfigController { } /** - * @Description 给角色添加操作权限和操作范围 + * @Description 给角色添加单个操作权限和操作范围 * @return * @author wxz * @date 2020.11.17 17:41 */ @PostMapping("add-ope-and-scopes-4role") public Result addOpeAndScopes4Role(@RequestBody AccessConfigAdd4RoletFormDTO form) { - ValidatorUtils.validateEntity(form); + ValidatorUtils.validateEntity(form, AccessConfigAdd4RoletFormDTO.AddSingleOperation4RoleGroup.class); String roleKey = form.getRoleKey(); String operationKey = form.getOperationKey(); List scopeKeys = form.getScopeKeys(); @@ -134,5 +134,18 @@ public class AccessConfigController { return new Result(); } + /** + * @Description 给角色添加单个操作权限和操作范围 + * @return + * @author wxz + * @date 2020.12.02 16:20 + */ + @PostMapping("add-opes-and-scopes-4role") + public Result addOpesAndScopes4Role(@RequestBody AccessConfigAdd4RoletFormDTO form) { + ValidatorUtils.validateEntity(form, AccessConfigAdd4RoletFormDTO.AddMultiOperations4RoleGroup.class); + accessConfigService.addOpesAndScopes4Role(form.getRoleKey(), form.getOperationsAndScopes()); + return new Result(); + } + } 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 508f3ad45f..a2b1850e04 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 @@ -1,6 +1,6 @@ package com.epmet.service; -import com.epmet.dto.form.AccessConfigRoleDefaultOpesFormDTO; +import com.epmet.dto.form.AccessConfigAdd4RoletFormDTO; import com.epmet.dto.result.AccessConfigOpeDefaultScopesResultDTO; import com.epmet.dto.result.AccessConfigOpesResultDTO; import com.epmet.dto.result.AccessConfigOptionsResultDTO; @@ -27,4 +27,6 @@ public interface AccessConfigService { void saveOpeDefaultScopes(String roleKey, String operationKey, List scopeKeys); void addOpeAndScopes4Role(String roleKey, String operationKey, List scopeKeys); + + void addOpesAndScopes4Role(String roleKey, List operations); } 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 06f391eada..52a0ae282c 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 @@ -4,6 +4,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; import com.epmet.dao.*; +import com.epmet.dto.form.AccessConfigAdd4RoletFormDTO; import com.epmet.dto.result.*; import com.epmet.entity.OperationScopeDefaultEntity; import com.epmet.entity.RoleOperationDefaultEntity; @@ -261,4 +262,13 @@ public class AccessConfigServiceImpl implements AccessConfigService { } } } + + @Override + public void addOpesAndScopes4Role(String roleKey, List operations) { + for (AccessConfigAdd4RoletFormDTO.OperationsAndScopes operation : operations) { + String operationKey = operation.getOperationKey(); + List scopeKeys = operation.getScopeKeys(); + addOpeAndScopes4Role(roleKey, operationKey, scopeKeys); + } + } }