@Override
public Map<String, List<Catalog2Vo>> getCatalogJson() {
List<CategoryEntity> level1Categories = getLevel1Categories();
return level1Categories.stream().collect(Collectors.toMap(k -> k.getCatId().toString(), v -> getCatalog2Vos(v.getCatId())
));
}
private List<Catalog2Vo> getCatalog2Vos(Long level1CatId) {
List<CategoryEntity> level2Categories = baseMapper.selectList(new LambdaQueryWrapper<CategoryEntity>()
.eq(CategoryEntity::getParentCid, level1CatId));
List<Catalog2Vo> catalog2Vos = null;
if (!CollectionUtils.isEmpty(level2Categories)) {
catalog2Vos = level2Categories.stream().map(item -> new Catalog2Vo(level1CatId.toString(), getCatalog3Vos(item.getCatId()), item.getCatId().toString(), item.getName())).collect(Collectors.toList());
}
return catalog2Vos;
}
private List<Catalog2Vo.Catalog3Vo> getCatalog3Vos(Long level2CatId) {
List<Catalog2Vo.Catalog3Vo> catalog3Vos = null;
List<CategoryEntity> level3Categories = baseMapper.selectList(new LambdaQueryWrapper<CategoryEntity>().eq(CategoryEntity::getParentCid, level2CatId));
if (!CollectionUtils.isEmpty(level3Categories)) {
catalog3Vos = level3Categories.stream().map(item -> new Catalog2Vo.Catalog3Vo(level2CatId.toString(), item.getCatId().toString(), item.getName())).collect(Collectors.toList());
}
return catalog3Vos;
}