Browse Source

行政地区编码查询

dev_shibei_match
zxc 5 years ago
parent
commit
7ac6155b98
  1. 3
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/constant/ScreenConstant.java
  2. 15
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/screen/AgencyController.java
  3. 12
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/AgencyService.java
  4. 25
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java
  5. 20
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/AreaCodeDictFormDTO.java
  6. 43
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/AreaCodeDictResultDTO.java
  7. 20
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
  8. 16
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java
  9. 14
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/constant/AreaCodeConstant.java
  10. 14
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/AreaCodeController.java
  11. 7
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeChildDao.java
  12. 7
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeDao.java
  13. 11
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/redis/AreaCodeRedis.java
  14. 11
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/AreaCodeService.java
  15. 168
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
  16. 3
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeChildDao.xml
  17. 3
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeDao.xml

3
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/constant/ScreenConstant.java

@ -21,4 +21,7 @@ public interface ScreenConstant {
String MONTH_ID = "month";
String YEAR_ID = "year";
String GET_AREA_TREE_FAILURE = "查询行政地区编码树失败......";
}

15
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/screen/AgencyController.java

@ -3,6 +3,8 @@ package com.epmet.datareport.controller.screen;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.datareport.service.evaluationindex.screen.AgencyService;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.evaluationindex.screen.dto.form.CompartmentByBizTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
@ -11,6 +13,8 @@ import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 组织相关api
*
@ -66,4 +70,15 @@ public class AgencyController {
return new Result<CompartmentResultDTO>().ok(agencyService.compartmentByBizType(compartmentFormDTO));
}
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
@PostMapping("areacodedict")
public Result<List<AreaCodeDictResultDTO>> areaCodeDictTree(@RequestBody AreaCodeDictFormDTO formDTO){
return new Result<List<AreaCodeDictResultDTO>>().ok(agencyService.areaCodeDictTree(formDTO));
}
}

12
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/AgencyService.java

@ -1,11 +1,15 @@
package com.epmet.datareport.service.evaluationindex.screen;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.evaluationindex.screen.dto.form.CompartmentByBizTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.result.CompartmentResultDTO;
import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
import java.util.List;
/**
* 组织相关api
*
@ -35,4 +39,12 @@ public interface AgencyService {
CompartmentResultDTO compartmentByBizType(CompartmentByBizTypeFormDTO compartmentFormDTO);
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
List<AreaCodeDictResultDTO> areaCodeDictTree(AreaCodeDictFormDTO formDTO);
}

25
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java

@ -3,10 +3,13 @@ package com.epmet.datareport.service.evaluationindex.screen.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.DataSourceConstant;
import com.epmet.datareport.dao.evaluationindex.screen.ScreenCustomerAgencyDao;
import com.epmet.datareport.dao.evaluationindex.screen.ScreenCustomerGridDao;
import com.epmet.datareport.service.evaluationindex.screen.AgencyService;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.evaluationindex.screen.constant.ScreenConstant;
import com.epmet.evaluationindex.screen.dto.form.CompartmentByBizTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
@ -14,9 +17,11 @@ import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.result.AgencyDistributionResultDTO;
import com.epmet.evaluationindex.screen.dto.result.CompartmentResultDTO;
import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
@ -35,6 +40,8 @@ public class AgencyServiceImpl implements AgencyService {
private ScreenCustomerAgencyDao screenCustomerAgencyDao;
@Autowired
private ScreenCustomerGridDao screenCustomerGridDao;
@Autowired
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
/**
* @Description 1组织机构树
@ -223,4 +230,22 @@ public class AgencyServiceImpl implements AgencyService {
}
return agencyAreaInfo;
}
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
@Override
public List<AreaCodeDictResultDTO> areaCodeDictTree(AreaCodeDictFormDTO formDTO) {
Result<List<AreaCodeDictResultDTO>> listResult = commonServiceOpenFeignClient.areaCodeDictTree(formDTO);
if (!listResult.success()){
throw new RenException(ScreenConstant.GET_AREA_TREE_FAILURE);
}
if (!CollectionUtils.isEmpty(listResult.getData())){
return listResult.getData();
}
return new ArrayList<>();
}
}

20
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/AreaCodeDictFormDTO.java

@ -0,0 +1,20 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/1/7 下午1:26
*/
@Data
public class AreaCodeDictFormDTO implements Serializable {
private static final long serialVersionUID = 5780301376757138238L;
/**
* 根结点code 不传则返回全部
*/
private String rootAreaCode;
}

