Commit 9a462646 by 江和松

菜单APP端查询需要查询出树结构

parent 363c3378
......@@ -12,13 +12,7 @@ import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import com.baosight.iplat4j.core.util.StringUtils;
import com.baosight.xservices.xs.util.LoginUserDetails;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -46,10 +40,10 @@ public class AuthenticationInfo {
private static final int DEFAULT_GROUP_THRESHOLD = 20;
private static Map<String, String> param = null;
private static final Logger logger = LogManager.getLogger(AuthenticationInfo.class);
public AuthenticationInfo() {
}
public static String getSubjectId(String subjectType, String subjectName) {
String memberId = null;
Map paramMap = new HashMap();
......@@ -69,7 +63,7 @@ public class AuthenticationInfo {
var9 = 0;
}
}
switch(var9) {
case 0:
subjectParam = "loginName";
......@@ -86,7 +80,7 @@ public class AuthenticationInfo {
resultParam = PlatApplicationContext.getProperty("xservices.security.subjectType." + subjectType + ".subjectIdParam");
checkSqlId = PlatApplicationContext.getProperty("xservices.security.subjectType." + subjectType + ".checkSqlId");
}
if (StringUtils.isNotEmpty(subjectParam) && StringUtils.isNotEmpty(resultParam) && StringUtils.isNotEmpty(checkSqlId)) {
paramMap.put(subjectParam, subjectName);
List members = getDao().query(checkSqlId, paramMap);
......@@ -95,23 +89,23 @@ public class AuthenticationInfo {
} else {
memberId = ((Map)members.get(0)).get(resultParam).toString();
}
return memberId;
} else {
throw new PlatException("当前授权类型主体配置缺失,请检查");
}
}
public static Map<String, Object> getUserBelongToGroups(String loginName) {
userBelongToGroups = CacheManager.getCache("iplat:security:subjectParentCache");
getUserBelongToGroupsList(loginName);
return userBelongToGroups;
}
public static List getUserBelongToGroupsList(String loginName) {
return getSubjectParentList("loginName", loginName, "XSAuthorization.queryUserGroupsByLoginName");
}
private static List getSubjectParentList(String paramKey, String paramVal, String sqlId) {
List result = (List)CacheManager.getCacheValue("iplat:security:subjectParentCache", paramVal, () -> {
param = new HashMap();
......@@ -120,14 +114,14 @@ public class AuthenticationInfo {
});
return result;
}
public static Map<String, Object> getResourceBelongToGroups(String resourceEname) {
param = new HashMap();
param.put("resourceEname", resourceEname);
getResultList("XSAuthorization.queryResourceGroupsByResourceEname", param, resourceBelongToGroups, resourceEname);
return resourceBelongToGroups;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getUserParentGroupsByGroupEname(String groupEname) {
......@@ -136,20 +130,20 @@ public class AuthenticationInfo {
returnMap.put(groupEname, result);
return returnMap;
}
public static List getUserParentGroupsByGroupEnameList(String groupEname) {
param = new HashMap();
param.put("groupEname", groupEname);
return getResultList("XSAuthorization.queryUserParentGroups", param);
}
public static Map<String, Object> getUserManagerGroups(String loginName) {
param = new HashMap();
param.put("loginName", loginName);
getResultList("XSAuthorization.queryUserManagerGroups", param, userManagerGroups, loginName);
return userManagerGroups;
}
public static Map<String, Object> getUserManageAuthentication(String loginName) {
long startTime = System.currentTimeMillis();
Map param = new HashMap();
......@@ -160,7 +154,7 @@ public class AuthenticationInfo {
System.out.println("getUserManageAuthentication使用时间:" + (endTime - startTime) + "毫秒");
return userManageAuthentication;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getAuthenticationByParam(String subjectName, String subjectType) {
......@@ -172,10 +166,10 @@ public class AuthenticationInfo {
authenticationByParam.put(subjectName, result);
resultMap = authenticationByParam;
}
return resultMap;
}
public static List getAuthenticationByParamList(String subjectName, String subjectType) {
List resultList = null;
if (subjectType.equals("USER")) {
......@@ -198,19 +192,19 @@ public class AuthenticationInfo {
result.addAll(list);
}
}
if (null != subjectList && subjectList.size() > 0) {
subjectId = ((Map)subjectList.get(0)).get("groupId").toString();
}
List list = getCachedSubjectAuthList(subjectId, subjectName);
result.addAll(list);
resultList = result;
}
return (List)resultList;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getOldAuthenticationByParam(String subjectName, String subjectType) {
......@@ -245,7 +239,7 @@ public class AuthenticationInfo {
paramMap.put(paramKey, subjectName);
subjectList = getDao().query("XSResourceManage.queryResourceGroup", paramMap);
}
if (null != parentGroupList && parentGroupList.size() > 0) {
for(int i = 0; i < parentGroupList.size(); ++i) {
Map map = new HashMap();
......@@ -254,11 +248,11 @@ public class AuthenticationInfo {
result.addAll(list);
}
}
if (null != subjectList && subjectList.size() > 0) {
subjectId = ((Map)subjectList.get(0)).get(subjectKey).toString();
}
Map map = new HashMap();
map.put("subjectId", subjectId);
List list = getResultList("XSAuthorization.queryRecursiveResourceAuthzBySubjectId", map);
......@@ -268,7 +262,7 @@ public class AuthenticationInfo {
return retMap;
}
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getUserAuthentication(String loginName) {
......@@ -276,11 +270,11 @@ public class AuthenticationInfo {
userAuthentication.put(loginName, result);
return userAuthentication;
}
public static List getUserAuthenticationList(String loginName) {
return getSubjectAuthenticationList(loginName, "USER");
}
public static List getSubjectAuthenticationList(String subjectName, String subjectType) {
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
......@@ -313,7 +307,7 @@ public class AuthenticationInfo {
String parentGroupSqlId = PlatApplicationContext.getProperty("xservices.security.subjectType." + subjectType + ".parentGroupSqlId");
userGroupsList = getSubjectParentList(subjectParam, subjectName, parentGroupSqlId);
}
long endTime1 = System.currentTimeMillis();
long executionTime1 = endTime1 - startTime1;
logger.info("getUserAuthenticationList:List userGroupsList = getUserBelongToGroupsList(loginName);Time:" + executionTime1);
......@@ -326,7 +320,7 @@ public class AuthenticationInfo {
} catch (NumberFormatException | NullPointerException var41) {
groupThreshold = 20;
}
List groupListAuthList;
if (userGroupsList.size() > groupThreshold) {
List paramUserGroupList = new ArrayList(userGroupsList);
......@@ -336,10 +330,10 @@ public class AuthenticationInfo {
} else {
groupListAuthList = getGroupListAuthList(userGroupsList);
}
result.addAll(groupListAuthList);
}
long endTime3 = System.currentTimeMillis();
long executionTime3 = endTime3 - startTime3;
logger.info("getUserAuthenticationList:groupListAuthList = getGroupListAuthList(userGroupsList);Time:" + executionTime3);
......@@ -349,29 +343,29 @@ public class AuthenticationInfo {
long endTime4 = System.currentTimeMillis();
long executionTime4 = endTime4 - startTime3;
logger.info("getUserAuthenticationList:List list = getCachedSubjectAuthList(userId, loginName);Time:" + executionTime4);
for(int k = 0; k < result.size(); ++k) {
Map resultMap = (Map)result.get(k);
resultMap.put(resultParam, subjectId);
}
long endTime5 = System.currentTimeMillis();
long executionTime5 = endTime5 - startTime;
logger.info("getUserAuthenticationList:TotalTime:" + executionTime5);
return result;
}
}
private static List getGroupListAuthList(List userGroupsList) {
Set resultGroupIds = new HashSet();
List resultGroups = new ArrayList();
for(int i = 0; i < userGroupsList.size(); ++i) {
String subjectId = (String)((Map)userGroupsList.get(i)).get("groupId");
String groupEname = (String)((Map)userGroupsList.get(i)).get("groupEname");
List list = getCachedSubjectAuthList(subjectId, groupEname);
Iterator var7 = list.iterator();
while(var7.hasNext()) {
Object cacheVal = var7.next();
if (cacheVal instanceof Map) {
......@@ -386,11 +380,11 @@ public class AuthenticationInfo {
}
}
}
resultGroupIds.clear();
return resultGroups;
}
private static List getCachedSubjectAuthList(String subjectId, String subjectEname) {
List list = (List)CacheManager.getCacheValue("iplat:security:subjectCache", subjectEname, () -> {
Map map = new HashMap();
......@@ -399,7 +393,7 @@ public class AuthenticationInfo {
});
return list;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getOldUserAuthentication(String loginName) {
......@@ -415,22 +409,22 @@ public class AuthenticationInfo {
result.addAll(list);
}
}
Map map = new HashMap();
map.put("subjectId", userDetails.get("userId"));
List list = getResultList("XSAuthorization.queryRecursiveResourceAuthzBySubjectId", map);
for(int k = 0; k < result.size(); ++k) {
Map resultMap = (Map)list.get(k);
resultMap.put("userId", userDetails.get("userId"));
}
result.addAll(list);
Map retMap = new HashMap();
retMap.put(loginName, result);
return retMap;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getUserAuthenticationOfResource(String loginName) {
......@@ -438,7 +432,7 @@ public class AuthenticationInfo {
userAuthenticationOfResource.put(loginName, result);
return userAuthenticationOfResource;
}
public static List getUserAuthenticationOfResourceList(String loginName) {
Map<String, Object> userBelongToGroups = getUserBelongToGroups(loginName);
List userGroupsList = (List)userBelongToGroups.get(loginName);
......@@ -455,11 +449,11 @@ public class AuthenticationInfo {
filterAuthResourceList(result, resEnameSet, list);
}
}
sortResorceList(result);
return result;
}
private static void sortResorceList(List<Map> result) {
result.sort((map1, map2) -> {
String key1 = map1.get("resourceEname").toString() + map1.get("operationType").toString();
......@@ -467,10 +461,10 @@ public class AuthenticationInfo {
return key1.compareTo(key2);
});
}
private static void filterAuthResourceList(List result, Set<String> resEnameSet, List list) {
Iterator var3 = list.iterator();
while(var3.hasNext()) {
Object resultObj = var3.next();
String resEname = (String)((Map)resultObj).get("resourceEname");
......@@ -481,9 +475,9 @@ public class AuthenticationInfo {
resEnameSet.add(key);
}
}
}
private static List<Map> clearButtonOfResource(List<Map> list) {
List<Map> result = new ArrayList();
if (null != list && list.size() > 0) {
......@@ -494,10 +488,10 @@ public class AuthenticationInfo {
}
}
}
return result;
}
private static List getCachedSubjectResList(String subjectId, String subjectEname) {
List<Map> list = (List)CacheManager.getCacheValue("iplat:security:subjectResourceCache", subjectEname, () -> {
Map map = new HashMap();
......@@ -508,7 +502,7 @@ public class AuthenticationInfo {
List newList2 = (List)Stream.concat(list.stream(), listUnAuthed.stream()).collect(Collectors.toList());
return newList2;
}
public static List getAllUnAuthPageButt() {
List<Map> list = (List)CacheManager.getCacheValue("iplat:security:unAuthPageButtCache", "unAuthPageButtCache", () -> {
List resultList = getResultList("XSAuthorization.queryAllUnAuthPageButt", new HashMap());
......@@ -516,7 +510,7 @@ public class AuthenticationInfo {
});
return list;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getOldUserAuthenticationOfResource(String loginName) {
......@@ -530,7 +524,7 @@ public class AuthenticationInfo {
res.put(loginName, result);
return res;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getUserAuthMenuPages(String p, String loginName) {
......@@ -538,7 +532,7 @@ public class AuthenticationInfo {
userAuthMenuPages.put(loginName, menuAndPageListForTree);
return userAuthMenuPages;
}
public static List getUserAuthMenuPagesList(String p, String loginName, String source) {
List result = null;
p = !org.apache.commons.lang.StringUtils.isEmpty(p) && !"$".equals(p) ? p : "root";
......@@ -557,7 +551,7 @@ public class AuthenticationInfo {
List pageAuthList = getUserAuthPagesList(loginName);
List menuList = new ArrayList();
List pageList = new ArrayList();
for(int i = 0; i < ret.size(); ++i) {
Map retMap = (Map)ret.get(i);
if ("1".equals(retMap.get("leaf").toString())) {
......@@ -566,67 +560,86 @@ public class AuthenticationInfo {
menuList.add(retMap);
}
}
List menuAndPageListForTree = new ArrayList();
for(int i = 0; i < ret.size(); ++i) {
Map retResultMap = (Map)ret.get(i);
BigDecimal retLeaf = (BigDecimal)retResultMap.get("leaf");
BigDecimal menuDecimal = new BigDecimal("2");
BigDecimal leafDecimal = new BigDecimal("1");
String parent = (String)retResultMap.get("parent");
if (retLeaf != null && menuDecimal.equals(retLeaf)) {
Map paramMap = new HashMap();
paramMap.put("node", retResultMap.get("label").toString());
List childPageForMenu = getDao().query("XSMenu.queryForRecursiveChildPage", paramMap);
boolean flag = false;
List childList = new LinkedList();
if (childPageForMenu != null && childPageForMenu.size() > 0) {
label85:
for(int j = 0; j < pageAuthList.size(); ++j) {
Map pageAuthMap = (Map)pageAuthList.get(j);
for(int k = 0; k < childPageForMenu.size(); ++k) {
Map childPageMap = (Map)childPageForMenu.get(k);
if (childPageMap.get("label").toString().equals(pageAuthMap.get("label").toString())) {
flag = true;
break label85;
//APP需要遍历所有子菜单
if(parent.equals("APP")){
label85:
for(int j = 0; j < pageAuthList.size(); ++j) {
Map pageAuthMap = (Map)pageAuthList.get(j);
for(int k = 0; k < childPageForMenu.size(); ++k) {
Map childPageMap = (Map)childPageForMenu.get(k);
if (childPageMap.get("label").toString().equals(pageAuthMap.get("label").toString())) {
flag = true;
childList.add(pageAuthMap);
}
}
}
}else{
label85:
for(int j = 0; j < pageAuthList.size(); ++j) {
Map pageAuthMap = (Map)pageAuthList.get(j);
for(int k = 0; k < childPageForMenu.size(); ++k) {
Map childPageMap = (Map)childPageForMenu.get(k);
if (childPageMap.get("label").toString().equals(pageAuthMap.get("label").toString())) {
flag = true;
childList.add(pageAuthMap);
break label85;
}
}
}
}
retResultMap.put("childMenu",childList);
}
if (flag) {
menuAndPageListForTree.add(retResultMap);
}
} else if (retLeaf != null && leafDecimal.equals(retLeaf)) {
boolean pageFlag = false;
for(int k = 0; k < pageAuthList.size(); ++k) {
Map pageAuthMap = (Map)pageAuthList.get(k);
if (pageAuthMap.get("label").toString().equals(retResultMap.get("label").toString())) {
pageFlag = true;
}
}
if (pageFlag) {
menuAndPageListForTree.add(retResultMap);
}
}
}
result = menuAndPageListForTree;
}
List newResult = new ArrayList();
for(int i = 0; i < ((List)result).size(); ++i) {
if (((Map)((List)result).get(i)).get("show_flag") == null || ((Map)((List)result).get(i)).get("show_flag").equals("1")) {
newResult.add(((List)result).get(i));
}
}
return newResult;
}
public static List getUserAllAuthMenuPagesList(String loginName) {
long startTime = System.currentTimeMillis();
List result = new ArrayList();
......@@ -660,7 +673,7 @@ public class AuthenticationInfo {
long startTime4 = System.currentTimeMillis();
List menuList = new ArrayList();
List pageList = new ArrayList();
for(int i = 0; i < ret.size(); ++i) {
Map retMap = (Map)ret.get(i);
if ("1".equals(retMap.get("leaf").toString())) {
......@@ -669,24 +682,24 @@ public class AuthenticationInfo {
menuList.add(retMap);
}
}
Map authPageMap = new HashMap();
for(int i = 0; i < pageAuthList.size(); ++i) {
String label = (String)((Map)pageAuthList.get(i)).get("label");
authPageMap.put(label, pageAuthList.get(i));
}
Map menuMap = new HashMap();
for(int i = 0; i < menuList.size(); ++i) {
String label = (String)((Map)menuList.get(i)).get("label");
menuMap.put(label, menuList.get(i));
}
Map pageResultMap = new HashMap();
Map menuResultMap = new HashMap();
int i;
Map entity;
for(i = 0; i < pageList.size(); ++i) {
......@@ -699,25 +712,25 @@ public class AuthenticationInfo {
menuResultMap = setMenuResultMap(parent, (Map)menuResultMap, menuMap);
}
}
for(i = 0; i < ret.size(); ++i) {
entity = (Map)ret.get(i);
if (((Map)menuResultMap).get(entity.get("label")) != null || pageResultMap.get(entity.get("label")) != null) {
((List)result).add(ret.get(i));
}
}
long endTime4 = System.currentTimeMillis();
long executionTime4 = endTime4 - startTime4;
logger.info("getUserAllAuthMenuPagesList:my_set_resultTime:" + executionTime4);
}
endTime5 = System.currentTimeMillis();
executionTime5 = endTime5 - startTime;
logger.info("getUserAllAuthMenuPagesList:totalTime:" + executionTime5);
return (List)result;
}
private static Map setMenuResultMap(String parentLabel, Map menuResultMap, Map<String, Map> menuMap) {
Map menu = (Map)menuMap.get(parentLabel);
if (menu != null && menuResultMap.get(parentLabel) == null) {
......@@ -725,10 +738,10 @@ public class AuthenticationInfo {
String parent = (String)menu.get("parent");
menuResultMap = setMenuResultMap(parent, menuResultMap, menuMap);
}
return menuResultMap;
}
/** @deprecated */
@Deprecated
public static Map<String, Object> getUserAuthPages(String loginName) {
......@@ -736,7 +749,7 @@ public class AuthenticationInfo {
userAuthPages.put(loginName, pageAuthList);
return userAuthPages;
}
public static List getUserAuthPagesList(String loginName) {
long startTime = System.currentTimeMillis();
List authList = getUserAuthenticationList(loginName);
......@@ -750,7 +763,7 @@ public class AuthenticationInfo {
long executionTime1 = endTime1 - startTime1;
logger.info("getUserAuthPagesList:List ret = getResultList(\"XSMenu.query\", new HashMap());Time:" + executionTime1);
List pageAuthList = new ArrayList();
int i;
Map pageMap;
for(i = 0; i < ret.size(); ++i) {
......@@ -759,7 +772,7 @@ public class AuthenticationInfo {
pageList.add(pageMap);
}
}
if (pageList.size() > 0) {
for(i = 0; i < pageList.size(); ++i) {
pageMap = (Map)pageList.get(i);
......@@ -776,35 +789,35 @@ public class AuthenticationInfo {
} else {
flag = true;
}
if (flag) {
pageAuthList.add(pageMap);
}
}
}
long endTime2 = System.currentTimeMillis();
long executionTime2 = endTime2 - startTime;
logger.info("getUserAuthPagesList:TotalTime:" + executionTime2);
return pageAuthList;
}
public static List getResultList(String sqlMap, Map params) {
List resultList = getDao().query(sqlMap, params, 0, -999999);
return resultList;
}
/** @deprecated */
public static Map<String, Object> getResultList(String sqlMap, Map params, Map result, String subjectName) {
if (params == null) {
params = new HashMap();
}
List resultList = getResultList(sqlMap, (Map)params);
result.put(subjectName, resultList);
return result;
}
public static List getUserAuthenticationPageOfResource(String loginName) {
Map<String, Object> userBelongToGroups = getUserBelongToGroups(loginName);
List userGroupsList = (List)userBelongToGroups.get(loginName);
......@@ -821,12 +834,12 @@ public class AuthenticationInfo {
filterAuthResourceList(result, resEnameSet, list);
}
}
List<Map> pageList = clearButtonOfResource(result);
sortResorceList(pageList);
return pageList;
}
private static List getCachedSubjectPageList(String subjectId, String subjectEname) {
List list = (List)CacheManager.getCacheValue("iplat:security:subjectPageCache", subjectEname, () -> {
Map map = new HashMap();
......@@ -837,7 +850,7 @@ public class AuthenticationInfo {
List newList2 = (List)Stream.concat(list.stream(), listUnAuthed.stream()).collect(Collectors.toList());
return newList2;
}
private static Dao getDao() {
return (Dao)PlatApplicationContext.getBean("dao");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment