|
|
|
@ -5,6 +5,7 @@ import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum; |
|
|
|
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
@ -12,6 +13,7 @@ import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.ResiByPolicyInfoResultDTO; |
|
|
|
@ -41,6 +43,8 @@ import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.time.temporal.TemporalUnit; |
|
|
|
import java.util.*; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@ -58,6 +62,8 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient userOpenFeignClient; |
|
|
|
|
|
|
|
public static final Pattern REG_DATE = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})"); |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ResiByPolicyInfoResultDTO> listByPolicyRules(String orgId, String orgType, String neighborHoodId, String buildingId, String unitId, |
|
|
|
String houseId, String idCard, String name, Integer pageNo, Integer pageSize, |
|
|
|
@ -92,6 +98,11 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
// 2.用户至少配置了house和stat规则的一个,那么就先查询房屋出来,然后根据房屋去找居民
|
|
|
|
int housePageNo = 1; |
|
|
|
int total = 0; |
|
|
|
|
|
|
|
// 只能手动分页了
|
|
|
|
int start = (pageNo - 1) * pageSize; |
|
|
|
int end = pageNo * pageSize; // 不包含
|
|
|
|
|
|
|
|
do { |
|
|
|
// 拿到房屋id列表,去查询居民列表
|
|
|
|
List<String> houseIds = govOrgService.listHouseIdsByRules(customerId, orgIdPath, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
@ -102,30 +113,32 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// 查询居民数量
|
|
|
|
Integer count = epmetUserService.getTotalByPolicyRules( |
|
|
|
customerId, orgIdPath, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
houseId, idCard, name, resiRule, houseIds); |
|
|
|
|
|
|
|
total += count; |
|
|
|
|
|
|
|
// 查询居民,满了20个,不再查询数据,只查询数量
|
|
|
|
if (resultResis.size() < pageSize) { |
|
|
|
if (resultResis.size() < end) { |
|
|
|
List<ResiByPolicyInfoResultDTO> resis = epmetUserService.listByPolicyRules( |
|
|
|
customerId, orgIdPath, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
houseId, idCard, name, pageNo, pageSize, resiRule, houseIds); |
|
|
|
houseId, idCard, name, 1, end, resiRule, houseIds); |
|
|
|
|
|
|
|
resultResis.addAll(resis); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询数量
|
|
|
|
Integer count = epmetUserService.getTotalByPolicyRules( |
|
|
|
customerId, orgIdPath, orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
houseId, idCard, name, resiRule, houseIds); |
|
|
|
|
|
|
|
total += count; |
|
|
|
|
|
|
|
housePageNo ++; |
|
|
|
} while (true); |
|
|
|
|
|
|
|
// 够了20个,那就截取前20个,否则直接返回
|
|
|
|
if (resultResis.size() > 20) { |
|
|
|
resultResis = resultResis.subList(0, 20); |
|
|
|
// 查出来所有的数据都没够到这一页的起始条数,返回空
|
|
|
|
if (resultResis.size() < start) { |
|
|
|
return new PageData<>(new ArrayList<>(), total); |
|
|
|
} |
|
|
|
|
|
|
|
resultResis = resultResis.subList(start, Math.min(end, resultResis.size())); |
|
|
|
|
|
|
|
// 补充额外信息
|
|
|
|
fillResisExtraInfoForPolicy(resultResis); |
|
|
|
return new PageData<>(resultResis, total); |
|
|
|
@ -137,13 +150,15 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
*/ |
|
|
|
private void specificRuleConvert(List<ResisByPolicyRulesFormDTO.ResiRule> resiRule) { |
|
|
|
// 使用年龄计算出生日期
|
|
|
|
resiRule.stream().forEach((r) -> { |
|
|
|
if ("BIRTHDAY".equals(r.getColKey())) { |
|
|
|
LocalDate birthday = LocalDate.now().minus(Long.valueOf(r.getColVal()), ChronoUnit.YEARS); |
|
|
|
r.setQueryType(revertQueryType(r.getQueryType())); |
|
|
|
r.setColVal(birthday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (resiRule != null) { |
|
|
|
resiRule.stream().forEach((r) -> { |
|
|
|
if ("BIRTHDAY".equals(r.getColKey())) { |
|
|
|
LocalDate birthday = LocalDate.now().minus(Long.valueOf(r.getColVal()), ChronoUnit.YEARS); |
|
|
|
r.setQueryType(revertQueryType(r.getQueryType())); |
|
|
|
r.setColVal(birthday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -203,19 +218,25 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
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(); |
|
|
|
Matcher matcher = REG_DATE.matcher(r.getBirthday()); |
|
|
|
if (matcher.matches()) { |
|
|
|
String year = matcher.group(1); |
|
|
|
String month = matcher.group(2); |
|
|
|
String day = matcher.group(3); |
|
|
|
LocalDate birthdayLocalDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); |
|
|
|
age = Period.between(birthdayLocalDate, LocalDate.now()).getYears(); |
|
|
|
r.setAge(age); |
|
|
|
} |
|
|
|
} catch (DateTimeException e) { |
|
|
|
throw new EpmetException("居民生日计算错误"); |
|
|
|
logger.error(r.getIcResiUserId() + "居民生日计算错误"); |
|
|
|
} |
|
|
|
r.setAge(age); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void exportResisByPolicy(String orgId, String orgType, String neighborHoodId, String buildingId, String unitId, |
|
|
|
String houseId, String idCard, String name, Integer pageNo, Integer pageSize, |
|
|
|
String houseId, String idCard, String name, |
|
|
|
String ruleId, List<ResisByPolicyRulesFormDTO.ResiRule> resiRule, |
|
|
|
List<ResisByPolicyRulesFormDTO.HouseRule> houseRule, |
|
|
|
List<ResisByPolicyRulesFormDTO.StatRule> statRule, |
|
|
|
@ -234,24 +255,34 @@ public class ResiServiceImpl implements ResiService, ResultDataResolver { |
|
|
|
statRule = ConvertUtils.sourceToTarget(ruleList.getStatRuleList(), ResisByPolicyRulesFormDTO.StatRule.class); |
|
|
|
} |
|
|
|
|
|
|
|
ServletOutputStream ostream = response.getOutputStream(); |
|
|
|
ExcelWriterSheetBuilder sheetBuilder = EasyExcel.write(ostream, ResisByPolicyExcel.class).sheet("居民列表"); |
|
|
|
|
|
|
|
// 循环填充数据
|
|
|
|
do { |
|
|
|
PageData<ResiByPolicyInfoResultDTO> resis = this.listByPolicyRules(orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
houseId, idCard, name, pageNo, pageSize, resiRule, houseRule, statRule); |
|
|
|
List<ResiByPolicyInfoResultDTO> list = resis.getList(); |
|
|
|
List<ResisByPolicyExcel> excelDatas = ConvertUtils.sourceToTarget(list, ResisByPolicyExcel.class); |
|
|
|
if (CollectionUtils.isEmpty(excelDatas)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
//sheetBuilder.write(excelDatas);
|
|
|
|
} while (true); |
|
|
|
|
|
|
|
|
|
|
|
// 模板导出
|
|
|
|
ExcelWriter writer = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("政策人员预览信息导出.xlsx", response)) |
|
|
|
//.withTemplate(inputStream)
|
|
|
|
.build(); |
|
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("政策人员列表") |
|
|
|
.head(ResiByPolicyInfoResultDTO.class) |
|
|
|
.build(); |
|
|
|
|
|
|
|
Integer pageSize = 500; |
|
|
|
Integer pageNo = 1; |
|
|
|
|
|
|
|
try { |
|
|
|
do { |
|
|
|
PageData<ResiByPolicyInfoResultDTO> resis = this.listByPolicyRules(orgId, orgType, neighborHoodId, buildingId, unitId, |
|
|
|
houseId, idCard, name, pageNo, pageSize, resiRule, houseRule, statRule); |
|
|
|
List<ResiByPolicyInfoResultDTO> list = resis.getList(); |
|
|
|
List<ResisByPolicyExcel> excelDatas = ConvertUtils.sourceToTarget(list, ResisByPolicyExcel.class); |
|
|
|
if (CollectionUtils.isEmpty(excelDatas)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println(666); |
|
|
|
writer.write(resis.getList(), writeSheet); |
|
|
|
pageNo++; |
|
|
|
} while (true); |
|
|
|
} finally { |
|
|
|
writer.finish(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|