package jnpf.permission.util; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import jnpf.base.UserInfo; import jnpf.base.entity.*; import jnpf.base.model.base.SystemBaeModel; import jnpf.base.model.button.ButtonModel; import jnpf.base.model.column.ColumnModel; import jnpf.base.model.form.ModuleFormModel; import jnpf.base.model.module.ModuleModel; import jnpf.base.model.print.PaginationPrint; import jnpf.base.model.resource.ResourceModel; import jnpf.base.service.*; import jnpf.constant.AuthorizeConst; import jnpf.constant.CodeConst; import jnpf.constant.JnpfConst; import jnpf.constant.PermissionConst; import jnpf.flowable.entity.TemplateEntity; import jnpf.flowable.model.template.TemplateTreeListVo; import jnpf.permission.entity.*; import jnpf.permission.model.authorize.*; import jnpf.permission.model.user.UserAuthForm; import jnpf.permission.model.user.mod.UserAuthorizeModel; import jnpf.permission.model.user.vo.UserAuthorizeVO; import jnpf.permission.service.*; import jnpf.util.JsonUtil; import jnpf.util.StringUtil; import jnpf.util.UserProvider; import jnpf.util.treeutil.SumTree; import jnpf.util.treeutil.newtreeutil.TreeDotUtils; import jnpf.workflow.service.TemplateApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; import java.util.stream.Collectors; /** * 权限查询列表 * * @author JNPF开发平台组 * @version v6.0.0 * @copyright 引迈信息技术有限公司 * @date 2025/3/19 14:59:51 */ @Component public class AuthPermUtil { @Autowired private AuthorizeService authorizeService; @Autowired private UserService userService; @Autowired private OrganizeService organizeService; @Autowired private PositionService positionService; @Autowired private RoleRelationService roleRelationService; @Autowired private SystemService systemApi; @Autowired private ModuleService moduleApi; @Autowired private ModuleButtonService buttonApi; @Autowired private ModuleColumnService columnApi; @Autowired private ModuleDataAuthorizeSchemeService schemeApi; @Autowired private ModuleFormService formApi; @Autowired private TemplateApi templateApi; @Autowired private PrintDevService printDevApi; public AuthorizeDataReturnVO getAuthMenuList(AuthorizeParam authorizeParam) { UserInfo userInfo = UserProvider.getUser(); Boolean isManageRole = userInfo.getIsManageRole(); Boolean isDevRole = userInfo.getIsDevRole(); //当前用户可配置权限 AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, null, 0, true); //继承上级权限 List authorizeList = authorizeService.list(new QueryWrapper().lambda().eq(AuthorizeEntity::getObjectId, authorizeParam.getObjectId())); //获取资源系统和菜单全数据 setAllSysAndModule(authorizeParam); // 处理当前用户不可选的 List authModelList = authorizeModel.getModuleList(); List authSysList = authorizeModel.getSystemList(); Set noContainsIds = new HashSet<>(); //额外添加用户创建的应用-及菜单 List listByCreUser = systemApi.getListByCreUser(userInfo.getUserId()); List creSysIds = listByCreUser.stream().map(SystemEntity::getId).collect(Collectors.toList()); authSysList.addAll(JsonUtil.getJsonToList(listByCreUser, SystemBaeModel.class)); noContainsIds.addAll(moduleApi.getModuleBySystemIds(creSysIds, null, null, 1).stream().map(ModuleEntity::getId).collect(Collectors.toList())); //添加当前用户有的权限 for (SystemBaeModel systemBaeModel : authSysList) { noContainsIds.add(systemBaeModel.getId()); if (Objects.equals(systemBaeModel.getIsMain(), 1)) { noContainsIds.add(CodeConst.XTCD); } else { noContainsIds.add(CodeConst.YYCD); } } for (ModuleModel moduleModel : authModelList) { noContainsIds.add(moduleModel.getId()); if (JnpfConst.WEB.equals(moduleModel.getCategory())) { noContainsIds.add(moduleModel.getSystemId() + "2"); } if (JnpfConst.APP.equals(moduleModel.getCategory())) { noContainsIds.add(moduleModel.getSystemId() + "1"); } } String moduleIds = authorizeParam.getModuleIds(); List selectIds = new ArrayList<>(); if (StringUtil.isNotBlank(moduleIds)) { String[] split = moduleIds.split(","); selectIds.addAll(Arrays.asList(split)); } //出系统菜单外其他类型的数据 List otherMList = new ArrayList<>(); // 选中的菜单 List ids = new ArrayList<>(); //实际业务 List menuEntityList = authorizeParam.getMenuEntityList(); Set hasModule = new HashSet<>(); switch (authorizeParam.getItemType()) { case AuthorizeConst.MODULE: ids = authorizeList.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); break; case AuthorizeConst.BUTTON: List buttonList = authorizeParam.getButtonEntityList(); for (ModuleButtonEntity item : buttonList) { //菜单选中的数据过滤 if (selectIds.contains(item.getModuleId())) { ModuleModel model = JsonUtil.getJsonToBean(item, ModuleModel.class); model.setParentId(item.getModuleId()); otherMList.add(model); hasModule.add(item.getModuleId()); } } //移除没有按钮的菜单 menuEntityList = removeLeaf(menuEntityList, hasModule); authorizeParam.setMenuEntityList(menuEntityList); //处理选中的 ids = authorizeList.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); //处理当前用户不可选的 List authBtnList = authorizeModel.getButtonList(); authBtnList.stream().forEach(t -> noContainsIds.add(t.getId())); break; case AuthorizeConst.COLUMN: List columnEntityList = authorizeParam.getColumnEntityList(); for (ModuleColumnEntity item : columnEntityList) { //菜单选中的数据过滤 if (selectIds.contains(item.getModuleId())) { ModuleModel model = JsonUtil.getJsonToBean(item, ModuleModel.class); model.setParentId(item.getModuleId()); otherMList.add(model); hasModule.add(item.getModuleId()); } } //移除没有的菜单 menuEntityList = removeLeaf(menuEntityList, hasModule); authorizeParam.setMenuEntityList(menuEntityList); //处理选中的 ids = authorizeList.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); //处理当前用户不可选的 List columnList = authorizeModel.getColumnList(); columnList.stream().forEach(t -> noContainsIds.add(t.getId())); break; case AuthorizeConst.RESOURCE: List resEntityList = authorizeParam.getResEntityList(); for (ModuleDataAuthorizeSchemeEntity item : resEntityList) { //菜单选中的数据过滤 if (selectIds.contains(item.getModuleId())) { ModuleModel model = JsonUtil.getJsonToBean(item, ModuleModel.class); model.setParentId(item.getModuleId()); otherMList.add(model); hasModule.add(item.getModuleId()); } } //移除没有的菜单 menuEntityList = removeLeaf(menuEntityList, hasModule); authorizeParam.setMenuEntityList(menuEntityList); //处理选中的 ids = authorizeList.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); //处理当前用户不可选的 List resourceList = authorizeModel.getResourceList(); resourceList.stream().forEach(t -> noContainsIds.add(t.getId())); break; case AuthorizeConst.FROM: List formEntityList = authorizeParam.getFormEntityList(); for (ModuleFormEntity item : formEntityList) { //菜单选中的数据过滤 if (selectIds.contains(item.getModuleId())) { ModuleModel model = JsonUtil.getJsonToBean(item, ModuleModel.class); model.setParentId(item.getModuleId()); otherMList.add(model); hasModule.add(item.getModuleId()); } } //移除没有的菜单 menuEntityList = removeLeaf(menuEntityList, hasModule); authorizeParam.setMenuEntityList(menuEntityList); //处理选中的 ids = authorizeList.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); //处理当前用户不可选的 List formsList = authorizeModel.getFormsList(); formsList.stream().forEach(t -> noContainsIds.add(t.getId())); break; default: break; } //组装系统菜单数据 List moduleList = new ArrayList<>(getModuleModels(authorizeParam)); //添加其他类型数据 moduleList.addAll(otherMList); //树形转换 List allIds = moduleList.stream().map(t -> t.getId()).collect(Collectors.toList()); List treeList = JsonUtil.getJsonToList(moduleList, AuthorizeDataModel.class); treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeDataModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())) .thenComparing(AuthorizeDataModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList()); //递归禁用当前用户不可操作的数据 Set disList = new HashSet<>(); treeList.forEach(t -> { if (!noContainsIds.contains(t.getId())) { t.setDisabled(true); disList.add(t.getId()); } }); setDisable(treeList, disList); List> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1"); List data = JsonUtil.getJsonToList(trees, AuthorizeDataReturnModel.class); if ((isManageRole || isDevRole)) { setDisableFalse(data, true); } setParentFalse(data, ids); AuthorizeDataReturnVO vo = new AuthorizeDataReturnVO(); vo.setList(data); vo.setAll(allIds); vo.setIds(ids); return vo; } /** * 菜单添加上级 * * @param authorizeParam * @return */ private List getModuleModels(AuthorizeParam authorizeParam) { boolean isMain = JnpfConst.MAIN_SYSTEM_CODE.equals(authorizeParam.getAppCode()) ? true : false; List systemEntityList = authorizeParam.getSystemEntityList(); List menuEntityList = authorizeParam.getMenuEntityList(); List removeMenu = new ArrayList<>(); removeMenu.addAll(JnpfConst.APP_CONFIG_MODULE); removeMenu.addAll(JnpfConst.ONLINE_DEV_MODULE); List menuHasSystemId = menuEntityList.stream().map(ModuleEntity::getSystemId).collect(Collectors.toList()); List xtIds = new ArrayList<>();//系统 List yyList = new ArrayList<>();//应用 List yyIds = new ArrayList<>(); for (SystemEntity systemEntity : systemEntityList) { if (!menuHasSystemId.contains(systemEntity.getId())) continue; if (Objects.equals(systemEntity.getIsMain(), 1)) { xtIds.add(systemEntity.getId()); } else { ModuleModel yymodel = JsonUtil.getJsonToBean(systemEntity, ModuleModel.class); yymodel.setParentId(CodeConst.YYCD); yyList.add(yymodel); yyIds.add(systemEntity.getId()); } } List xtCdList = new ArrayList<>();//系统菜单 List yyCdList = new ArrayList<>();//应用菜单 Map appIds = new HashMap<>(16); Map webIds = new HashMap<>(16); for (ModuleEntity moduleEntity : menuEntityList) { if (removeMenu.contains(moduleEntity.getEnCode())) continue; ModuleModel t = JsonUtil.getJsonToBean(moduleEntity, ModuleModel.class); if (xtIds.contains(t.getSystemId())) { if ("-1".equals(t.getParentId())) { t.setParentId(CodeConst.XTCD); } xtCdList.add(t); } else { if (JnpfConst.APP.equals(t.getCategory()) && "-1".equals(t.getParentId())) { if (!appIds.containsKey(t.getSystemId())) { t.setParentId(t.getSystemId() + "1"); ModuleModel appData = new ModuleModel(); appData.setId(t.getSystemId() + "1"); appData.setSortCode(0L); appData.setFullName("APP菜单"); appData.setIcon(PermissionConst.APP_ICON); appData.setParentId(t.getSystemId()); appData.setSystemId(t.getSystemId()); yyCdList.add(appData); appIds.put(t.getSystemId(), appData.getId()); } else { t.setParentId(appIds.get(t.getSystemId()) + ""); } } else if (JnpfConst.WEB.equals(t.getCategory()) && "-1".equals(t.getParentId())) { if (!webIds.containsKey(t.getSystemId())) { t.setParentId(t.getSystemId() + "2"); ModuleModel webData = new ModuleModel(); webData.setId(t.getSystemId() + "2"); webData.setSortCode(-1L); webData.setFullName("WEB菜单"); webData.setIcon(PermissionConst.PC_ICON); webData.setParentId(t.getSystemId()); webData.setSystemId(t.getSystemId()); yyCdList.add(webData); webIds.put(t.getSystemId(), webData.getId()); } else { t.setParentId(webIds.get(t.getSystemId()) + ""); } } yyCdList.add(t); } } List modelList = new ArrayList<>(); if (isMain) { ModuleModel moduleModel = new ModuleModel(); moduleModel.setId(CodeConst.XTCD); moduleModel.setFullName("系统菜单"); moduleModel.setParentId("-1"); ModuleModel moduleModel2 = new ModuleModel(); moduleModel2.setId(CodeConst.YYCD); moduleModel2.setFullName("应用菜单"); moduleModel2.setParentId("-1"); if (CollectionUtil.isNotEmpty(xtCdList)) { modelList.add(moduleModel); } if (CollectionUtil.isNotEmpty(yyCdList)) { modelList.add(moduleModel2); } modelList.addAll(yyList); modelList.addAll(xtCdList); modelList.addAll(yyCdList); } else { modelList.addAll(yyCdList); } return modelList; } /** * 获取当前 组织、岗位、角色拥有的全部系统和菜单权限 */ private void setAllSysAndModule(AuthorizeParam authorizeParam) { String objectId = authorizeParam.getObjectId(); String objectType = authorizeParam.getObjectType(); String itemType = authorizeParam.getItemType(); boolean needFilter = true;//根据组织岗位角色判断是否需要过滤 List list = new ArrayList<>(); if (PermissionConst.ORGANIZE.equals(objectType)) { OrganizeEntity info = organizeService.getInfo(objectId); if ("-1".equals(info.getParentId()) || StringUtil.isEmpty(info.getParentId())) { //全数据 needFilter = false; } else { //获取父级组织和组织角色的全部授权菜单 List objectIds = new ArrayList<>(); objectIds.add(info.getParentId()); List collect = roleRelationService.getListByObjectId(info.getParentId(), PermissionConst.ORGANIZE) .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); objectIds.addAll(collect); list = authorizeService.list(new QueryWrapper().lambda().in(AuthorizeEntity::getObjectId, objectIds)); } } if (PermissionConst.POSITION.equals(objectType)) { PositionEntity info = positionService.getInfo(objectId); if ("-1".equals(info.getParentId()) || StringUtil.isEmpty(info.getParentId())) { List objectIds = new ArrayList<>(); objectIds.add(info.getOrganizeId()); List collect = roleRelationService.getListByObjectId(info.getOrganizeId(), PermissionConst.ORGANIZE) .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); objectIds.addAll(collect); list = authorizeService.list(new QueryWrapper().lambda().in(AuthorizeEntity::getObjectId, objectIds)); } else { //获取父级岗位及岗位角色的全部授权信息 List objectIds = new ArrayList<>(); objectIds.add(info.getParentId()); List collect = roleRelationService.getListByObjectId(info.getParentId(), PermissionConst.POSITION) .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); objectIds.addAll(collect); list = authorizeService.list(new QueryWrapper().lambda().in(AuthorizeEntity::getObjectId, objectIds)); } } if (PermissionConst.ROLE.equals(objectType)) { //全数据 needFilter = false; } if (needFilter) { List systemList = list.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List moduleList = list.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); authorizeParam.setSystemEntityList(systemApi.getListByIds(systemList, null) .stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); authorizeParam.setMenuEntityList(moduleApi.getModuleByIds(moduleList) .stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); if (AuthorizeConst.BUTTON.equals(itemType)) { List itemIds = list.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); authorizeParam.setButtonEntityList(buttonApi.getListByIds(itemIds).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.COLUMN.equals(itemType)) { List itemIds = list.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); authorizeParam.setColumnEntityList(columnApi.getListByIds(itemIds).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.RESOURCE.equals(itemType)) { List itemIds = list.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); authorizeParam.setResEntityList(schemeApi.getListByIds(itemIds).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.FROM.equals(itemType)) { List itemIds = list.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType())).map(AuthorizeEntity::getItemId).collect(Collectors.toList()); authorizeParam.setFormEntityList(formApi.getListByIds(itemIds).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } } else { authorizeParam.setSystemEntityList(systemApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); authorizeParam.setMenuEntityList(moduleApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); if (AuthorizeConst.BUTTON.equals(itemType)) { authorizeParam.setButtonEntityList(buttonApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.COLUMN.equals(itemType)) { authorizeParam.setColumnEntityList(columnApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.RESOURCE.equals(itemType)) { authorizeParam.setResEntityList(schemeApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } if (AuthorizeConst.FROM.equals(itemType)) { authorizeParam.setFormEntityList(formApi.getList().stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList())); } } } /** * 递归获取包含的上级(根据下级移除没有下级的数据) * * @param list * @param hasIds * @return */ public static List removeLeaf(List list, Set hasIds) { List res = new ArrayList<>(); Set newHasIds = new HashSet<>(); for (ModuleEntity moduleEntity : list) { if (hasIds.contains(moduleEntity.getId())) { res.add(moduleEntity); newHasIds.add(moduleEntity.getParentId()); } } if (CollectionUtil.isNotEmpty(newHasIds)) { res.addAll(removeLeaf(list, newHasIds)); } return res; } private static void setDisable(List list, Set disList) { Set newIds = new HashSet<>(); for (AuthorizeDataModel item : list) { if (disList.contains(item.getId())) { item.setDisabled(true); if (StringUtil.isNotEmpty(item.getParentId()) && !"-1".equals(item.getParentId())) { newIds.add(item.getParentId()); } } } if (CollectionUtil.isNotEmpty(newIds)) { setDisable(list, newIds); } } /** * 管理员和开发者角色:应用部分菜单可授权 * * @param list * @param isFirst 是否一级 */ private static void setDisableFalse(List list, boolean isFirst) { for (AuthorizeDataReturnModel item : list) { if (!isFirst || CodeConst.YYCD.equals(item.getId())) { item.setDisabled(false); if (CollectionUtil.isNotEmpty(item.getChildren())) { setDisableFalse(item.getChildren(), false); } } } } private static void setParentFalse(List list, List ids) { for (AuthorizeDataReturnModel item : list) { if (CollectionUtil.isNotEmpty(item.getChildren())) { //先进底层设置 setParentFalse(item.getChildren(), ids); //设置完后,设置当前层级问题 List children = item.getChildren(); List collect = children.stream().filter(t -> t.isDisabled()).collect(Collectors.toList()); boolean disCheck = collect.stream().anyMatch(t -> ids.contains(t.getId())); //全部禁用不调整,禁用的没有被勾选--放开上级勾选 if (children.size() != collect.size() && !disCheck) { item.setDisabled(false); } } } } /** * 递归获取需要删除的权限idlist * * @param param * @return */ public static List getDelAllAuth(AuthorizeSaveParam param) { List listRes = new ArrayList<>(); Map> allAuthMap = param.getAllAuthMap(); List roleRealationList = param.getRoleRealationList(); List allOrgList = param.getAllOrgList(); List allPosList = param.getAllPosList(); String objectType = param.getObjectType(); String objectId = param.getObjectId(); List systemSave = new ArrayList<>(param.getSystemSave()); List moduleSave = new ArrayList<>(param.getModuleSave()); List buttonSave = new ArrayList<>(param.getButtonSave()); List columnSave = new ArrayList<>(param.getColumnSave()); List resourceSave = new ArrayList<>(param.getResourceSave()); List formSave = new ArrayList<>(param.getFormSave()); if (PermissionConst.ORGANIZE.equals(objectType)) { OrganizeEntity organizeEntity = allOrgList.stream().filter(t -> objectId.equals(t.getId())).findFirst().orElse(null); if (organizeEntity != null) { List roleIds = roleRealationList.stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType()) && objectId.equals(t.getObjectId())).map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); //本级角色拥有的下级不删除 for (String roleId : roleIds) { //移除角色相关权限时,需要跳过当前权限 if (StringUtil.isNotEmpty(param.getThisRole())) continue; //角色权限为空跳过 if (allAuthMap.get(roleId) == null) continue; for (AuthorizeEntity t : allAuthMap.get(roleId)) { if (AuthorizeConst.SYSTEM.equals(t.getItemType()) && !systemSave.contains(t.getItemId())) systemSave.add(t.getItemId()); if (AuthorizeConst.MODULE.equals(t.getItemType()) && !moduleSave.contains(t.getItemId())) moduleSave.add(t.getItemId()); if (AuthorizeConst.BUTTON.equals(t.getItemType()) && !buttonSave.contains(t.getItemId())) buttonSave.add(t.getItemId()); if (AuthorizeConst.COLUMN.equals(t.getItemType()) && !columnSave.contains(t.getItemId())) columnSave.add(t.getItemId()); if (AuthorizeConst.RESOURCE.equals(t.getItemType()) && !resourceSave.contains(t.getItemId())) resourceSave.add(t.getItemId()); if (AuthorizeConst.FROM.equals(t.getItemType()) && !formSave.contains(t.getItemId())) formSave.add(t.getItemId()); } } //移除子组织权限 List orgList = allOrgList.stream().filter(t -> objectId.equals(t.getParentId())).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(orgList)) { for (OrganizeEntity entity : orgList) { //获取需要删除的权限关联数据id List authorizeEntities = allAuthMap.get(entity.getId()) == null ? Collections.EMPTY_LIST : allAuthMap.get(entity.getId()); List delIds = authorizeEntities.stream().filter(t -> (AuthorizeConst.SYSTEM.equals(t.getItemType()) && !systemSave.contains(t.getItemId())) || (AuthorizeConst.MODULE.equals(t.getItemType()) && !moduleSave.contains(t.getItemId())) || (AuthorizeConst.BUTTON.equals(t.getItemType()) && !buttonSave.contains(t.getItemId())) || (AuthorizeConst.COLUMN.equals(t.getItemType()) && !columnSave.contains(t.getItemId())) || (AuthorizeConst.RESOURCE.equals(t.getItemType()) && !resourceSave.contains(t.getItemId())) || (AuthorizeConst.FROM.equals(t.getItemType()) && !formSave.contains(t.getItemId()))).map(AuthorizeEntity::getId).collect(Collectors.toList()); listRes.addAll(delIds); //递归子数据删除 List deleteAllAuth = AuthPermUtil.getDelAllAuth(AuthorizeSaveParam .builder().objectId(entity.getId()).objectType(PermissionConst.ORGANIZE).allOrgList(allOrgList).allPosList(allPosList).allAuthMap(allAuthMap) .roleRealationList(roleRealationList) .systemSave(authorizeEntities.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType()) && systemSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .moduleSave(authorizeEntities.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType()) && moduleSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .buttonSave(authorizeEntities.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType()) && buttonSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .columnSave(authorizeEntities.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType()) && columnSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .resourceSave(authorizeEntities.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType()) && resourceSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .formSave(authorizeEntities.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType()) && formSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .build()); listRes.addAll(deleteAllAuth); } } //移除改组织下岗位的权限 List posList = allPosList.stream().filter(t -> objectId.equals(t.getOrganizeId()) && StringUtil.isEmpty(t.getParentId())).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(posList)) { for (PositionEntity entity : posList) { //获取需要删除的权限关联数据id List authorizeEntities = allAuthMap.get(entity.getId()) == null ? Collections.EMPTY_LIST : allAuthMap.get(entity.getId()); List delIds = authorizeEntities.stream().filter(t -> (AuthorizeConst.SYSTEM.equals(t.getItemType()) && !systemSave.contains(t.getItemId())) || (AuthorizeConst.MODULE.equals(t.getItemType()) && !moduleSave.contains(t.getItemId())) || (AuthorizeConst.BUTTON.equals(t.getItemType()) && !buttonSave.contains(t.getItemId())) || (AuthorizeConst.COLUMN.equals(t.getItemType()) && !columnSave.contains(t.getItemId())) || (AuthorizeConst.RESOURCE.equals(t.getItemType()) && !resourceSave.contains(t.getItemId())) || (AuthorizeConst.FROM.equals(t.getItemType()) && !formSave.contains(t.getItemId()))).map(AuthorizeEntity::getId).collect(Collectors.toList()); listRes.addAll(delIds); List deleteAllAuth = AuthPermUtil.getDelAllAuth(AuthorizeSaveParam .builder().objectId(entity.getId()).objectType(PermissionConst.POSITION).allOrgList(allOrgList).allPosList(allPosList).allAuthMap(allAuthMap) .roleRealationList(roleRealationList) .systemSave(authorizeEntities.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType()) && systemSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .moduleSave(authorizeEntities.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType()) && moduleSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .buttonSave(authorizeEntities.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType()) && buttonSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .columnSave(authorizeEntities.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType()) && columnSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .resourceSave(authorizeEntities.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType()) && resourceSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .formSave(authorizeEntities.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType()) && formSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .build()); listRes.addAll(deleteAllAuth); } } } } if (PermissionConst.POSITION.equals(objectType)) { PositionEntity positionEntity = allPosList.stream().filter(t -> objectId.equals(t.getId())).findFirst().orElse(null); if (positionEntity != null) { List roleIds = roleRealationList.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType()) && objectId.equals(t.getObjectId())).map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); //本级角色拥有的下级不删除 for (String roleId : roleIds) { if (allAuthMap.get(roleId) == null) continue; for (AuthorizeEntity t : allAuthMap.get(roleId)) { if (AuthorizeConst.SYSTEM.equals(t.getItemType()) && !systemSave.contains(t.getItemId())) systemSave.add(t.getItemId()); if (AuthorizeConst.MODULE.equals(t.getItemType()) && !moduleSave.contains(t.getItemId())) moduleSave.add(t.getItemId()); if (AuthorizeConst.BUTTON.equals(t.getItemType()) && !buttonSave.contains(t.getItemId())) buttonSave.add(t.getItemId()); if (AuthorizeConst.COLUMN.equals(t.getItemType()) && !columnSave.contains(t.getItemId())) columnSave.add(t.getItemId()); if (AuthorizeConst.RESOURCE.equals(t.getItemType()) && !resourceSave.contains(t.getItemId())) resourceSave.add(t.getItemId()); if (AuthorizeConst.FROM.equals(t.getItemType()) && !formSave.contains(t.getItemId())) formSave.add(t.getItemId()); } } //移除下级岗位的权限 List posList = allPosList.stream().filter(t -> objectId.equals(t.getParentId())).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(posList)) { for (PositionEntity entity : posList) { //获取需要删除的权限关联数据id List authorizeEntities = allAuthMap.get(entity.getId()) == null ? Collections.EMPTY_LIST : allAuthMap.get(entity.getId()); List delIds = authorizeEntities.stream().filter(t -> (AuthorizeConst.SYSTEM.equals(t.getItemType()) && !systemSave.contains(t.getItemId())) || (AuthorizeConst.MODULE.equals(t.getItemType()) && !moduleSave.contains(t.getItemId())) || (AuthorizeConst.BUTTON.equals(t.getItemType()) && !buttonSave.contains(t.getItemId())) || (AuthorizeConst.COLUMN.equals(t.getItemType()) && !columnSave.contains(t.getItemId())) || (AuthorizeConst.RESOURCE.equals(t.getItemType()) && !resourceSave.contains(t.getItemId())) || (AuthorizeConst.FROM.equals(t.getItemType()) && !formSave.contains(t.getItemId()))).map(AuthorizeEntity::getId).collect(Collectors.toList()); listRes.addAll(delIds); List deleteAllAuth = AuthPermUtil.getDelAllAuth(AuthorizeSaveParam .builder().objectId(entity.getId()).objectType(PermissionConst.POSITION).allOrgList(allOrgList).allPosList(allPosList).allAuthMap(allAuthMap) .roleRealationList(roleRealationList) .systemSave(authorizeEntities.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType()) && systemSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .moduleSave(authorizeEntities.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType()) && moduleSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .buttonSave(authorizeEntities.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType()) && buttonSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .columnSave(authorizeEntities.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType()) && columnSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .resourceSave(authorizeEntities.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType()) && resourceSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .formSave(authorizeEntities.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType()) && formSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .build()); listRes.addAll(deleteAllAuth); } } } } if (PermissionConst.ROLE.equals(objectType)) { List rList = roleRealationList.stream().filter(t -> t.getRoleId().equals(objectId)).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(rList)) { for (RoleRelationEntity item : rList) { if (PermissionConst.ORGANIZE.equals(item.getObjectType())) { OrganizeEntity organizeEntity = allOrgList.stream().filter(t -> item.getObjectId().equals(t.getId())).findFirst().orElse(null); if (organizeEntity != null) { List authorizeEntities = allAuthMap.get(organizeEntity.getId()) == null ? Collections.EMPTY_LIST : allAuthMap.get(organizeEntity.getId()); //当前不移除,移除子组织的相关权限 List deleteAllAuth = AuthPermUtil.getDelAllAuth(AuthorizeSaveParam .builder().objectId(organizeEntity.getId()).objectType(PermissionConst.ORGANIZE).allOrgList(allOrgList).allPosList(allPosList).allAuthMap(allAuthMap) .roleRealationList(roleRealationList) .systemSave(authorizeEntities.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType()) && systemSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .moduleSave(authorizeEntities.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType()) && moduleSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .buttonSave(authorizeEntities.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType()) && buttonSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .columnSave(authorizeEntities.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType()) && columnSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .resourceSave(authorizeEntities.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType()) && resourceSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .formSave(authorizeEntities.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType()) && formSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .thisRole(objectId) .build()); listRes.addAll(deleteAllAuth); } } else { PositionEntity positionEntity = allPosList.stream().filter(t -> item.getObjectId().equals(t.getId())).findFirst().orElse(null); if (positionEntity != null) { List authorizeEntities = allAuthMap.get(positionEntity.getId()) == null ? Collections.EMPTY_LIST : allAuthMap.get(positionEntity.getId()); //当前不移除,移除子岗位的相关权限 List deleteAllAuth = AuthPermUtil.getDelAllAuth(AuthorizeSaveParam .builder().objectId(positionEntity.getId()).objectType(PermissionConst.ORGANIZE).allOrgList(allOrgList).allPosList(allPosList).allAuthMap(allAuthMap) .roleRealationList(roleRealationList) .systemSave(authorizeEntities.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType()) && systemSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .moduleSave(authorizeEntities.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType()) && moduleSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .buttonSave(authorizeEntities.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType()) && buttonSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .columnSave(authorizeEntities.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType()) && columnSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .resourceSave(authorizeEntities.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType()) && resourceSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .formSave(authorizeEntities.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType()) && formSave.contains(t.getItemId())) .map(AuthorizeEntity::getItemId).collect(Collectors.toList())) .thisRole(objectId) .build()); listRes.addAll(deleteAllAuth); } } } } } return listRes; } /** * 个人权限 * * @return */ public UserAuthorizeVO getUserAuth(UserAuthForm param) { String userId = param.getUserId(); if (StringUtil.isEmpty(param.getUserId())) { userId = UserProvider.getUser().getUserId(); } UserEntity info = userService.getInfo(userId); if (info == null) return new UserAuthorizeVO(); boolean isAdmin = Objects.equals(info.getIsAdministrator(), 1); boolean filter = isAdmin; List list; if (PermissionConst.POSITION.equals(param.getObjectType()) || PermissionConst.ROLE.equals(param.getObjectType())) { list = authorizeService.getListByPosOrRoleId(param.getObjectId(), param.getObjectType()); filter = false; } else { list = authorizeService.getListByUserId(false, userId, false); } List systemAuthList = list.stream().filter(t -> AuthorizeConst.SYSTEM.equals(t.getItemType())).collect(Collectors.toList()); List moduleAuthList = list.stream().filter(t -> AuthorizeConst.MODULE.equals(t.getItemType())).collect(Collectors.toList()); List buttonAuthList = list.stream().filter(t -> AuthorizeConst.BUTTON.equals(t.getItemType())).collect(Collectors.toList()); List columnAuthList = list.stream().filter(t -> AuthorizeConst.COLUMN.equals(t.getItemType())).collect(Collectors.toList()); List formAuthList = list.stream().filter(t -> AuthorizeConst.FROM.equals(t.getItemType())).collect(Collectors.toList()); List dataAuthList = list.stream().filter(t -> AuthorizeConst.RESOURCE.equals(t.getItemType())).collect(Collectors.toList()); List flowAuthList = list.stream().filter(t -> AuthorizeConst.FLOW.equals(t.getItemType())).collect(Collectors.toList()); List printAuthList = list.stream().filter(t -> AuthorizeConst.PRINT.equals(t.getItemType())).collect(Collectors.toList()); List systemIds = systemAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List moduleIds = moduleAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List buttonIds = buttonAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List columnIds = columnAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List formIds = formAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List dataIds = dataAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List flowIds = flowAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List printIds = printAuthList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList()); List systemList = filter ? systemApi.getList() : systemApi.getListByIds(systemIds, new ArrayList<>()); List sysModelList = new ArrayList<>(); Set mainSys = new HashSet<>(); for (SystemEntity s : systemList) { AuthorizeModel authorizeModel; if (Objects.equals(s.getIsMain(), 1)) { authorizeModel = new AuthorizeModel(); authorizeModel.setId(CodeConst.XTCD); authorizeModel.setFullName("系统菜单"); authorizeModel.setParentId("-1"); authorizeModel.setSortCode(0l); mainSys.add(s.getId()); } else { authorizeModel = JsonUtil.getJsonToBean(s, AuthorizeModel.class); AuthorizeModel web = new AuthorizeModel(); web.setId(authorizeModel.getId() + "2"); web.setFullName("WEB菜单"); web.setParentId(authorizeModel.getId()); web.setSortCode(0l); AuthorizeModel app = new AuthorizeModel(); app.setId(authorizeModel.getId() + "1"); app.setFullName("APP菜单"); app.setParentId(authorizeModel.getId()); app.setSortCode(0l); sysModelList.add(web); sysModelList.add(app); } sysModelList.add(authorizeModel); } List moduleList = filter ? moduleApi.getList() : moduleApi.getModuleByIds(moduleIds); List appComModule = new ArrayList<>(); appComModule.addAll(JnpfConst.APP_CONFIG_MODULE); appComModule.addAll(JnpfConst.ONLINE_DEV_MODULE); //移除固定菜单 moduleList = moduleList.stream().filter(t -> !appComModule.contains(t.getEnCode())).collect(Collectors.toList()); for (ModuleEntity me : moduleList) { if (StringUtil.isEmpty(me.getParentId()) || "-1".equals(me.getParentId())) { if (mainSys.contains(me.getSystemId())) { me.setParentId(CodeConst.XTCD); } else { if (JnpfConst.WEB.equals(me.getCategory())) { me.setParentId(me.getSystemId() + "2"); } else { me.setParentId(me.getSystemId() + "1"); } } } } List moduleAuth = JsonUtil.getJsonToList(moduleList, AuthorizeModel.class); //获取菜单 if (isAdmin) { moduleIds = adminGetAuth(moduleList, null, mainSys); } List module = getEachAuth(sysModelList, moduleAuth, moduleIds); List sysAndModule = new ArrayList<>(); sysAndModule.addAll(sysModelList); sysAndModule.addAll(moduleAuth); //获取按钮 List buttonEntityList = filter ? buttonApi.getList() : buttonApi.getListByIds(buttonIds); List buttonAuth = new ArrayList<>(); for (ModuleButtonEntity item : buttonEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getModuleId()); buttonAuth.add(auth); } if (isAdmin) { List collect = buttonEntityList.stream().map(ModuleButtonEntity::getModuleId).collect(Collectors.toList()); buttonIds = adminGetAuth(moduleList, collect, mainSys); } List button = getEachAuth(sysAndModule, buttonAuth, buttonIds); //获取列表 List columnEntityList = filter ? columnApi.getList() : columnApi.getListByIds(columnIds); List columnAuth = new ArrayList<>(); for (ModuleColumnEntity item : columnEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getModuleId()); columnAuth.add(auth); } if (isAdmin) { List collect = columnEntityList.stream().map(ModuleColumnEntity::getModuleId).collect(Collectors.toList()); columnIds = adminGetAuth(moduleList, collect, mainSys); } List column = getEachAuth(sysAndModule, columnAuth, columnIds); //获取表单 List formEntityList = filter ? formApi.getList() : formApi.getListByIds(formIds); List formAuth = new ArrayList<>(); for (ModuleFormEntity item : formEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getModuleId()); formAuth.add(auth); } if (isAdmin) { List collect = formEntityList.stream().map(ModuleFormEntity::getModuleId).collect(Collectors.toList()); formIds = adminGetAuth(moduleList, collect, mainSys); } List form = getEachAuth(sysAndModule, formAuth, formIds); //获取数据权限 List dataEntityList = filter ? schemeApi.getList() : schemeApi.getListByIds(dataIds); List dataAuth = new ArrayList<>(); for (ModuleDataAuthorizeSchemeEntity item : dataEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getModuleId()); dataAuth.add(auth); } if (isAdmin) { List collect = dataEntityList.stream().map(ModuleDataAuthorizeSchemeEntity::getModuleId).collect(Collectors.toList()); dataIds = adminGetAuth(moduleList, collect, mainSys); } List dataScheme = getEachAuth(sysAndModule, dataAuth, dataIds); //全部应用 List systemAll = systemApi.getList(); List systemAuthAll = JsonUtil.getJsonToList(systemAll, AuthorizeModel.class); //获取流程权限 if (isAdmin) { List treeList = templateApi.treeListWithPower(); List idAll = new ArrayList<>(); idList(treeList, idAll); flowIds = idAll; } List flowEntityList = templateApi.getListByFlowIds(flowIds); List flowAuth = new ArrayList<>(); List flowIdsAdmin = new ArrayList<>(); for (TemplateEntity item : flowEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getSystemId()); flowAuth.add(auth); flowIdsAdmin.add(item.getId()); flowIdsAdmin.add(item.getSystemId()); } if (isAdmin) { flowIds = flowIdsAdmin; } List flow = getEachAuth(systemAuthAll, flowAuth, flowIds); //获取打印权限 PaginationPrint paginationPrint = new PaginationPrint(); paginationPrint.setDataType(1); paginationPrint.setVisibleType(2); List printEntityList = filter ? printDevApi.getWorkSelector(paginationPrint) : printDevApi.getListByIds(printIds); List printAuth = new ArrayList<>(); List printIdsAdmin = new ArrayList<>(); for (PrintDevEntity item : printEntityList) { AuthorizeModel auth = JsonUtil.getJsonToBean(item, AuthorizeModel.class); auth.setParentId(item.getSystemId()); printAuth.add(auth); printIdsAdmin.add(item.getId()); printIdsAdmin.add(item.getSystemId()); } if (isAdmin) { printIds = printIdsAdmin; } List print = getEachAuth(systemAuthAll, printAuth, printIds); UserAuthorizeVO vo = UserAuthorizeVO.builder() .module(module) .button(button) .column(column) .form(form) .resource(dataScheme) .flow(flow) .print(print) .build(); return vo; } private static List getEachAuth(List sysModelList, List moduleAuth, List moduleIds) { List allAuth = new ArrayList<>(); for (AuthorizeModel authorizeModel : sysModelList) { if (moduleIds.contains(authorizeModel.getId())) { allAuth.add(authorizeModel); } } allAuth.addAll(moduleAuth); List> trees = TreeDotUtils.convertListToTreeDot(allAuth); List module = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class); module = module.stream().filter(t -> CollectionUtil.isNotEmpty(t.getChildren())).collect(Collectors.toList()); return module; } private void idList(List list, List idAll) { for (TemplateTreeListVo vo : list) { idAll.add(vo.getId()); vo.setDisabled(false); if (vo.getChildren() != null) { idList(vo.getChildren(), idAll); } } } private static List adminGetAuth(List moduleList, List moduleIds, Set mainSys) { Set auth = new HashSet<>(); List moduleListResult; if (moduleIds != null) { List finalModuleList = new ArrayList<>(); //递归获取父级菜单 getParent(moduleList, moduleIds, finalModuleList); //有权限的菜单 finalModuleList.addAll(moduleIds); moduleListResult = moduleList.stream().filter(t -> finalModuleList.contains(t.getId())).collect(Collectors.toList()); } else { moduleListResult = moduleList; } for (ModuleEntity item : moduleListResult) { auth.add(item.getId()); if (mainSys.contains(item.getSystemId())) { auth.add(CodeConst.XTCD); } else { auth.add(item.getSystemId()); if (JnpfConst.WEB.equals(item.getCategory())) { auth.add(item.getSystemId() + "2"); } else { auth.add(item.getSystemId() + "1"); } } } return new ArrayList<>(auth); } /** * 递归获取父级菜单 * * @param list * @param child * @param parent */ private static void getParent(List list, List child, List parent) { List childList = list.stream().filter(t -> child.contains(t.getId())).collect(Collectors.toList()); List parenIds = childList.stream().map(ModuleEntity::getParentId).collect(Collectors.toList()); List parentList = list.stream().filter(t -> parenIds.contains(t.getId())).collect(Collectors.toList()); List newParent = parentList.stream().map(ModuleEntity::getId).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(parentList)) { parent.addAll(newParent); getParent(list, newParent, parent); } } }