| | |
| | | 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; |
| | |
| | | // 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)); |
| | | } |
| | |
| | | } |
| | | return userNameAdmin; |
| | | } |
| | | |
| | | /** |
| | | * 获取配置的开发人员 |
| | | * @param key 配置key |
| | |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | |
| | | return map; |
| | | } |
| | | |
| | | |
| | | public FunctionInfo[] getFunctionsByParentId(String parentId, String userName) { |
| | | FunctionInfo[] funcObjs = null; |
| | | try { |
| | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | } |