From 3e8159ed09163dbd8051be53fced8568f8b53122 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Mon, 17 Jun 2024 20:04:43 +0800
Subject: [PATCH] 租客导入优化
---
src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java | 284 ++++++++++++++++++++++++++++++++------------------------
1 files changed, 161 insertions(+), 123 deletions(-)
diff --git a/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java b/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
index 3a81999..7b04ed6 100644
--- a/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
+++ b/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
@@ -23,6 +23,8 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springblade.common.constant.CommonConstant;
import org.springblade.common.node.TreeIntegerNode;
import org.springblade.common.node.TreeStringNode;
@@ -74,6 +76,8 @@
*/
@Service
public class HouseholdServiceImpl extends ServiceImpl<HouseholdMapper, HouseholdEntity> implements IHouseholdService {
+
+ private static Logger logger = LoggerFactory.getLogger(HouseholdServiceImpl.class);
@Autowired
private IUserHouseLabelService userHouseLabelService;
@@ -350,17 +354,19 @@
ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
// 创建Future列表来保存每个任务的结果
- List<Future<String>> futures = new ArrayList<>();
+ List<Future<Map<String, String>>> futures = new ArrayList<>();
for (ImportHouseholdExcel houseHoldExcel : data) {
- Callable<String> task = () -> importHouseHold(houseHoldExcel,houseService,isCovered,isTenant);
+ Callable<Map<String, String>> task = () -> importHouseHold(houseHoldExcel, houseService, isCovered, isTenant);
futures.add(executorService.submit(task));
}
// 收集并打印结果
- for (Future<String> future : futures) {
+ for (Future<Map<String, String>> future : futures) {
try {
- String result = future.get();
- switch (result){
+ Map<String, String> stringStringMap = future.get();
+ logger.info("结果:{}", stringStringMap);
+ String result = stringStringMap.get("restult");
+ switch (result) {
case "1":
importNum++;
break;
@@ -370,10 +376,18 @@
case "3":
errorNum++;
break;
+ case "4":
+ importNum++;
+ updateNum++;
+ break;
+ default:
+ errorNum++;
+ break;
}
// 获取并打印每个任务的结果
} catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
+ errorNum++;
+ logger.error("获取异常-----》", e);
}
}
// 关闭线程池
@@ -398,129 +412,153 @@
}
- public String importHouseHold(ImportHouseholdExcel houseHoldExcel, IHouseService houseService, Boolean isCovered,String isTenant) {
- HouseholdEntity householdEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class));
- // 判断姓名,手机号
- if (Strings.isBlank(householdEntity.getName())
- || Strings.isBlank(householdEntity.getHouseCode())
- ) {
- // errorNum++;
- // continue;
- return "3";
- }
- // 查询库中是否已存在
- QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>();
- wrapper.eq("house_code", householdEntity.getHouseCode())
- .eq("is_deleted", 0)
- .eq("name", householdEntity.getName());
- List<HouseholdEntity> list = this.list(wrapper);
- // 与角色关系
- if (!Strings.isBlank(houseHoldExcel.getRelationship())) {
- householdEntity.setRelationship(Integer.parseInt(houseHoldExcel.getRelationship()));
- // 如果是业主,则需要往用户表插入用户
- if (householdEntity.getRelationship() == 1) {
- houseService.saveOrUpdateUser(householdEntity);
+ public Map<String, String> importHouseHold(ImportHouseholdExcel houseHoldExcel, IHouseService houseService, Boolean isCovered, String isTenant) {
+ Map<String, String> objectObjectHashMap = new HashMap<>();
+ try {
+ HouseholdEntity householdEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class));
+ // 判断姓名,手机号
+ if (Strings.isBlank(householdEntity.getName()) || Strings.isBlank(householdEntity.getHouseCode())) {
+ objectObjectHashMap.put("row", householdEntity.getName() + ":" + householdEntity.getPhoneNumber());
+ objectObjectHashMap.put("restult", "3");
+ return objectObjectHashMap;
}
- }
- // 判断是否租户导入
- if (StringUtils.isNotBlank(isTenant)) {
- householdEntity.setRelationship(18);
- HouseRentalEntity houseRentalEntity = iHouseRentalService.getOne(Wrappers.<HouseRentalEntity>lambdaQuery()
- .eq(HouseRentalEntity::getHouseCode, householdEntity.getHouseCode()));
- if (houseRentalEntity != null) {
- householdEntity.setHousingRentalId(houseRentalEntity.getId());
- } else {
- // 新建出租屋
- HouseRentalEntity rentalEntity = new HouseRentalEntity();
- rentalEntity.setHouseCode(householdEntity.getHouseCode());
- rentalEntity.setHouseStatus(1);
- rentalEntity.setAuditStatus(0);
- rentalEntity.setRentalUse(4);
- rentalEntity.setTenantRelationship(1);
- rentalEntity.setRentalTime(new Date());
- rentalEntity.setDueTime(new Date());
- rentalEntity.setTerminationTime(new Date());
- iHouseRentalService.save(rentalEntity);
- householdEntity.setHousingRentalId(rentalEntity.getId());
+ // 去除手机号中间空格
+ if (StringUtils.isNotBlank(householdEntity.getPhoneNumber())) {
+ householdEntity.setPhoneNumber(householdEntity.getPhoneNumber().replaceAll(" ", ""));
}
- }
-
- /// 是否主要联系人
- if (!Strings.isBlank(houseHoldExcel.getIsPrimaryContact())) {
- householdEntity.setIsPrimaryContact(Integer.parseInt(houseHoldExcel.getIsPrimaryContact()));
- }
- // 居住状态
- if (!Strings.isBlank(houseHoldExcel.getResidentialStatus())) {
- householdEntity.setResidentialStatus(Integer.parseInt(houseHoldExcel.getResidentialStatus()));
- }
- // 性别
- if (!Strings.isBlank(houseHoldExcel.getGender())) {
- householdEntity.setGender(Short.parseShort(houseHoldExcel.getGender()));
- }
- // 居民身份证
- if (!Strings.isBlank(houseHoldExcel.getIdCard())) {
- if (IdcardUtil.isValidCard(houseHoldExcel.getIdCard())) {
- // 身份证类型为居民身份证
- householdEntity.setCardType(111);
+ // 查询库中是否已存在
+ QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>();
+ wrapper.eq("house_code", householdEntity.getHouseCode())
+ .eq("is_deleted", 0)
+ .eq("name", householdEntity.getName());
+ // 判断是否租客
+ if (StringUtils.isNotBlank(isTenant)) {
+ wrapper.eq("relationship", 18);
}
- }
- // 党员
- if (!Strings.isBlank(houseHoldExcel.getPartyEmber())) {
- householdEntity.setPartyEmber(Integer.parseInt(houseHoldExcel.getPartyEmber()));
- }
- // 民族
- if (!Strings.isBlank(houseHoldExcel.getEthnicity())) {
- householdEntity.setEthnicity(Integer.parseInt(houseHoldExcel.getEthnicity()));
- }
- // 学历
- if (!Strings.isBlank(houseHoldExcel.getEducation())) {
- householdEntity.setEducation(Integer.parseInt(houseHoldExcel.getEducation()));
- }
- // 健康状况
- if (!Strings.isBlank(houseHoldExcel.getHealthStatus())) {
- householdEntity.setHealthStatus(Integer.parseInt(houseHoldExcel.getHealthStatus()));
- }
- // 工作状态
- if (!Strings.isBlank(houseHoldExcel.getWorkStatus())) {
- householdEntity.setWorkStatus(Integer.parseInt(houseHoldExcel.getWorkStatus()));
- }
- // 外出时间
- if (!Strings.isBlank(houseHoldExcel.getGoOutTime())) {
- try {
- Date date = new SimpleDateFormat("yyyy-MM-dd").parse(houseHoldExcel.getGoOutTime());
- householdEntity.setGoOutTime(date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- // 婚姻状态
- if (!Strings.isBlank(houseHoldExcel.getMaritalStatus())) {
- householdEntity.setMaritalStatus(Integer.parseInt(houseHoldExcel.getMaritalStatus()));
- }
-
- if (list.size() == 0) {
- // 新增
- this.save(householdEntity);
- // importNum++;
- // 处理标签
- handleLabel(householdEntity, houseHoldExcel);
- return "1";
- } else {
- // updateNum++;
- if (isCovered) {
- for (HouseholdEntity one : list) {
- // 覆盖更新
- householdEntity.setId(one.getId());
- // 更新
- updateById(householdEntity);
- // 处理标签
- handleLabel(householdEntity, houseHoldExcel);
+ List<HouseholdEntity> list = this.list(wrapper);
+ // 与角色关系
+ if (!Strings.isBlank(houseHoldExcel.getRelationship())) {
+ householdEntity.setRelationship(Integer.parseInt(houseHoldExcel.getRelationship()));
+ // 如果是业主,则需要往用户表插入用户
+ if (householdEntity.getRelationship() == 1) {
+ houseService.saveOrUpdateUser(householdEntity);
}
- // importNum++;
- return "2";
}
+ // 判断是否租户导入
+ if (StringUtils.isNotBlank(isTenant)) {
+ householdEntity.setRelationship(18);
+ HouseRentalEntity houseRentalEntity = iHouseRentalService.getOne(Wrappers.<HouseRentalEntity>lambdaQuery()
+ .eq(HouseRentalEntity::getHouseCode, householdEntity.getHouseCode()).last("limit 1"));
+ if (houseRentalEntity != null) {
+ householdEntity.setHousingRentalId(houseRentalEntity.getId());
+ } else {
+ // 新建出租屋
+ HouseRentalEntity rentalEntity = new HouseRentalEntity();
+ rentalEntity.setHouseCode(householdEntity.getHouseCode());
+ rentalEntity.setHouseStatus(1);
+ rentalEntity.setAuditStatus(0);
+ rentalEntity.setRentalUse(4);
+ rentalEntity.setTenantRelationship(1);
+ rentalEntity.setRentalTime(new Date());
+ rentalEntity.setDueTime(new Date());
+ rentalEntity.setTerminationTime(new Date());
+ iHouseRentalService.save(rentalEntity);
+ householdEntity.setHousingRentalId(rentalEntity.getId());
+ }
+ }
+
+ /// 是否主要联系人
+ if (!Strings.isBlank(houseHoldExcel.getIsPrimaryContact())) {
+ householdEntity.setIsPrimaryContact(Integer.parseInt(houseHoldExcel.getIsPrimaryContact()));
+ }
+ // 居住状态
+ if (!Strings.isBlank(houseHoldExcel.getResidentialStatus())) {
+ householdEntity.setResidentialStatus(Integer.parseInt(houseHoldExcel.getResidentialStatus()));
+ }
+ // 性别
+ if (!Strings.isBlank(houseHoldExcel.getGender())) {
+ householdEntity.setGender(Short.parseShort(houseHoldExcel.getGender()));
+ }
+ // 居民身份证
+ if (!Strings.isBlank(houseHoldExcel.getIdCard())) {
+ if (IdcardUtil.isValidCard(houseHoldExcel.getIdCard())) {
+ // 身份证类型为居民身份证
+ householdEntity.setCardType(111);
+ }
+ }
+ // 党员
+ if (!Strings.isBlank(houseHoldExcel.getPartyEmber())) {
+ householdEntity.setPartyEmber(Integer.parseInt(houseHoldExcel.getPartyEmber()));
+ }
+ // 民族
+ if (!Strings.isBlank(houseHoldExcel.getEthnicity())) {
+ householdEntity.setEthnicity(Integer.parseInt(houseHoldExcel.getEthnicity()));
+ }
+ // 学历
+ if (!Strings.isBlank(houseHoldExcel.getEducation())) {
+ householdEntity.setEducation(Integer.parseInt(houseHoldExcel.getEducation()));
+ }
+ // 健康状况
+ if (!Strings.isBlank(houseHoldExcel.getHealthStatus())) {
+ householdEntity.setHealthStatus(Integer.parseInt(houseHoldExcel.getHealthStatus()));
+ }
+ // 工作状态
+ if (!Strings.isBlank(houseHoldExcel.getWorkStatus())) {
+ householdEntity.setWorkStatus(Integer.parseInt(houseHoldExcel.getWorkStatus()));
+ }
+ // 外出时间
+ if (!Strings.isBlank(houseHoldExcel.getGoOutTime())) {
+ try {
+ Date date = new SimpleDateFormat("yyyy-MM-dd").parse(houseHoldExcel.getGoOutTime());
+ householdEntity.setGoOutTime(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ // 婚姻状态
+ if (!Strings.isBlank(houseHoldExcel.getMaritalStatus())) {
+ householdEntity.setMaritalStatus(Integer.parseInt(houseHoldExcel.getMaritalStatus()));
+ }
+
+ if (list.size() == 0) {
+ // 新增
+ this.save(householdEntity);
+ // importNum++;
+ // 处理标签
+ handleLabel(householdEntity, houseHoldExcel);
+ // return "1";
+ objectObjectHashMap.put("row", householdEntity.getName() + ":" + householdEntity.getPhoneNumber());
+ objectObjectHashMap.put("restult", "1");
+ return objectObjectHashMap;
+ } else {
+ // updateNum++;
+ if (isCovered) {
+ for (HouseholdEntity one : list) {
+ // 覆盖更新
+ householdEntity.setId(one.getId());
+ // 更新
+ updateById(householdEntity);
+ // 处理标签
+ handleLabel(householdEntity, houseHoldExcel);
+ }
+ // importNum++;
+ // return "4";
+ objectObjectHashMap.put("row", householdEntity.getName() + ":" + householdEntity.getPhoneNumber());
+ objectObjectHashMap.put("restult", "4");
+ return objectObjectHashMap;
+ }
+ // return "2";
+ objectObjectHashMap.put("row", householdEntity.getName() + ":" + householdEntity.getPhoneNumber());
+ objectObjectHashMap.put("restult", "2");
+ return objectObjectHashMap;
+ }
+ } catch (Exception e) {
+ logger.error("异常导入------------》", e);
+ // return "3";
+ // objectObjectHashMap.put("row", householdEntity.getName() + ":" + householdEntity.getPhoneNumber());
+ objectObjectHashMap.put("restult", "3");
+ return objectObjectHashMap;
}
- return "3";
}
/**
--
Gitblit v1.9.3