|
|
@ -22,6 +22,7 @@ import com.epmet.commons.tools.utils.*; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dao.IcNatDao; |
|
|
|
import com.epmet.dao.IcNatRelationDao; |
|
|
|
import com.epmet.dao.IcResiUserDao; |
|
|
|
import com.epmet.dao.UserBaseInfoDao; |
|
|
|
import com.epmet.dto.IcNatDTO; |
|
|
|
import com.epmet.dto.IcNoticeDTO; |
|
|
@ -29,6 +30,7 @@ import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.IcNatEntity; |
|
|
|
import com.epmet.entity.IcNatRelationEntity; |
|
|
|
import com.epmet.entity.IcResiUserEntity; |
|
|
|
import com.epmet.excel.data.IcNatImportExcelData; |
|
|
|
import com.epmet.excel.handler.IcNatExcelImportListener; |
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
@ -54,10 +56,7 @@ import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -82,6 +81,8 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp |
|
|
|
private UserBaseInfoDao userBaseInfoDao; |
|
|
|
@Autowired |
|
|
|
private IcNatRelationDao icNatRelationDao; |
|
|
|
@Autowired |
|
|
|
private IcResiUserDao icResiUserDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
@ -313,7 +314,9 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp |
|
|
|
LoginUserDetailsResultDTO loginUserDetails = getResultDataOrThrowsException(epmetUserOpenFeignClient.getLoginUserDetails(ludf), ServiceConstant.EPMET_USER_SERVER, |
|
|
|
EpmetErrorCode.SERVER_ERROR.getCode(), "调用user出错", ""); |
|
|
|
|
|
|
|
IcNatExcelImportListener listener = new IcNatExcelImportListener(userId, loginUserDetails.getAgencyId(), loginUserDetails.getOrgIdPath(), this); |
|
|
|
String agencyId = loginUserDetails.getAgencyId(); |
|
|
|
|
|
|
|
IcNatExcelImportListener listener = new IcNatExcelImportListener(userId, agencyId, loginUserDetails.getOrgIdPath().replace(":".concat(agencyId), ""), this); |
|
|
|
|
|
|
|
EasyExcel.read(filePath.toFile(), IcNatImportExcelData.class, listener).headRowNumber(2).sheet(0).doRead(); |
|
|
|
|
|
|
@ -425,14 +428,171 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp |
|
|
|
* 批量持久化 |
|
|
|
* @param entities |
|
|
|
*/ |
|
|
|
public void batchPersist(List<IcNatEntity> entities) { |
|
|
|
//insertBatch(entities);
|
|
|
|
public void batchPersist(List<IcNatEntity> entities, IcNatExcelImportListener listener) { |
|
|
|
String customerId = EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID); |
|
|
|
String currentUserId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); |
|
|
|
|
|
|
|
entities.forEach(e -> { |
|
|
|
String id = IdWorker.getIdStr(e); |
|
|
|
e.setId(id); |
|
|
|
e.setUpdatedBy(currentUserId); |
|
|
|
baseDao.insertOrUpdate(e); |
|
|
|
try { |
|
|
|
persisNat(e, customerId, currentUserId, listener); |
|
|
|
} catch (Exception exception) { |
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(exception); |
|
|
|
log.error(errorMsg); |
|
|
|
|
|
|
|
IcNatImportExcelData.ErrorRow errorRow = new IcNatImportExcelData.ErrorRow(); |
|
|
|
errorRow.setName(e.getName()); |
|
|
|
errorRow.setMobile(e.getMobile()); |
|
|
|
errorRow.setIdCard(e.getIdCard()); |
|
|
|
errorRow.setErrorInfo("未知系统错误c "); |
|
|
|
listener.getErrorRows().add(errorRow); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 单条持久化 |
|
|
|
* @param e |
|
|
|
* @param customerId |
|
|
|
* @param currentUserId |
|
|
|
* @param listener |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void persisNat(IcNatEntity e, String customerId, String currentUserId, IcNatExcelImportListener listener) { |
|
|
|
List<IcNatImportExcelData.ErrorRow> errorRows = listener.getErrorRows(); |
|
|
|
|
|
|
|
Date natTime = e.getNatTime(); |
|
|
|
String idCard = e.getIdCard(); |
|
|
|
String name = e.getName(); |
|
|
|
String mobile = e.getMobile(); |
|
|
|
String natResult = e.getNatResult(); |
|
|
|
String natAddress = e.getNatAddress(); |
|
|
|
|
|
|
|
//1.先看客户下有没有这个人
|
|
|
|
IcNatEntity resiNat = getResiNat(customerId, idCard, natTime); |
|
|
|
if (resiNat != null && !"import".equals(resiNat.getUserType())) { |
|
|
|
// 有这个人,并且不是导入的
|
|
|
|
String message = "已存在该次核酸检测录入记录,请到系统中修改"; |
|
|
|
|
|
|
|
IcNatImportExcelData.ErrorRow errorRow = new IcNatImportExcelData.ErrorRow(); |
|
|
|
errorRow.setName(name); |
|
|
|
errorRow.setMobile(mobile); |
|
|
|
errorRow.setIdCard(idCard); |
|
|
|
errorRow.setErrorInfo(message); |
|
|
|
errorRows.add(errorRow); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (resiNat != null) { |
|
|
|
boolean needUpdate = false; |
|
|
|
// 有这个人,也是导入的,那就要更新le
|
|
|
|
ArrayList<String> changedFieldNames = new ArrayList<>(); |
|
|
|
if (!name.equals(resiNat.getName())) { |
|
|
|
changedFieldNames.add("姓名"); |
|
|
|
resiNat.setName(name); |
|
|
|
needUpdate = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!natResult.equals(resiNat.getNatResult())) { |
|
|
|
changedFieldNames.add("检测结果"); |
|
|
|
resiNat.setNatResult(natResult); |
|
|
|
needUpdate = true; |
|
|
|
} |
|
|
|
|
|
|
|
// 检测地点和手机号先不提示,说需要提示再提示
|
|
|
|
if (!natAddress.equals(resiNat.getNatAddress())) { |
|
|
|
changedFieldNames.add("检测地点"); |
|
|
|
resiNat.setNatResult(natAddress); |
|
|
|
needUpdate = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!mobile.equals(resiNat.getMobile())) { |
|
|
|
changedFieldNames.add("手机号"); |
|
|
|
resiNat.setMobile(mobile); |
|
|
|
needUpdate = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (changedFieldNames.size() > 0) { |
|
|
|
String fieldsStr = String.join(",", changedFieldNames); |
|
|
|
String message = "该次核酸检测记录已存在,执行更新动作," + fieldsStr + "已成功更新"; |
|
|
|
IcNatImportExcelData.ErrorRow errorRow = new IcNatImportExcelData.ErrorRow(); |
|
|
|
errorRow.setName(name); |
|
|
|
errorRow.setMobile(mobile); |
|
|
|
errorRow.setIdCard(idCard); |
|
|
|
errorRow.setErrorInfo(message); |
|
|
|
errorRows.add(errorRow); |
|
|
|
} |
|
|
|
|
|
|
|
if (needUpdate) { |
|
|
|
resiNat.setUpdatedBy(currentUserId); |
|
|
|
resiNat.setUpdatedTime(new Date()); |
|
|
|
baseDao.updateById(resiNat); |
|
|
|
} |
|
|
|
|
|
|
|
// 还要创建关系
|
|
|
|
createNatRelation(resiNat.getId(), listener.getCurrentAgencyId(), listener.getCurrentAgencyPids()); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 执行新增操作
|
|
|
|
e.setIsResiUser(isResi(customerId, idCard)); |
|
|
|
e.setUserType("import"); |
|
|
|
|
|
|
|
baseDao.insert(e); |
|
|
|
|
|
|
|
// 还要创建关系
|
|
|
|
createNatRelation(e.getId(), listener.getCurrentAgencyId(), listener.getCurrentAgencyPids()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 是否是客户下的居民; |
|
|
|
* 0:否 |
|
|
|
* 1:是 |
|
|
|
* @param customerId |
|
|
|
* @param idCard |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String isResi(String customerId, String idCard) { |
|
|
|
LambdaQueryWrapper<IcResiUserEntity> query = new LambdaQueryWrapper(); |
|
|
|
query.eq(IcResiUserEntity::getCustomerId, customerId); |
|
|
|
query.eq(IcResiUserEntity::getIdCard, idCard); |
|
|
|
return icResiUserDao.selectCount(query) > 0 ? "1" : "0"; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param customerId |
|
|
|
* @param idCard |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public IcNatEntity getResiNat(String customerId, String idCard, Date natTime) { |
|
|
|
LambdaQueryWrapper<IcNatEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(IcNatEntity::getCustomerId, customerId); |
|
|
|
query.eq(IcNatEntity::getIdCard, idCard); |
|
|
|
query.eq(IcNatEntity::getNatTime, natTime); |
|
|
|
return baseDao.selectOne(query); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建nat关系 |
|
|
|
* @param natId |
|
|
|
* @param currentUserAgencyId |
|
|
|
*/ |
|
|
|
private void createNatRelation(String natId, String currentUserAgencyId, String agencyPids) { |
|
|
|
|
|
|
|
// 没有关系创建关系,有关系就跳过
|
|
|
|
LambdaQueryWrapper<IcNatRelationEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(IcNatRelationEntity::getIcNatId, natId); |
|
|
|
query.eq(IcNatRelationEntity::getAgencyId, currentUserAgencyId); |
|
|
|
if (icNatRelationDao.selectCount(query) > 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
IcNatRelationEntity relation = new IcNatRelationEntity(); |
|
|
|
relation.setAgencyId(currentUserAgencyId); |
|
|
|
relation.setPids(String.join(":", Arrays.asList(agencyPids, currentUserAgencyId))); |
|
|
|
relation.setIcNatId(natId); |
|
|
|
relation.setUserType("import"); |
|
|
|
icNatRelationDao.insert(relation); |
|
|
|
} |
|
|
|
} |
|
|
|