Commit 7ac47779 authored by zhangfeng's avatar zhangfeng

仓库树状列表获取优化

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