解决查询目录资源时,查询结果不包含软连接下的数据的问题

master
guoxin 1 year ago
parent 4e9aa4aab8
commit 9c575cb77c
  1. 14
      shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java
  2. 45
      shandan-system/src/main/java/com/keyware/shandan/bianmu/service/DirectoryTreeService.java

@ -17,6 +17,7 @@ import com.keyware.shandan.system.constants.FormTypeEnum;
import com.keyware.shandan.system.entity.SysFormConfig; import com.keyware.shandan.system.entity.SysFormConfig;
import com.keyware.shandan.system.service.SysFormConfigService; import com.keyware.shandan.system.service.SysFormConfigService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -119,22 +120,13 @@ public class MetadataCommonController {
* @return * @return
*/ */
@GetMapping("/list/directory") @GetMapping("/list/directory")
@Transactional(readOnly = true)
public Result<Page<DirectoryResource>> listByDirectory(Page<DirectoryResource> page, String directoryId, String resourceName, boolean allChild) { public Result<Page<DirectoryResource>> listByDirectory(Page<DirectoryResource> page, String directoryId, String resourceName, boolean allChild) {
if (StringUtils.isBlank(directoryId)) { if (StringUtils.isBlank(directoryId)) {
return Result.of(null, false, "参数不能为空"); return Result.of(null, false, "参数不能为空");
} }
DirectoryVo parent = directoryService.getById(directoryId);
DirectoryResource param = new DirectoryResource();
if (allChild) {
param.setDirectoryPath(parent.getDirectoryPath() + "/");
} else {
param.setDirectoryId(directoryId);
}
if (StringUtils.hasText(resourceName)) {
param.setResourceName(resourceName);
}
Page<DirectoryResource> result = treeService.directoryResourcePage(page, param); Page<DirectoryResource> result = treeService.resourcePage(page, directoryId, resourceName, allChild);
StreamUtil.as(result.getRecords()).peek(item -> { StreamUtil.as(result.getRecords()).peek(item -> {
if (StringUtils.hasText(item.getDirectoryPath())) { if (StringUtils.hasText(item.getDirectoryPath())) {
int i = item.getDirectoryPath().lastIndexOf("/"); int i = item.getDirectoryPath().lastIndexOf("/");

@ -143,32 +143,37 @@ public class DirectoryTreeService {
return directoryService.list(wrapper); return directoryService.list(wrapper);
} }
public Page<DirectoryResource> directoryResourcePage(Page<DirectoryResource> page, DirectoryResource directoryResource) { public Page<DirectoryResource> resourcePage(Page<DirectoryResource> page, String parentId, String text, boolean all) {
QueryWrapper<DirectoryResource> wrapper = new QueryWrapper<>(directoryResource); DirectoryVo parent = directoryService.getById(parentId);
HashSet<DirectoryVo> allDir = new HashSet<>();
if (all) {
allDirectoryByParent(parent, allDir);
} else {
allDir.addAll(directoryService.childrenListByParent(parentId));
}
Set<String> allowDirIds = dirPermissionService.getByReadPermis(SecurityUtil.getLoginSysUser()); Set<String> allowDirIds = dirPermissionService.getByReadPermis(SecurityUtil.getLoginSysUser());
// Set<String> dirIds = allDir.stream().map(DirectoryVo::getId).filter(allowDirIds::contains).collect(Collectors.toSet());
if (StringUtils.hasText(directoryResource.getResourceName())) { dirIds.add(parentId);
wrapper.and(queryWrapper -> { QueryWrapper<DirectoryResource> query = new QueryWrapper<>();
query.in("PARENT_ID", dirIds);
if (StringUtils.hasText(text)) {
query.and(queryWrapper -> {
queryWrapper. queryWrapper.
like("RESOURCE_NAME", directoryResource.getResourceName()) like("RESOURCE_NAME", text)
.or() .or()
.like("RESOURCE_COMMENT", directoryResource.getResourceName()); .like("RESOURCE_COMMENT", text);
}); });
directoryResource.setResourceName(null);
}
if (directoryResource.getDirectoryPath() != null) {
String path = directoryResource.getDirectoryPath();
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
} }
DirectoryVo parent = directoryService.getByPath(path); return directoryResourceMapper.selectPage(page, query);
List<DirectoryVo> dirList = directoryService.childrenLists(parent);
HashSet<String> ids = (HashSet<String>) dirList.stream().filter(child -> allowDirIds.contains(child.getId())).map(DirectoryVo::getId).collect(Collectors.toSet());
ids.add(parent.getId());
wrapper.in("PARENT_ID", ids);
directoryResource.setDirectoryPath(null);
} }
return directoryResourceMapper.selectPage(page, wrapper);
private void allDirectoryByParent(DirectoryVo parent, HashSet<DirectoryVo> result) {
String parentId = DirectoryType.LINK_DIR == parent.getDirectoryType() ? parent.getResourceId() : parent.getId();
List<DirectoryVo> children = directoryService.childrenListByParent(parentId);
children.forEach(dir -> {
result.add(dir);
allDirectoryByParent(dir, result);
});
} }
private static class DirectoryParentBuilder { private static class DirectoryParentBuilder {