From 13e122a3484144f235a89e72715678463c1dac1b Mon Sep 17 00:00:00 2001 From: wanggongfeng <1305282856@qq.com> Date: Tue, 19 Jul 2022 17:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E8=A3=85=E5=AE=A2=E6=88=B7=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/service/impl/AgencyServiceImpl.java | 69 +++++++++++++++++-- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index 3973150622..9d09ed5526 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -57,6 +57,7 @@ import com.epmet.redis.CustomerAgencyRedis; import com.epmet.service.AgencyService; import com.epmet.service.CustomerAgencyService; import com.epmet.service.CustomerOrgParameterService; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -935,7 +936,7 @@ public class AgencyServiceImpl implements AgencyService { }); treeMap = treeList.stream().collect(Collectors.toMap(CustomerTreeDTO::getAreaCode, Function.identity(), (val1, val2) -> val2)); // 组合成组织树 - rootList = getCustomerTree(treeMap); + rootList = getCustomerTree(treeList); // 回显客户名称 rootList.forEach(item -> { List customerNames = new ArrayList<>(); @@ -1029,10 +1030,68 @@ public class AgencyServiceImpl implements AgencyService { * @author zhy * @date 2022/7/6 13:54 */ - private List getCustomerTree(Map treeMap) { - List tree = new ArrayList<>(); - // todo 组合树形结构 - return tree; + private List getCustomerTree(List treeList) { + treeList = treeList.stream().distinct().collect(Collectors.toList()); + + // 省 + List province = new ArrayList(); + // 市 + List city = new ArrayList(); + // 区 + List district = new ArrayList(); + // 街道 + List street = new ArrayList(); + // 社区 + List community = new ArrayList(); + for(int i = 0 ; i < treeList.size() ; i++){ + if("province".equals(treeList.get(i).getLevel())){ + province.add(treeList.get(i)); + } else if("city".equals(treeList.get(i).getLevel())){ + city.add(treeList.get(i)); + } else if("district".equals(treeList.get(i).getLevel())){ + district.add(treeList.get(i)); + } else if("street".equals(treeList.get(i).getLevel())){ + street.add(treeList.get(i)); + } else if("community".equals(treeList.get(i).getLevel())){ + community.add(treeList.get(i)); + } + } + + // 组装街道树 + for(CustomerTreeDTO streetDto : street){ + this.addChild(streetDto,community); + } + // 组装区树 + for(CustomerTreeDTO districtDto : district){ + this.addChild(districtDto,street); + } + // 组装市树 + for(CustomerTreeDTO cityDto : city){ + this.addChild(cityDto,district); + } + // 组装省树 + for(CustomerTreeDTO provinceDto : province){ + this.addChild(provinceDto,city); + } + + return province; + } + + + /** + * 组装子项 + * @param parentDto + * @param childList + */ + private void addChild(CustomerTreeDTO parentDto,List childList){ + List children = new ArrayList(); + for(CustomerTreeDTO childDto : childList){ + if(parentDto.getAreaCode().equals(childDto.getParentCode())){ + children.add(childDto); + } + } + parentDto.setChildren(children); + } }