修复分组搜索Bug

pull/22/head
rays 2021-06-21 11:46:00 +08:00
parent e5f731c484
commit b14d646352
2 changed files with 35 additions and 5 deletions

View File

@ -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
<if test="paramCondition.groupName != null and paramCondition.groupName != ''">
AND ar.api_alias LIKE CONCAT('%', #{paramCondition.groupName}, '%')
AND (
ar.api_alias LIKE CONCAT('%', #{paramCondition.groupName}, '%')
OR sr.url LIKE CONCAT('%', #{paramCondition.groupName}, '%')
)
</if>
<if test="paramCondition.groupId != null">
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}
)
</if>
OR ag.group_pid = -1
GROUP BY ag.group_id
</select>
</mapper>

View File

@ -182,6 +182,9 @@ public class ApiGroupServiceImpl extends ServiceImpl<ApiGroupMapper, ApiGroup> i
stringSysResourceMap.put(sysResource.getResourceCode(), sysResource);
}
// 所有非空分组
Map<Long, Integer> notNullGroup = new HashMap<>();
// 查询所有分组
List<ApiGroup> apiGroups = this.dataList(apiGroupRequest);
if (ObjectUtil.isNotEmpty(apiGroups)) {
@ -202,6 +205,15 @@ public class ApiGroupServiceImpl extends ServiceImpl<ApiGroupMapper, ApiGroup> i
List<ApiResource> 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<ApiGroupMapper, ApiGroup> i
allApiGroupTreeWrapperList.add(item);
}
}
// 删除空分组
Iterator<ApiGroupTreeWrapper> 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;
}