Browse Source

新增门类类型菜单

master
刘力 3 years ago
parent
commit
6f15e09673
  1. 8
      archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
  2. 28
      archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/ArchivesTypeVo.java
  3. 13
      archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesTypeService.java
  4. 3
      archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java
  5. 29
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java

8
archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java

@ -44,6 +44,7 @@ public class ArchivesTypeController {
@ApiOperation("创建门类")
@AnonymousPostMapping("create")
//TODO:权限未添加
public ApiResponse<Object> 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<Object> getMenuTree(){
return ApiResponse.success(archivesTypeService.buildTree());
}
}

28
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;
}

13
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<ArchivesTypeDTO> buildTree();
}

3
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<ArchivesTypeDTO> children;
private String cnName;
private String enName;

29
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<ArchivesTypeDTO> buildTree() {
List<ArchivesType> arcList = archivesTypeRepository.findAll();
List<ArchivesTypeDTO> archivesTypeDTOS = archivesTypeMapper.toDto(arcList);
List<ArchivesTypeDTO> trees = new ArrayList<>();
Set<String> 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;
}
}
Loading…
Cancel
Save