From 9c575cb77c2ee357ebef3e4255100d7a608057d5 Mon Sep 17 00:00:00 2001 From: guoxin <371864209@qq.com> Date: Sun, 17 Sep 2023 03:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9F=A5=E8=AF=A2=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=B5=84=E6=BA=90=E6=97=B6=EF=BC=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=B8=8D=E5=8C=85=E5=90=AB=E8=BD=AF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E4=B8=8B=E7=9A=84=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MetadataCommonController.java | 14 ++---- .../bianmu/service/DirectoryTreeService.java | 47 ++++++++++--------- 2 files changed, 29 insertions(+), 32 deletions(-) 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 {