|
|
@ -62,8 +62,8 @@ public class UserServiceImpl implements UserService { |
|
|
|
dataPacket.setDateId(timeDimension.getDateId()); |
|
|
|
dataPacket.setMonthId(timeDimension.getMonthId()); |
|
|
|
//自上向下检索
|
|
|
|
|
|
|
|
Map<String, List<AgencySubTreeDto>> agencyMap = agencies.stream().collect(Collectors.groupingBy(AgencySubTreeDto::getAgencyId)); |
|
|
|
//subGridOfAgency key:agencyId ,value:当前组织下的所有网格(即直属网格+下级组织下的所有网格)
|
|
|
|
Map<String,Set<String>> subGridOfAgency = new HashMap<>(); |
|
|
|
agencies.forEach(agency -> { |
|
|
|
initAgencyGridMap(agency.getAgencyId(),agency,subGridOfAgency); |
|
|
@ -71,12 +71,13 @@ public class UserServiceImpl implements UserService { |
|
|
|
|
|
|
|
//对每一个机关进行数据统计
|
|
|
|
if(subGridOfAgency.size() > NumConstant.ZERO){ |
|
|
|
subGridOfAgency.forEach((k,v) -> { |
|
|
|
//如果当前客户存在组织
|
|
|
|
subGridOfAgency.forEach((agencyId,subGridIds) -> { |
|
|
|
queryUserData(ModuleConstant.DIM_SUB_AGENCY, |
|
|
|
k, |
|
|
|
(null == agencyMap.get(k) || agencyMap.get(k).isEmpty()) ? NumConstant.ZERO_STR : agencyMap.get(k).get(NumConstant.ZERO).getPid(), |
|
|
|
(null == agencyMap.get(k) || agencyMap.get(k).isEmpty()) ? null : agencyMap.get(k).get(NumConstant.ZERO).getCustomerId(), |
|
|
|
v, |
|
|
|
agencyId, |
|
|
|
// (null == agencyMap.get(agencyId) || agencyMap.get(agencyId).isEmpty()) ? NumConstant.ZERO_STR : agencyMap.get(agencyId).get(NumConstant.ZERO).getPid(),
|
|
|
|
(null == agencyMap.get(agencyId) || agencyMap.get(agencyId).isEmpty()) ? null : agencyMap.get(agencyId).get(NumConstant.ZERO).getCustomerId(), |
|
|
|
subGridIds, |
|
|
|
targetDate, |
|
|
|
dataPacket, |
|
|
|
timeDimension); |
|
|
@ -107,11 +108,11 @@ public class UserServiceImpl implements UserService { |
|
|
|
//自上向下检索
|
|
|
|
Map<String, List<AgencySubTreeDto>> agencyMap = agencies.stream().collect(Collectors.groupingBy(AgencySubTreeDto::getAgencyId)); |
|
|
|
if(null != agencyMap && agencyMap.size() > NumConstant.ZERO){ |
|
|
|
agencyMap.forEach((k,v) -> { |
|
|
|
agencyMap.forEach((agencyId,v) -> { |
|
|
|
if(null != v && v.size() > NumConstant.ZERO){ |
|
|
|
queryUserData(ModuleConstant.DIM_BELONGING_GRID, |
|
|
|
k, |
|
|
|
v.get(NumConstant.ZERO).getPid(), |
|
|
|
agencyId, |
|
|
|
// v.get(NumConstant.ZERO).getPid(),
|
|
|
|
v.get(NumConstant.ZERO).getCustomerId(), |
|
|
|
new HashSet<>(v.get(NumConstant.ZERO).getGridIds()), |
|
|
|
targetDate, |
|
|
@ -181,22 +182,22 @@ public class UserServiceImpl implements UserService { |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 初始化机关-所有下级网格Map |
|
|
|
* @param pid - 固定一个机关Id |
|
|
|
* @param agencyId - 当前组织id |
|
|
|
* @param agency - AgencySubTreeDto |
|
|
|
* @param subGridOfAgency - Map<String,Set<String>> |
|
|
|
* @return |
|
|
|
* @author wangc |
|
|
|
* @date 2020.06.18 15:54 |
|
|
|
**/ |
|
|
|
void initAgencyGridMap(String pid, AgencySubTreeDto agency, Map<String,Set<String>> subGridOfAgency){ |
|
|
|
void initAgencyGridMap(String agencyId, AgencySubTreeDto agency, Map<String,Set<String>> subGridOfAgency){ |
|
|
|
|
|
|
|
//向map中放入数据
|
|
|
|
if(subGridOfAgency.containsKey(pid)){ |
|
|
|
if(subGridOfAgency.containsKey(agencyId)){ |
|
|
|
//包含key
|
|
|
|
Set<String> grids = subGridOfAgency.get(pid); |
|
|
|
Set<String> grids = subGridOfAgency.get(agencyId); |
|
|
|
if(null == grids){ |
|
|
|
grids = new HashSet<>(); |
|
|
|
subGridOfAgency.put(pid,grids); |
|
|
|
subGridOfAgency.put(agencyId,grids); |
|
|
|
} |
|
|
|
if(null != agency.getGridIds() && agency.getGridIds().size() > NumConstant.ZERO){ |
|
|
|
grids.addAll(agency.getGridIds()); |
|
|
@ -204,18 +205,20 @@ public class UserServiceImpl implements UserService { |
|
|
|
}else{ |
|
|
|
//不包含key
|
|
|
|
Set<String> grids = new HashSet<>(agency.getGridIds()); |
|
|
|
subGridOfAgency.put(pid,grids); |
|
|
|
subGridOfAgency.put(agencyId,grids); |
|
|
|
} |
|
|
|
|
|
|
|
//外层是从顶级组织向下循环,所以循环到社区时跳出
|
|
|
|
//定义递归出口
|
|
|
|
if(StringUtils.equals(ModuleConstant.AGENCY_LEVEL_COMMUNITY,agency.getLevel()) || null == agency.getSubAgencies() || agency.getSubAgencies().size() == NumConstant.ZERO){ |
|
|
|
if (StringUtils.equals(ModuleConstant.AGENCY_LEVEL_COMMUNITY, agency.getLevel()) |
|
|
|
|| null == agency.getSubAgencies() |
|
|
|
|| agency.getSubAgencies().size() == NumConstant.ZERO) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//定义递归入口
|
|
|
|
agency.getSubAgencies().forEach(obj -> { |
|
|
|
initAgencyGridMap(pid,obj,subGridOfAgency); |
|
|
|
initAgencyGridMap(agencyId,obj,subGridOfAgency); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -223,7 +226,7 @@ public class UserServiceImpl implements UserService { |
|
|
|
* @Description 执行查询用户数据统计的逻辑 |
|
|
|
* @param relation - agency(下级机关加网格) | grid(直属网格) |
|
|
|
* @param agencyId |
|
|
|
* @param pid |
|
|
|
* @param //pid 当前agency的父级组织id
|
|
|
|
* @param customerId |
|
|
|
* @param gridIds - 机关下所有网格集合/机关下直属网格集合 |
|
|
|
* @param targetDate |
|
|
@ -233,10 +236,12 @@ public class UserServiceImpl implements UserService { |
|
|
|
* @author wangc |
|
|
|
* @date 2020.06.19 10:01 |
|
|
|
**/ |
|
|
|
void queryUserData(String relation, String agencyId, String pid, String customerId, Set<String> gridIds, Date targetDate, UserStatisticalData dataPacket, DimIdGenerator.DimIdBean timeDimension){ |
|
|
|
|
|
|
|
if(StringUtils.isBlank(pid)) |
|
|
|
pid = NumConstant.ZERO_STR; |
|
|
|
void queryUserData(String relation, String agencyId, |
|
|
|
// String pid,
|
|
|
|
String customerId, Set<String> gridIds, Date targetDate, UserStatisticalData dataPacket, DimIdGenerator.DimIdBean timeDimension){ |
|
|
|
//pid没用到还传过来干啥-- 注释掉
|
|
|
|
// if(StringUtils.isBlank(pid))
|
|
|
|
// pid = NumConstant.ZERO_STR;
|
|
|
|
|
|
|
|
dataPacket.setCustomerId(customerId); |
|
|
|
|
|
|
@ -253,6 +258,9 @@ public class UserServiceImpl implements UserService { |
|
|
|
|
|
|
|
//指定日期 OR T-1
|
|
|
|
calendar.setTime(targetDateCheck); |
|
|
|
//calendar.get(Calendar.DATE) 当前日期数eg:2021-03-29 :29
|
|
|
|
//calendar.getActualMinimum(Calendar.DAY_OF_MONTH) :1
|
|
|
|
|
|
|
|
//如果目标日期不是是当月的第一天
|
|
|
|
if(calendar.get(Calendar.DATE) != calendar.getActualMinimum(Calendar.DAY_OF_MONTH)){ |
|
|
|
//求出这个月的第一天
|
|
|
@ -264,7 +272,6 @@ public class UserServiceImpl implements UserService { |
|
|
|
|
|
|
|
isMonthBeginning = false; |
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.equals(ModuleConstant.DIM_SUB_AGENCY,relation)){ |
|
|
|
|
|
|
|
|
|
|
@ -396,8 +403,6 @@ public class UserServiceImpl implements UserService { |
|
|
|
partiAgencyM.setWarmHeartedProportion(partiAgencyD.getWarmHeartedProportion()); |
|
|
|
partiAgencyM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果是月初第一天,不再做日期区间查询
|
|
|
|
if(isMonthBeginning) { |
|
|
|
if (null == dataPacket.getRegAgencyMonthlyList()) { |
|
|
@ -416,6 +421,7 @@ public class UserServiceImpl implements UserService { |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//如果不是月初第一天
|
|
|
|
//targetDateCheck:定时任务参数中的date;calendar.getTime():date所属月第一天;
|
|
|
|
|
|
|
|
//本月注册用户增长数
|
|
|
|
Integer regIncrMonthly = userDao.selectResiIncrWithinTimeRange(ModuleConstant.REG_OR_PARTI_FLAG_REG,gridIds,calendar.getTime(),targetDateCheck); |
|
|
|