43
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/AreaCodeDictResultDTO.java

@ -0,0 +1,43 @@
package com.epmet.dto.result;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @Author zxc
* @DateTime 2021/1/7 下午1:32
*/
@Data
public class AreaCodeDictResultDTO implements Serializable {
private static final long serialVersionUID = -1312164785403693464L;
/**
* 编码
*/
private String code;
/**
* 名称
*/
private String name;
/**
* 下一级
*/
private List<AreaCodeDictResultDTO> children;
@JsonIgnore
private String parentCode;
public AreaCodeDictResultDTO() {
this.code = "";
this.name = "";
this.parentCode = "";
this.children = new ArrayList<>();
}
}

20
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java

@ -2,15 +2,8 @@ package com.epmet.feign;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.CostDayFormDTO;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.GetJwtAccessTokenFormDTO;
import com.epmet.dto.form.WorkDayFormDTO;
import com.epmet.dto.result.CostDayResultDTO;
import com.epmet.dto.form.WorkMinuteFormDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.WorkDayResultDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.fallback.EpmetCommonServiceOpenFeignClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
@ -101,4 +94,13 @@ public interface EpmetCommonServiceOpenFeignClient {
*/
@PostMapping("commonservice/workday/workminutes")
Result<Map<String,Integer>> workMinutes(@RequestBody WorkMinuteFormDTO param);
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
@PostMapping("commonservice/areacode/areacodedicttree")
Result<List<AreaCodeDictResultDTO>> areaCodeDictTree(@RequestBody AreaCodeDictFormDTO formDTO);
}

16
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java

@ -3,15 +3,8 @@ package com.epmet.feign.fallback;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.CostDayFormDTO;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.GetJwtAccessTokenFormDTO;
import com.epmet.dto.form.WorkDayFormDTO;
import com.epmet.dto.form.WorkMinuteFormDTO;
import com.epmet.dto.result.CostDayResultDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.WorkDayResultDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import org.springframework.stereotype.Component;
@ -86,4 +79,9 @@ public class EpmetCommonServiceOpenFeignClientFallback implements EpmetCommonSer
public Result<Map<String, Integer>> workMinutes(WorkMinuteFormDTO param) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "workMinutes", param);
}
@Override
public Result<List<AreaCodeDictResultDTO>> areaCodeDictTree(AreaCodeDictFormDTO formDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "areaCodeDictTree", formDTO);
}
}

14
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/constant/AreaCodeConstant.java

@ -0,0 +1,14 @@
package com.epmet.constant;
/**
* @Author zxc
* @DateTime 2021/1/7 下午4:53
*/
public interface AreaCodeConstant {
/**
* redis的key
*/
String SCREEN_TREE = "epmet:screen:tree:areacode";
}

14
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/AreaCodeController.java

@ -25,10 +25,13 @@ import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.service.AreaCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@ -81,4 +84,15 @@ public class AreaCodeController {
return new Result();
}
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
@PostMapping("areacodedicttree")
public Result<List<AreaCodeDictResultDTO>> areaCodeDictTree(@RequestBody AreaCodeDictFormDTO formDTO){
return new Result<List<AreaCodeDictResultDTO>>().ok(areaCodeService.areaCodeDictTree(formDTO));
}
}

7
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeChildDao.java

@ -18,9 +18,12 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.AreaCodeChildDTO;
import com.epmet.entity.AreaCodeChildEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* (4-5)街道/城镇和社区/村地区code
*
@ -29,5 +32,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface AreaCodeChildDao extends BaseDao<AreaCodeChildEntity> {
List<AreaCodeChildDTO> selectAllChild();
}

7
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeDao.java

@ -18,9 +18,12 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.entity.AreaCodeEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 大陆省市区地区码
*
@ -29,5 +32,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface AreaCodeDao extends BaseDao<AreaCodeEntity> {
List<AreaCodeDTO> selectAllArea();
}

11
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/redis/AreaCodeRedis.java

