diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java index 613b7c8..8fb5d6e 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java @@ -44,6 +44,7 @@ public class ArchivesTypeController { @ApiOperation("创建门类") @AnonymousPostMapping("create") + //TODO:权限未添加 public ApiResponse save(@RequestBody ArchivesTypeDTO archivesTypeDTO) { if (!archivesTypeDTO.getId().isEmpty()) { throw new BaseException("this is not empty Data"); @@ -57,4 +58,11 @@ public class ArchivesTypeController { archivesTypeService.create(archivesTypeDTO); return ApiResponse.success("保存成功"); } + + @ApiOperation("获取门类树状菜单") + @AnonymousGetMapping("menuTree") + //TODO:权限未添加 + public ApiResponse getMenuTree(){ + return ApiResponse.success(archivesTypeService.buildTree()); + } } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/ArchivesTypeVo.java b/archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/ArchivesTypeVo.java new file mode 100644 index 0000000..beef557 --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/ArchivesTypeVo.java @@ -0,0 +1,28 @@ +package com.storeroom.modules.dictionary.domain.vo; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.io.Serializable; + +@Data +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class ArchivesTypeVo implements Serializable { + + private String id; + + private String cnName; + + private String enName; + + private String pid; + + private Integer isType; + + private Integer isTypeMetic; + + private Integer categorySeq; + + private String remark; +} diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java index 53f75ed..2627270 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java @@ -1,7 +1,11 @@ package com.storeroom.modules.dictionary.service; + import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; +import java.util.List; + + public interface ArchivesTypeService { @@ -11,4 +15,13 @@ public interface ArchivesTypeService { */ void create(ArchivesTypeDTO archivesTypeDTO); + + /** + * 构建菜单树 + * @return + */ + List buildTree(); + + + } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java index 9394cf7..7e80d6f 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.Setter; import java.io.Serializable; +import java.util.List; import java.util.Objects; @Getter @@ -16,6 +17,8 @@ public class ArchivesTypeDTO extends BaseDTO implements Serializable { private String id; + private List children; + private String cnName; private String enName; diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java index c1d33c6..228c6f0 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java @@ -17,7 +17,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; @Service @@ -48,4 +49,30 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { throw new BaseException("门类名称不能重复"); } } + + @Override + public List buildTree() { + List arcList = archivesTypeRepository.findAll(); + List archivesTypeDTOS = archivesTypeMapper.toDto(arcList); + List trees = new ArrayList<>(); + Set ids = new HashSet<>(); + for (ArchivesTypeDTO archivesTypeDTO : archivesTypeDTOS) { + if (archivesTypeDTO.getPid() == null) { + trees.add(archivesTypeDTO); + } + for (ArchivesTypeDTO at : archivesTypeDTOS) { + if (archivesTypeDTO.getId().equals(at.getPid())) { + if (archivesTypeDTO.getChildren() == null) { + archivesTypeDTO.setChildren(new ArrayList<>()); + } + archivesTypeDTO.getChildren().add(at); + ids.add(at.getId()); + } + } + } + if (trees.size() == 0) { + trees = archivesTypeDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList()); + } + return trees; + } }