diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java index c8cf862..e62a345 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java @@ -17,6 +17,7 @@ import com.keyware.shandan.system.constants.FormTypeEnum; import com.keyware.shandan.system.entity.SysFormConfig; import com.keyware.shandan.system.service.SysFormConfigService; 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.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -119,22 +120,13 @@ public class MetadataCommonController { * @return */ @GetMapping("/list/directory") + @Transactional(readOnly = true) public Result> listByDirectory(Page page, String directoryId, String resourceName, boolean allChild) { if (StringUtils.isBlank(directoryId)) { 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 result = treeService.directoryResourcePage(page, param); + Page result = treeService.resourcePage(page, directoryId, resourceName, allChild); StreamUtil.as(result.getRecords()).peek(item -> { if (StringUtils.hasText(item.getDirectoryPath())) { int i = item.getDirectoryPath().lastIndexOf("/"); diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/service/DirectoryTreeService.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/service/DirectoryTreeService.java index 47a642b..7351196 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/service/DirectoryTreeService.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/service/DirectoryTreeService.java @@ -143,32 +143,37 @@ public class DirectoryTreeService { return directoryService.list(wrapper); } - public Page directoryResourcePage(Page page, DirectoryResource directoryResource) { - QueryWrapper wrapper = new QueryWrapper<>(directoryResource); + public Page resourcePage(Page page, String parentId, String text, boolean all) { + DirectoryVo parent = directoryService.getById(parentId); + HashSet allDir = new HashSet<>(); + if (all) { + allDirectoryByParent(parent, allDir); + } else { + allDir.addAll(directoryService.childrenListByParent(parentId)); + } Set allowDirIds = dirPermissionService.getByReadPermis(SecurityUtil.getLoginSysUser()); - // - if (StringUtils.hasText(directoryResource.getResourceName())) { - wrapper.and(queryWrapper -> { + Set dirIds = allDir.stream().map(DirectoryVo::getId).filter(allowDirIds::contains).collect(Collectors.toSet()); + dirIds.add(parentId); + QueryWrapper query = new QueryWrapper<>(); + query.in("PARENT_ID", dirIds); + if (StringUtils.hasText(text)) { + query.and(queryWrapper -> { queryWrapper. - like("RESOURCE_NAME", directoryResource.getResourceName()) + like("RESOURCE_NAME", text) .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); - List dirList = directoryService.childrenLists(parent); - HashSet ids = (HashSet) 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); + return directoryResourceMapper.selectPage(page, query); + } + + private void allDirectoryByParent(DirectoryVo parent, HashSet result) { + String parentId = DirectoryType.LINK_DIR == parent.getDirectoryType() ? parent.getResourceId() : parent.getId(); + List children = directoryService.childrenListByParent(parentId); + children.forEach(dir -> { + result.add(dir); + allDirectoryByParent(dir, result); + }); } private static class DirectoryParentBuilder {