@ -17,6 +17,7 @@
package com.epmet.redis;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -36,11 +37,15 @@ public class AreaCodeRedis {
}
public void set(){
public void set(String key,Object o){
redisUtils.set(key,o, NumConstant.ONE_NEG);
}
public String get(String id){
public String get(String key){
Object o = redisUtils.get(key);
if (null != o){
return o.toString();
}
return null;
}

11
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/AreaCodeService.java

@ -20,7 +20,10 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.entity.AreaCodeEntity;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.Map;
@ -92,4 +95,12 @@ public interface AreaCodeService extends BaseService<AreaCodeEntity> {
* @date 2021-01-07
*/
void delete(String[] ids);
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
List<AreaCodeDictResultDTO> areaCodeDictTree(AreaCodeDictFormDTO formDTO);
}

168
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java

@ -17,14 +17,21 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.constant.AreaCodeConstant;
import com.epmet.dao.AreaCodeChildDao;
import com.epmet.dao.AreaCodeDao;
import com.epmet.dto.AreaCodeChildDTO;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.entity.AreaCodeEntity;
import com.epmet.redis.AreaCodeRedis;
import com.epmet.service.AreaCodeService;
@ -32,10 +39,11 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/**
* 大陆省市区地区码
@ -48,6 +56,8 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
@Autowired
private AreaCodeRedis areaCodeRedis;
@Autowired
private AreaCodeChildDao childDao;
@Override
public PageData<AreaCodeDTO> page(Map<String, Object> params) {
@ -101,4 +111,156 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
baseDao.deleteBatchIds(Arrays.asList(ids));
}
/**
* @Description 行政地区编码查询
* @Param formDTO
* @author zxc
* @date 2021/1/7 下午1:41
*/
@Override
public List<AreaCodeDictResultDTO> areaCodeDictTree(AreaCodeDictFormDTO formDTO) {
List<AreaCodeDictResultDTO> tree = new ArrayList<>();
String s = areaCodeRedis.get(AreaCodeConstant.SCREEN_TREE);
if (StringUtils.isNotBlank(s)){
tree = JSON.parseArray(s,AreaCodeDictResultDTO.class);
}else {
List<AreaCodeDictResultDTO> areaCodeDictResultDTOS = disposeTree();
areaCodeRedis.set(AreaCodeConstant.SCREEN_TREE,areaCodeDictResultDTOS);
tree = areaCodeDictResultDTOS;
}
if (StringUtils.isBlank(formDTO.getRootAreaCode())){
return tree;
}
List<AreaCodeDictResultDTO> treeByRootAreaCode = getTreeByRootAreaCode(tree, formDTO.getRootAreaCode());
return treeByRootAreaCode;
}
/**
* @Description 行政区树查询
* @Param
* @author zxc
* @date 2021/1/8 上午8:57
*/
public List<AreaCodeDictResultDTO> disposeTree(){
List<AreaCodeDTO> areaCodeDTOS = baseDao.selectAllArea();
List<AreaCodeChildDTO> areaCodeChildDTOS = childDao.selectAllChild();
List<AreaCodeDictResultDTO> result = new ArrayList<>();
List<AreaCodeDictResultDTO> fourResult = new ArrayList<>();
List<AreaCodeDictResultDTO> cityResult = new ArrayList<>();
// 街道-社区
Map<Integer, List<AreaCodeChildDTO>> groupByLevel = areaCodeChildDTOS.stream().collect(Collectors.groupingBy(AreaCodeChildDTO::getLevel));
List<AreaCodeChildDTO> levelFive = groupByLevel.get(NumConstant.FIVE);
Map<String, List<AreaCodeChildDTO>> groupByPCode = levelFive.stream().collect(Collectors.groupingBy(AreaCodeChildDTO::getPCode));
List<AreaCodeChildDTO> levelFour = groupByLevel.get(NumConstant.FOUR);
levelFour.forEach(four -> {
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO();
dto.setCode(four.getCode());
dto.setName(four.getName());
dto.setParentCode(four.getPCode());
groupByPCode.forEach((pCode,v) -> {
if (dto.getCode().equals(pCode)){
List<AreaCodeDictResultDTO> fiveResult = new ArrayList<>();
v.forEach(five -> {
AreaCodeDictResultDTO fiveDto = new AreaCodeDictResultDTO();
fiveDto.setCode(five.getCode());
fiveDto.setName(five.getName());
fiveResult.add(fiveDto);
});
List<AreaCodeDictResultDTO> fiveSort = fiveResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList());
dto.setChildren(fiveSort);
}
});
fourResult.add(dto);
});
List<AreaCodeDictResultDTO> fourSort = new ArrayList<>();
if (!CollectionUtils.isEmpty(fourResult)){
fourSort = fourResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList());
}
// 省市区
Map<String, List<AreaCodeDTO>> groupByCity = areaCodeDTOS.stream().collect(Collectors.groupingBy(AreaCodeDTO::getCityCode));
Map<String, List<AreaCodeDTO>> groupByProvince = areaCodeDTOS.stream().collect(Collectors.groupingBy(AreaCodeDTO::getProvinceCode));
List<AreaCodeDictResultDTO> finalFourSort = fourSort;
groupByCity.forEach((c, v) -> {
AreaCodeDictResultDTO cityDto = new AreaCodeDictResultDTO();
cityDto.setName(v.get(NumConstant.ZERO).getCityName());
cityDto.setCode(v.get(NumConstant.ZERO).getCityCode());
cityDto.setParentCode(v.get(NumConstant.ZERO).getProvinceCode());
List<AreaCodeDictResultDTO> threeResult = new ArrayList<>();
v.forEach(three -> {
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO();
dto.setCode(three.getCountyCode());
dto.setName(three.getCountyName());
List<AreaCodeDictResultDTO> fourOnceResult = new ArrayList<>();
finalFourSort.forEach(four -> {
if (dto.getCode().equals(four.getParentCode())){
fourOnceResult.add(four);
}
});
dto.setChildren(fourOnceResult);
threeResult.add(dto);
});
List<AreaCodeDictResultDTO> threeSort = threeResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList());
cityDto.setChildren(threeSort);
cityResult.add(cityDto);
});
groupByProvince.forEach((p,v) -> {
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO();
dto.setCode(p);
dto.setName(v.get(NumConstant.ZERO).getProvinceName());
List<AreaCodeDictResultDTO> cityOnceResult = new ArrayList<>();
cityResult.forEach(c -> {
if (dto.getCode().equals(c.getParentCode())){
cityOnceResult.add(c);
}
});
List<AreaCodeDictResultDTO> citySort = cityOnceResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList());
dto.setChildren(citySort);
result.add(dto);
});
List<AreaCodeDictResultDTO> collect = result.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList());
return collect;
}
/**
* @Description 根据节点获取组织区域树遍历传参只能是 区级别
* @Param tree
* @Param rootAreaCode
* @author zxc
* @date 2021/1/8 上午10:02
*/
public List<AreaCodeDictResultDTO> getTreeByRootAreaCode(List<AreaCodeDictResultDTO> tree , String rootAreaCode){
List<AreaCodeDictResultDTO> result = new ArrayList<>();
AtomicReference<Boolean> flag = new AtomicReference<>(false);
if (!CollectionUtils.isEmpty(tree)){
// 省级获取
tree.forEach(t -> {
if (rootAreaCode.equals(t.getCode())){
result.add(t);
flag.set(true);
}
// 市级获取
if (!CollectionUtils.isEmpty(t.getChildren()) && flag.get() == false){
t.getChildren().forEach(c -> {
if (rootAreaCode.equals(c.getCode())){
result.add(c);
flag.set(true);
}
// 区级获取
if (!CollectionUtils.isEmpty(c.getChildren()) && flag.get() == false){
c.getChildren().forEach(three -> {
if (rootAreaCode.equals(three.getCode()) && flag.get() == false){
result.add(three);
flag.set(true);
}
});
}
});
}
});
}
return result;
}
}

3
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeChildDao.xml

@ -4,4 +4,7 @@
<mapper namespace="com.epmet.dao.AreaCodeChildDao">
<select id="selectAllChild" resultType="com.epmet.dto.AreaCodeChildDTO">
select * from area_code_child
</select>
</mapper>

3
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeDao.xml

@ -4,4 +4,7 @@
<mapper namespace="com.epmet.dao.AreaCodeDao">
<select id="selectAllArea" resultType="com.epmet.dto.AreaCodeDTO">
select * from area_code;
</select>
</mapper>
Loading…
Cancel
Save