|
@ -41,6 +41,10 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { |
|
|
List<ArchivesType> archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); |
|
|
List<ArchivesType> archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); |
|
|
if (archivesType1.size() == 0) { |
|
|
if (archivesType1.size() == 0) { |
|
|
tableName += DateUtils.getNowDateTime(); |
|
|
tableName += DateUtils.getNowDateTime(); |
|
|
|
|
|
if (archivesType.getPid() == null) { |
|
|
|
|
|
archivesType.setPid("0"); |
|
|
|
|
|
} |
|
|
|
|
|
archivesType.setPid("0"); |
|
|
archivesType.setId(NanoIdUtils.randomNanoId()); |
|
|
archivesType.setId(NanoIdUtils.randomNanoId()); |
|
|
archivesType.setEnName(tableName); |
|
|
archivesType.setEnName(tableName); |
|
|
archivesTypeRepository.save(archivesType); |
|
|
archivesTypeRepository.save(archivesType); |
|
@ -51,36 +55,53 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @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) { |
|
|
|
|
|
// //如果父节点id为空就是一级菜单 |
|
|
|
|
|
// 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 (archivesTypeDTO.getChildren() != null && archivesTypeDTO.getCategorySeq() != null) { |
|
|
|
|
|
// archivesTypeDTO.getChildren().sort(Comparator.reverseOrder()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (trees.size() == 0) { |
|
|
|
|
|
// trees = archivesTypeDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList()); |
|
|
|
|
|
// } |
|
|
|
|
|
// trees.sort(Comparator.reverseOrder()); |
|
|
|
|
|
// return trees; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
@Override |
|
|
@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) { |
|
|
|
|
|
//如果父节点id为空就是一级菜单 |
|
|
|
|
|
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 (archivesTypeDTO.getChildren() != null && archivesTypeDTO.getCategorySeq() != null) { |
|
|
|
|
|
archivesTypeDTO.getChildren().sort(Comparator.reverseOrder()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (trees.size() == 0) { |
|
|
|
|
|
trees = archivesTypeDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList()); |
|
|
|
|
|
} |
|
|
|
|
|
trees.sort(Comparator.reverseOrder()); |
|
|
|
|
|
return trees; |
|
|
|
|
|
|
|
|
public List<ArchivesType> buildTree() { |
|
|
|
|
|
List<ArchivesType> list = archivesTypeRepository.findAll(); |
|
|
|
|
|
|
|
|
|
|
|
return list.stream().filter(item -> item.getPid().equals("0")) |
|
|
|
|
|
.map(item -> item.setChildren(getChildren(item.getId(), list))) |
|
|
|
|
|
.sorted(Comparator.comparingInt(menu -> (menu.getCategorySeq() == null ? 0 : menu.getCategorySeq()))) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<ArchivesType> getChildren(String id, List<ArchivesType> list) { |
|
|
|
|
|
return list.stream().filter(item -> item.getPid().equals(id)) |
|
|
|
|
|
.map(item -> item.setChildren(getChildren(item.getId(), list))) |
|
|
|
|
|
.sorted(Comparator.comparingInt(menu -> (menu.getCategorySeq() == null ? 0 : menu.getCategorySeq()))) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|