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