From 9d92bb1d5698690bfd06fb93c668d9ae73300426 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期五, 13 十二月 2024 13:05:09 +0800 Subject: [PATCH] 添加按钮权限查询接口。 修改UI页面定义的属性字段。 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java | 62 ++++++++++++++++++++++-------- 1 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java index 2037c31..896915e 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/util/RightControlUtil.java @@ -9,15 +9,12 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; @Slf4j @Component public class RightControlUtil { - @Resource private PlatformClientUtil platformClientUtil; @@ -25,11 +22,17 @@ // add by xchao 2012.09.20 缁熶竴褰掓暣绠$悊鍛樸�佸紑鍙戣�呯敤鎴峰垽鏂� // 浠ヤ究灏嗘潵鏈夊彲鑳戒慨鏀圭鐞嗗憳銆佸紑鍙戣�呯敤鎴凤紝瀵逛簬鍒ゆ柇渚濈劧鏈夋晥 private static String userAdminEnum = "user.admin"; + private String userNameAdmin = null; + private static String userDeveloperEnum = "user.developer"; + private String userNameDeveloper = null; + private String userNameRoot = null; + private static String userRootEnum = "user.rooter"; + public boolean isAdmin(String userName){ return userName.equals(getUserNameAdmin(userAdminEnum)); } @@ -70,6 +73,7 @@ } return userNameAdmin; } + /** * 鑾峰彇閰嶇疆鐨勫紑鍙戜汉鍛� * @param key 閰嶇疆key @@ -168,7 +172,7 @@ if (mapRight.containsKey(right.funcId)) { lstRight = mapRight.get(right.funcId); } else { - lstRight = new ArrayList<RoleRightInfo>(); + lstRight = new ArrayList<>(); } lstRight.add(right); mapRight.put(right.funcId, lstRight); @@ -197,18 +201,8 @@ else{ if (lstRight.size() > 0) isHasRight = true; -// for (int j = 0; j < lstRight.size(); j++) { -// long lRight = lstRight.get(j).getRightValue(); -// if (lRight != 0){ -// isHasRight = true; -// //System.out.println(" === 鏈夋巿鏉�"); -// -// break; -// } -// } } } - if (!isHasRight) { continue; } @@ -227,7 +221,6 @@ return map; } - public FunctionInfo[] getFunctionsByParentId(String parentId, String userName) { FunctionInfo[] funcObjs = null; try { @@ -241,6 +234,40 @@ log.error(e.code, e.messages); } return funcObjs; + } + + /** + * 鏍规嵁鐖朵富閿拰鐢ㄦ埛浠ュ強瑙掕壊淇℃伅鏉ヨ繑鍥炶彍鍗曟暟鎹� + * @param parentId + * @param userName + * @param userRoleRights + * @return + */ + public List<FunctionInfo> getMenusByPIdAndPermission(String parentId, String userName,RoleRightInfo[] userRoleRights) { + Map<String, List<RoleRightInfo>> mapRight = new LinkedHashMap<String, List<RoleRightInfo>>(); + for (int i = 0; i < userRoleRights.length; i++) { + RoleRightInfo right = userRoleRights[i]; + + List<RoleRightInfo> lstRight = null; + if (mapRight.containsKey(right.funcId)) { + lstRight = mapRight.get(right.funcId); + } else { + lstRight = new ArrayList<>(); + } + lstRight.add(right); + mapRight.put(right.funcId, lstRight); + } + FunctionInfo[] functionInfos = this.getFunctionsByParentId(parentId, userName); + boolean isAllShow = isDeveloper(userName) || isAdmin(userName) || !isFunctionSwithOn(); + + List<FunctionInfo> functionInfoList = Arrays.stream(functionInfos).filter(menu -> { + // 鍙繑鍥炴湁鏁堜笖鏄彍鍗曠殑鑺傜偣 + if ((menu.isValid && menu.functionType == 0) && (mapRight.containsKey(menu.id) || isAllShow)) { + return true; + } + return false; + }).collect(Collectors.toList()); + return functionInfoList; } /** @@ -261,4 +288,5 @@ return false; } + } -- Gitblit v1.9.3