Commit 7ac47779 authored by zhangfeng's avatar zhangfeng

仓库树状列表获取优化

parent 3d4559a6
......@@ -37,6 +37,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
......@@ -450,42 +451,41 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override
public List<WarehouseTreeRegionSimpleVO> getWarehouseTreeRegionListSimple() {
List<WarehouseTreeRegionVO> listIn = warehouseService.getWarehouseTreeRegionList(1);
List<WarehouseTreeRegionVO> listOut = warehouseService.getWarehouseTreeRegionList(2);
List<WarehouseTreeRegionVO> list = ListUtils.sum(listIn, listOut);
ArrayList<WarehouseTreeRegionSimpleVO> warehouseTreeRegionSimpleVOS = new ArrayList<>();
for (WarehouseTreeRegionVO warehouseTreeRegionVO : list) {
WarehouseTreeRegionSimpleVO warehouseTreeRegionSimpleVO = new WarehouseTreeRegionSimpleVO();
warehouseTreeRegionSimpleVO.setId(warehouseTreeRegionVO.getGuojia());
warehouseTreeRegionSimpleVO.setLabelZh(warehouseTreeRegionVO.getGuojiaName().replaceAll("\t", ""));
warehouseTreeRegionSimpleVO.setLabelEn(warehouseTreeRegionVO.getChildren().get(0).getGuojiaNameEn());
ArrayList<WarehouseTreeRegionSimpleVO.WarehouseCity> warehouseCitiesSimple = new ArrayList<>();
for (WarehouseTreeRegionVO warehouseTreeRegionVOChild : warehouseTreeRegionVO.getChildren()) {
WarehouseTreeRegionSimpleVO.WarehouseCity warehouseCity = new WarehouseTreeRegionSimpleVO.WarehouseCity();
warehouseCity.setId(warehouseTreeRegionVOChild.getShi());
warehouseCity.setLabelZh(warehouseTreeRegionVOChild.getShiName().replaceAll("\t", ""));
warehouseCity.setLabelEn(warehouseTreeRegionVOChild.getShiNameEn());
if (warehouseCitiesSimple.contains(warehouseCity)) {
WarehouseTreeRegionSimpleVO.Warehouse warehouse = new WarehouseTreeRegionSimpleVO.Warehouse();
warehouse.setId(warehouseTreeRegionVOChild.getId());
warehouse.setLabelZh(warehouseTreeRegionVOChild.getTitleZh());
warehouse.setLabelEn(warehouseTreeRegionVOChild.getTitleEn());
warehouseCitiesSimple.get(warehouseCitiesSimple.indexOf(warehouseCity)).getChildren().add(warehouse);
continue;
}
ArrayList<WarehouseTreeRegionSimpleVO.Warehouse> warehouseSimples = new ArrayList<>();
WarehouseTreeRegionSimpleVO.Warehouse warehouse = new WarehouseTreeRegionSimpleVO.Warehouse();
warehouse.setId(warehouseTreeRegionVOChild.getId());
warehouse.setLabelZh(warehouseTreeRegionVOChild.getTitleZh().replaceAll("\t", ""));
warehouse.setLabelEn(warehouseTreeRegionVOChild.getTitleEn());
warehouseSimples.add(warehouse);
warehouseCity.setChildren(warehouseSimples);
warehouseCitiesSimple.add(warehouseCity);
}
warehouseTreeRegionSimpleVO.setChildren(warehouseCitiesSimple);
warehouseTreeRegionSimpleVOS.add(warehouseTreeRegionSimpleVO);
List<WarehouseTreeRegionVO> list = ListUtils.sum(
warehouseService.getWarehouseTreeRegionList(1),
warehouseService.getWarehouseTreeRegionList(2)
);
return list.stream().map(this::convertToSimpleVO).collect(Collectors.toList());
}
private WarehouseTreeRegionSimpleVO convertToSimpleVO(WarehouseTreeRegionVO regionVO) {
WarehouseTreeRegionSimpleVO simpleVO = new WarehouseTreeRegionSimpleVO();
simpleVO.setId(regionVO.getGuojia());
simpleVO.setLabelZh(regionVO.getGuojiaName().trim());
simpleVO.setLabelEn(regionVO.getChildren().isEmpty() ? "" : regionVO.getChildren().get(0).getGuojiaNameEn());
// 构建城市和仓库的树状结构
Map<Long, WarehouseTreeRegionSimpleVO.WarehouseCity> cityMap = new LinkedHashMap<>();
for (WarehouseTreeRegionVO child : regionVO.getChildren()) {
WarehouseTreeRegionSimpleVO.WarehouseCity city = cityMap
.computeIfAbsent(child.getShi(), key -> {
WarehouseTreeRegionSimpleVO.WarehouseCity newCity = new WarehouseTreeRegionSimpleVO.WarehouseCity();
newCity.setId(child.getShi());
newCity.setLabelZh(child.getShiName().trim());
newCity.setLabelEn(child.getShiNameEn());
newCity.setChildren(new ArrayList<>());
return newCity;
});
WarehouseTreeRegionSimpleVO.Warehouse warehouse = new WarehouseTreeRegionSimpleVO.Warehouse();
warehouse.setId(child.getId());
warehouse.setLabelZh(child.getTitleZh().trim());
warehouse.setLabelEn(child.getTitleEn());
city.getChildren().add(warehouse);
}
return warehouseTreeRegionSimpleVOS;
simpleVO.setChildren(new ArrayList<>(cityMap.values()));
return simpleVO;
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment