|
@ -1,19 +1,21 @@ |
|
|
package com.epmet.dataaggre.service.impl; |
|
|
package com.epmet.dataaggre.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; |
|
|
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; |
|
|
import com.epmet.dataaggre.dto.epmetuser.result.ResiInfoResultDTO; |
|
|
import com.epmet.dataaggre.dto.epmetuser.result.ResiByPolicyInfoResultDTO; |
|
|
|
|
|
import com.epmet.dataaggre.dto.govorg.result.GridsInfoListResultDTO; |
|
|
import com.epmet.dataaggre.entity.govorg.IcHouseEntity; |
|
|
import com.epmet.dataaggre.entity.govorg.IcHouseEntity; |
|
|
import com.epmet.dataaggre.service.ResiService; |
|
|
import com.epmet.dataaggre.service.ResiService; |
|
|
import com.epmet.dataaggre.service.epmetuser.EpmetUserService; |
|
|
import com.epmet.dataaggre.service.epmetuser.EpmetUserService; |
|
|
import com.epmet.dataaggre.service.govorg.GovOrgService; |
|
|
import com.epmet.dataaggre.service.govorg.GovOrgService; |
|
|
|
|
|
import com.epmet.dto.IcNeighborHoodDTO; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.time.*; |
|
|
import java.util.List; |
|
|
import java.util.*; |
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
@ -26,38 +28,45 @@ public class ResiServiceImpl implements ResiService { |
|
|
private GovOrgService govOrgService; |
|
|
private GovOrgService govOrgService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<ResiInfoResultDTO> listByPolicyRules(Integer pageNo, Integer pageSize, |
|
|
public List<ResiByPolicyInfoResultDTO> listByPolicyRules(String orgId, String orgType, String neighborHoodId, String buildingId, String unitId, |
|
|
Set<ResisByPolicyRulesFormDTO.PolicyRule> resiRule, |
|
|
String houseId, String idCard, String name, Integer pageNo, Integer pageSize, |
|
|
Set<ResisByPolicyRulesFormDTO.PolicyRule> houseRule, |
|
|
List<ResisByPolicyRulesFormDTO.ResiRule> resiRule, |
|
|
Set<ResisByPolicyRulesFormDTO.PolicyRule> houseStat) { |
|
|
List<ResisByPolicyRulesFormDTO.HouseRule> houseRule, |
|
|
|
|
|
List<ResisByPolicyRulesFormDTO.StatRule> statRule) { |
|
|
String customerId = EpmetRequestHolder.getLoginUserCustomerId(); |
|
|
String customerId = EpmetRequestHolder.getLoginUserCustomerId(); |
|
|
|
|
|
|
|
|
// 结果集
|
|
|
// 结果集
|
|
|
List<ResiInfoResultDTO> resultResis = new ArrayList<>(); |
|
|
List<ResiByPolicyInfoResultDTO> resultResis = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 1.用户没配置house和stat规则,直接按照居民规则查询
|
|
|
|
|
|
if (CollectionUtils.isEmpty(houseRule) && CollectionUtils.isEmpty(statRule)) { |
|
|
|
|
|
return epmetUserService.listByPolicyRules(customerId, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
|
|
houseId, idCard, name, pageNo, pageSize, resiRule, null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2.用户至少配置了house和stat规则的一个,那么就先查询房屋出来,然后根据房屋去找居民
|
|
|
int housePageNo = 0; |
|
|
int housePageNo = 0; |
|
|
do { |
|
|
do { |
|
|
// houseIds 为null,说明用户没有指定house和统计的规则,则不应该使用这两项来查询,sql中不应该有这方面的条件
|
|
|
|
|
|
List<String> houseIds = null; |
|
|
|
|
|
|
|
|
|
|
|
// 拿到房屋id列表,去查询居民列表
|
|
|
// 拿到房屋id列表,去查询居民列表
|
|
|
if (CollectionUtils.isNotEmpty(houseRule) || CollectionUtils.isNotEmpty(houseStat)) { |
|
|
List<IcHouseEntity> houseEntities = govOrgService.listHousesByRules(customerId, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
List<IcHouseEntity> houseEntities = govOrgService.listHousesByRules(houseRule, houseStat, housePageNo, 50); |
|
|
houseId, houseRule, statRule, housePageNo, 50); |
|
|
houseIds = houseEntities.stream().map(icHouseEntity -> icHouseEntity.getId()).collect(Collectors.toList()); |
|
|
List<String> houseIds = houseEntities.stream().map(icHouseEntity -> icHouseEntity.getId()).collect(Collectors.toList()); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (houseIds != null && houseIds.size() == 0) { |
|
|
if (houseIds.size() == 0) { |
|
|
// 用户使用了房屋和统计相关的条件,但是没查到房屋,我看就没有走下去了的必要了吧..
|
|
|
// 用户使用了房屋和统计相关的条件,但是没查到房屋,我看就没有走下去了的必要了吧..
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 查询居民
|
|
|
// 查询居民
|
|
|
List<ResiInfoResultDTO> resis = epmetUserService.listByPolicyRules(customerId, resiRule, houseIds); |
|
|
List<ResiByPolicyInfoResultDTO> resis = epmetUserService.listByPolicyRules( |
|
|
|
|
|
customerId, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
|
|
houseId, idCard, name, pageNo, pageSize, resiRule, houseIds); |
|
|
|
|
|
|
|
|
resultResis.addAll(resis); |
|
|
resultResis.addAll(resis); |
|
|
|
|
|
|
|
|
// 满了20个,或者查不到居民和房屋了(数据空了),则跳出
|
|
|
// 满了20个,或者查不到居民和房屋了(数据空了),则跳出
|
|
|
// 没有用house的条件,没有循环的必要,查一次居民信息即可,跳出
|
|
|
// 没有用house的条件,没有循环的必要,查一次居民信息即可,跳出
|
|
|
if (resultResis.size() >= pageSize || houseIds == null ) { |
|
|
if (resultResis.size() >= pageSize) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -66,9 +75,50 @@ public class ResiServiceImpl implements ResiService { |
|
|
|
|
|
|
|
|
// 够了20个,那就截取前20个,否则直接返回
|
|
|
// 够了20个,那就截取前20个,否则直接返回
|
|
|
if (resultResis.size() > 20) { |
|
|
if (resultResis.size() > 20) { |
|
|
return resultResis.subList(0, 20); |
|
|
resultResis = resultResis.subList(0, 20); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 补充额外信息
|
|
|
|
|
|
fillResisExtraInfoForPolicy(resultResis); |
|
|
return resultResis; |
|
|
return resultResis; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 补充额外信息 |
|
|
|
|
|
* @param resultResis |
|
|
|
|
|
*/ |
|
|
|
|
|
private void fillResisExtraInfoForPolicy(List<ResiByPolicyInfoResultDTO> resultResis) { |
|
|
|
|
|
List<String> gridIds = new ArrayList<>(); |
|
|
|
|
|
List<String> neighborhoodIds = new ArrayList<>(); |
|
|
|
|
|
resultResis.stream().forEach((r) -> { |
|
|
|
|
|
gridIds.add(r.getGridId()); |
|
|
|
|
|
neighborhoodIds.add(r.getNeighborhoodId()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 统一收集网格和小区信息
|
|
|
|
|
|
Map<String, String> gridIdAndName = govOrgService.gridListByIds(gridIds) |
|
|
|
|
|
.stream() |
|
|
|
|
|
.collect(Collectors.toMap(GridsInfoListResultDTO::getGridId, GridsInfoListResultDTO::getName)); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> neighborhoodIdAndName = govOrgService.neighborhoodsByIds(neighborhoodIds) |
|
|
|
|
|
.stream().collect(Collectors.toMap(IcNeighborHoodDTO::getId, IcNeighborHoodDTO::getNeighborHoodName)); |
|
|
|
|
|
|
|
|
|
|
|
resultResis.stream().forEach((r) -> { |
|
|
|
|
|
// 小区名称
|
|
|
|
|
|
r.setNeighborHoodName(gridIdAndName.get(r.getGridId()).concat("-").concat(neighborhoodIdAndName.get(r.getNeighborhoodId()))); |
|
|
|
|
|
|
|
|
|
|
|
// 出生日期 & 年龄
|
|
|
|
|
|
if (r.getBirthday() != null) { |
|
|
|
|
|
Integer age = null; |
|
|
|
|
|
try { |
|
|
|
|
|
LocalDate birthdayLocalDate = LocalDateTime.ofInstant(r.getBirthday().toInstant(), ZoneId.systemDefault()).toLocalDate(); |
|
|
|
|
|
age = Period.between(birthdayLocalDate, LocalDate.now()).getYears(); |
|
|
|
|
|
} catch (DateTimeException e) { |
|
|
|
|
|
throw new EpmetException("居民生日计算错误"); |
|
|
|
|
|
} |
|
|
|
|
|
r.setAge(age); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|