From a308409036586a1abe20695cb7ab6747fac9dcf8 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 30 Apr 2020 09:58:13 +0800 Subject: [PATCH] =?UTF-8?q?DEC-13003=20=E8=A7=92=E8=89=B2=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E8=AE=BE=E7=BD=AE=E6=8F=92=E4=BB=B6finekit=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../state/BaseRedisCollectionConfig.java | 6 +- .../fanruan/api/decision/AuthorityKit.java | 64 ++++++++++++++++++- .../api/decision/role/CustomRoleKit.java | 35 ++++++++++ .../fanruan/api/decision/user/UserKit.java | 13 +++- 4 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java diff --git a/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java b/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java index 4a620ef..20acb59 100644 --- a/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java +++ b/src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java @@ -13,12 +13,12 @@ public class BaseRedisCollectionConfig extends RedisCollectionConfig { public BaseRedisCollectionConfig(Codec codec, String host, int port) { - super(codec, host, port); + //super(codec, host, port); } public BaseRedisCollectionConfig(String host, int port, String password) { - super(host, port, password); + //super(host, port, password); } public BaseRedisCollectionConfig() { @@ -28,6 +28,6 @@ public class BaseRedisCollectionConfig extends RedisCollectionConfig { public BaseRedisCollectionConfig(String host, int port) { - super(host, port); + //super(host, port); } } diff --git a/src/main/java/com/fanruan/api/decision/AuthorityKit.java b/src/main/java/com/fanruan/api/decision/AuthorityKit.java index c19b311..2d84621 100644 --- a/src/main/java/com/fanruan/api/decision/AuthorityKit.java +++ b/src/main/java/com/fanruan/api/decision/AuthorityKit.java @@ -1,6 +1,12 @@ package com.fanruan.api.decision; +import com.fr.decision.authority.AuthorityContext; import com.fr.decision.authority.base.constant.AuthorityStaticItemId; +import com.fr.decision.authority.base.constant.AuthorityValue; +import com.fr.decision.authority.base.constant.type.authority.AuthorityType; +import com.fr.decision.authority.controller.GradeAuthorityController; +import com.fr.decision.authority.data.personnel.DepRole; +import com.fr.decision.webservice.utils.WebServiceUtils; /** * @author richie @@ -13,7 +19,7 @@ public class AuthorityKit { /** * 内置管理系统节点id */ - public static class Management{ + public static class Management { public static final String USER = AuthorityStaticItemId.DEC_MANAGEMENT_USER_ID; public static final String AUTHORITY = AuthorityStaticItemId.DEC_MANAGEMENT_AUTHORITY_ID; @@ -42,4 +48,60 @@ public class AuthorityKit { public static final String MAINTENANCE = AuthorityStaticItemId.DEC_MANAGEMENT_MAINTENANCE_ID; } + + /** + * 给部门职位设置人员管理权限 + * + * @param depostId 部门职位id + * @param authValue 接受/拒绝 + * @param authId 实体id + * @param authType 权限类型 + * @throws Exception 异常 + */ + public static void setDepAuth(String depostId, int authValue, String authId, int authType) throws Exception { + + DepRole depRole = WebServiceUtils.parseUniqueDepartmentPostId(depostId); + AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setDepAuthorityValue( + depRole.getDepartmentId(), + depRole.getPostId(), + AuthorityValue.fromInteger(authValue), + authId, + AuthorityType.fromInteger(authType)); + } + + /** + * 给用户设置人员管理权限 + * + * @param userId 用户id + * @param authValue 接受/拒绝 + * @param authId 实体id + * @param authType 权限类型 + * @throws Exception 异常 + */ + public static void setUserAuth(String userId, int authValue, String authId, int authType) throws Exception { + + AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setUserAuthorityValue( + userId, + AuthorityValue.fromInteger(authValue), + authId, + AuthorityType.fromInteger(authType)); + } + + /** + * 给角色设置人员管理权限 + * + * @param roleId 角色id + * @param authValue 接受/拒绝 + * @param authId 实体id + * @param authType 权限类型 + * @throws Exception 异常 + */ + public static void setCustomRoleAuth(String roleId, int authValue, String authId, int authType) throws Exception { + + AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setCustomAuthorityValue( + roleId, + AuthorityValue.fromInteger(authValue), + authId, + AuthorityType.fromInteger(authType)); + } } diff --git a/src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java b/src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java new file mode 100644 index 0000000..a6d3261 --- /dev/null +++ b/src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java @@ -0,0 +1,35 @@ +package com.fanruan.api.decision.role; + +import com.fr.decision.authority.data.CustomRole; +import com.fr.decision.webservice.utils.ControllerFactory; + +import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Zed + * @version 10.0 + * Created by Zed on 2020/4/30 + */ +public class CustomRoleKit { + + /** + * 获取角色id + * + * @param userId 用户id + * @param keyword 搜索关键字 + * @return 角色id + * @throws Exception 异常 + */ + public static List getCustomRoleIds(@NotNull String userId, String keyword) throws Exception { + + List result = new ArrayList<>(); + CustomRole[] roles = ControllerFactory.getInstance().getCustomRoleController(userId).getAllCustomRoles(userId, keyword); + for (CustomRole role : roles) { + result.add(role.getId()); + } + + return result; + } +} diff --git a/src/main/java/com/fanruan/api/decision/user/UserKit.java b/src/main/java/com/fanruan/api/decision/user/UserKit.java index 6375a0e..d5e0409 100644 --- a/src/main/java/com/fanruan/api/decision/user/UserKit.java +++ b/src/main/java/com/fanruan/api/decision/user/UserKit.java @@ -72,7 +72,18 @@ public class UserKit { * @return 用户名数组 * @throws Exception 如果邮箱不存在则抛出此异常 */ - public static List getUserNamesFromEmail(String email) throws Exception { + public static List getUserNamesFromEmail(String email) throws Exception { return UserService.getInstance().getUserNamesFromEmail(email); } + + /** + * 获取当前用户id + * + * @param request 请求体 + * @return 用户id + * @throws Exception 异常 + */ + public static String getCurrentUserId(HttpServletRequest request) throws Exception { + return UserService.getInstance().getCurrentUserId(request); + } }