Browse Source

查询agency的所有下级网格Id逻辑修改

master
wangchao 5 years ago
parent
commit
4b4491588c
  1. 27
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java

27
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java

@ -35,22 +35,22 @@ public class UserServiceImpl implements UserService {
/** /**
* @Description 遍历所有机关(它的下级机关)统计注册用户和参与用户的数据,使用level控制 * @Description 遍历所有机关(它的下级机关)统计注册用户和参与用户的数据,使用level控制
* @param topAgencies - List<AgencySubTreeDto> * @param agencies - List<AgencySubTreeDto>
* @return * @return
* @author wangc * @author wangc
* @date 2020.06.18 10:03 * @date 2020.06.18 10:03
**/ **/
@Override @Override
public void traverseAgencyUser(List<AgencySubTreeDto> topAgencies, Date targetDate) { public void traverseAgencyUser(List<AgencySubTreeDto> agencies, Date targetDate) {
if(null == topAgencies || topAgencies.size() == NumConstant.ZERO){ if(null == agencies || agencies.size() == NumConstant.ZERO){
logger.warn("没有相应的机关集合"); logger.warn("没有相应的机关集合");
return ; return ;
} }
//自上向下检索 //自上向下检索
//Map<String, List<AgencySubTreeDto>> agencyMap = agencies.stream().collect(Collectors.groupingBy(AgencySubTreeDto::getAgencyId)); //Map<String, List<AgencySubTreeDto>> agencyMap = agencies.stream().collect(Collectors.groupingBy(AgencySubTreeDto::getAgencyId));
Map<String,Set<String>> subGridOfAgency = new HashMap<>(); Map<String,Set<String>> subGridOfAgency = new HashMap<>();
topAgencies.forEach(agency -> { agencies.forEach(agency -> {
initAgencyGridMap(agency,subGridOfAgency); initAgencyGridMap(agency.getAgencyId(),agency,subGridOfAgency);
}); });
//对每一个机关进行数据统计 //对每一个机关进行数据统计
@ -86,6 +86,7 @@ public class UserServiceImpl implements UserService {
} }
} }
/** /**
* @Description 初始化机关-所有下级网格Map * @Description 初始化机关-所有下级网格Map
* @param agency - AgencySubTreeDto * @param agency - AgencySubTreeDto
@ -93,15 +94,16 @@ public class UserServiceImpl implements UserService {
* @return * @return
* @author wangc * @author wangc
* @date 2020.06.18 15:54 * @date 2020.06.18 15:54
**/ **/
void initAgencyGridMap(AgencySubTreeDto agency, Map<String,Set<String>> subGridOfAgency){ void initAgencyGridMap(String pid, AgencySubTreeDto agency, Map<String,Set<String>> subGridOfAgency){
//向map中放入数据 //向map中放入数据
if(subGridOfAgency.containsKey(agency.getAgencyId())){ if(subGridOfAgency.containsKey(pid)){
//包含key //包含key
Set<String> grids = subGridOfAgency.get(agency.getAgencyId()); Set<String> grids = subGridOfAgency.get(pid);
if(null == grids){ if(null == grids){
grids = new HashSet<>(); grids = new HashSet<>();
subGridOfAgency.put(agency.getAgencyId(),grids); subGridOfAgency.put(pid,grids);
} }
if(null != agency.getGridIds() && agency.getGridIds().size() > NumConstant.ZERO){ if(null != agency.getGridIds() && agency.getGridIds().size() > NumConstant.ZERO){
grids.addAll(agency.getGridIds()); grids.addAll(agency.getGridIds());
@ -109,7 +111,7 @@ public class UserServiceImpl implements UserService {
}else{ }else{
//不包含key //不包含key
Set<String> grids = new HashSet<>(agency.getGridIds()); Set<String> grids = new HashSet<>(agency.getGridIds());
subGridOfAgency.put(agency.getAgencyId(),grids); subGridOfAgency.put(pid,grids);
} }
//定义递归出口 //定义递归出口
@ -117,9 +119,10 @@ public class UserServiceImpl implements UserService {
return ; return ;
} }
//定义递归入口 //定义递归入口
agency.getSubAgencies().forEach(obj -> { agency.getSubAgencies().forEach(obj -> {
initAgencyGridMap(obj,subGridOfAgency); initAgencyGridMap(pid,obj,subGridOfAgency);
}); });
} }

Loading…
Cancel
Save