diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/mapper/mapping/ApiGroupMapper.xml b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/mapper/mapping/ApiGroupMapper.xml index 52d1ce716..86d6d8aad 100644 --- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/mapper/mapping/ApiGroupMapper.xml +++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/mapper/mapping/ApiGroupMapper.xml @@ -27,16 +27,20 @@ LEFT JOIN api_resource ar ON ag.group_id = ar.group_id LEFT JOIN sys_resource sr ON ar.resource_code = sr.resource_code WHERE - 1 = 1 - OR ag.group_pid = -1 + 1=1 - AND ar.api_alias LIKE CONCAT('%', #{paramCondition.groupName}, '%') + AND ( + ar.api_alias LIKE CONCAT('%', #{paramCondition.groupName}, '%') OR sr.url LIKE CONCAT('%', #{paramCondition.groupName}, '%') + ) - AND ag.group_pids NOT LIKE CONCAT('%[', #{paramCondition.groupId}, ']%') - AND ag.group_id != #{paramCondition.groupId} + AND ( + ag.group_pids NOT LIKE CONCAT('%[', #{paramCondition.groupId}, ']%') + AND ag.group_id != #{paramCondition.groupId} + ) + OR ag.group_pid = -1 GROUP BY ag.group_id \ No newline at end of file diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/ApiGroupServiceImpl.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/ApiGroupServiceImpl.java index c6edfd389..502c282c9 100644 --- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/ApiGroupServiceImpl.java +++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/ApiGroupServiceImpl.java @@ -182,6 +182,9 @@ public class ApiGroupServiceImpl extends ServiceImpl i stringSysResourceMap.put(sysResource.getResourceCode(), sysResource); } + // 所有非空分组 + Map notNullGroup = new HashMap<>(); + // 查询所有分组 List apiGroups = this.dataList(apiGroupRequest); if (ObjectUtil.isNotEmpty(apiGroups)) { @@ -202,6 +205,15 @@ public class ApiGroupServiceImpl extends ServiceImpl i List apiResourceList = this.apiResourceService.dataList(apiGroupRequest); if (ObjectUtil.isNotEmpty(apiResourceList)) { for (ApiResource apiResource : apiResourceList) { + // 处理分组信息 + Integer count = notNullGroup.get(apiResource.getGroupId()); + if (ObjectUtil.isEmpty(count)) { + count = 0; + } + count = count + 1; + notNullGroup.put(apiResource.getGroupId(), count); + + // 处理节点信息 ApiGroupTreeWrapper item = new ApiGroupTreeWrapper(); item.setId(apiResource.getApiResourceId()); item.setPid(apiResource.getGroupId()); @@ -217,6 +229,20 @@ public class ApiGroupServiceImpl extends ServiceImpl i allApiGroupTreeWrapperList.add(item); } } + + // 删除空分组 + Iterator iterator = allApiGroupTreeWrapperList.iterator(); + while (iterator.hasNext()) { + ApiGroupTreeWrapper item = iterator.next(); + if (RuleConstants.TREE_ROOT_ID.toString().equals(item.getNodeParentId()) || NodeTypeEnums.DATA_NODE.getType().equals(item.getType())) { + continue; + } else { + Integer integer = notNullGroup.get(item.getId()); + if (ObjectUtil.isEmpty(integer) || integer == 0) { + iterator.remove(); + } + } + } return allApiGroupTreeWrapperList; }