From 38b68edd726a1e25384c2b29230bdccfa78619e8 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Tue, 27 Sep 2022 13:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=94=E5=AF=B9=E6=A0=B8=E7=AE=97=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=9C=AA=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/tools/utils/YtHsResUtils.java | 4 +- .../epmet/constants/ImportTaskConstants.java | 5 + .../IcNatCompareRecordController.java | 84 ++++++++- .../IcTripReportRecordController.java | 1 + .../com/epmet/dao/IcNatCompareRecordDao.java | 4 + .../entity/IcNatCompareRecordEntity.java | 7 +- .../data/IcNatCompareRecordExcelData.java | 48 ++++++ ...IcNatCompareRecordExcelImportListener.java | 152 ++++++++++++++++ .../service/IcNatCompareRecordService.java | 3 + .../impl/IcNatCompareRecordServiceImpl.java | 163 ++++++++++++++++++ .../mapper/IcNatCompareRecordDao.xml | 15 +- 11 files changed, 472 insertions(+), 14 deletions(-) create mode 100644 epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatCompareRecordExcelData.java create mode 100644 epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatCompareRecordExcelImportListener.java diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java index 80bc4e76f0..dcde88f23f 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java @@ -3,7 +3,7 @@ package com.epmet.commons.tools.utils; import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.dto.result.YtHsjcResDTO; import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.exception.EpmetException; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; @@ -35,7 +35,7 @@ public class YtHsResUtils { return resultResult; } catch (Exception e) { log.error(String.format("烟台核算检测结果查询异常cardNo:%s,异常信息:%s", cardNo, e.getMessage())); - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "获取核算检测结果api异常"+e.getMessage()); } } } diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java index 58109b1b89..a8621ce09d 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java @@ -73,4 +73,9 @@ public interface ImportTaskConstants { * 社会组织 */ String IC_SOCIETY_ORG="ic_society_org"; + + /** + * 未做核酸比对 + */ + String IC_NAT_COMPARE_RECORD="ic_nat_compare_record"; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatCompareRecordController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatCompareRecordController.java index dfa3b097ad..0bce12ceda 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatCompareRecordController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatCompareRecordController.java @@ -6,26 +6,38 @@ import com.alibaba.excel.write.metadata.WriteSheet; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.MaskResponse; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.commons.tools.utils.DateUtils; -import com.epmet.commons.tools.utils.ExcelUtils; -import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.*; import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dto.IcNatCompareRecordDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; import com.epmet.dto.form.yqfk.IcNatCompareRecordPageFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.IcNatCompareRecordService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; import java.util.Date; +import java.util.UUID; /** @@ -37,10 +49,12 @@ import java.util.Date; @Slf4j @RestController @RequestMapping("icNatCompareRecord") -public class IcNatCompareRecordController { +public class IcNatCompareRecordController implements ResultDataResolver { @Autowired private IcNatCompareRecordService icNatCompareRecordService; + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; /** * 未做核酸比对-分页查询 @@ -97,4 +111,58 @@ public class IcNatCompareRecordController { } } + + /** + * 导入excel + * @return + */ + @NoRepeatSubmit + @PostMapping("import") + public Result importExcel(@LoginUser TokenDto tokenDto, @RequestPart("file") MultipartFile file) { + String userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); + + // 1.暂存文件 + String originalFilename = file.getOriginalFilename(); + String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); + + Path fileSavePath; + try { + Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat_compare_record", "import"); + fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName)); + } catch (IOException e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【未做核酸比对】创建临时存储文件失败:{}", errorMsg); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败"); + } + + InputStream is = null; + FileOutputStream os = null; + + try { + is = file.getInputStream(); + os = new FileOutputStream(fileSavePath.toString()); + IOUtils.copy(is, os); + } catch (Exception e) { + log.error("method exception", e); + } finally { + org.apache.poi.util.IOUtils.closeQuietly(is); + org.apache.poi.util.IOUtils.closeQuietly(os); + } + + // 2.生成导入任务记录 + ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); + importTaskForm.setOperatorId(userId); + importTaskForm.setBizType(ImportTaskConstants.IC_NAT_COMPARE_RECORD); + importTaskForm.setOriginFileName(originalFilename); + + ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException(commonServiceOpenFeignClient.createImportTask(importTaskForm), + ServiceConstant.EPMET_COMMON_SERVICE, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + "excel未做核酸比对导入文件错误", + "未做核酸比对导入文件失败"); + + // 3.执行导入 + icNatCompareRecordService.execAsyncExcelImport(fileSavePath, rstData.getTaskId(),tokenDto.getCustomerId(),tokenDto.getUserId()); + return new Result(); + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java index cfc1313c69..aea630040c 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java @@ -251,6 +251,7 @@ public class IcTripReportRecordController implements ResultDataResolver { * 导入excel * @return */ + @NoRepeatSubmit @PostMapping("import") public Result importExcel(@LoginUser TokenDto tokenDto, MultipartFile file) { String userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatCompareRecordDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatCompareRecordDao.java index b23eaf8ef1..ef0273fc0f 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatCompareRecordDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatCompareRecordDao.java @@ -5,6 +5,7 @@ import com.epmet.dto.IcNatCompareRecordDTO; import com.epmet.dto.form.yqfk.IcNatCompareRecordPageFormDTO; import com.epmet.entity.IcNatCompareRecordEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -23,4 +24,7 @@ public interface IcNatCompareRecordDao extends BaseDao * @return */ List pageList(IcNatCompareRecordPageFormDTO formDTO); + + + IcNatCompareRecordEntity selectByIdCard(@Param("customerId") String customerId, @Param("idCard")String idCard); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatCompareRecordEntity.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatCompareRecordEntity.java index 92885ecd58..0c18972d12 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatCompareRecordEntity.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcNatCompareRecordEntity.java @@ -42,7 +42,7 @@ public class IcNatCompareRecordEntity extends BaseEpmetEntity { private String isResiUser; /** - * 是本辖区的居民时候,ic_resi_user.id + * 是否客户下居民,ic_resi_user.id */ private String icResiUserId; @@ -60,5 +60,8 @@ public class IcNatCompareRecordEntity extends BaseEpmetEntity { * 检测地点:接口填入 */ private String natAddress; - + /** + * 联系地址:接口填入 + */ + private String contactAddress; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatCompareRecordExcelData.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatCompareRecordExcelData.java new file mode 100644 index 0000000000..26b8ecf8f0 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/data/IcNatCompareRecordExcelData.java @@ -0,0 +1,48 @@ +package com.epmet.excel.data; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Description + * @Author yzm + * @Date 2022/9/27 9:41 + */ +@Data +public class IcNatCompareRecordExcelData { + @NotBlank(message = "姓名为必填项") + @ExcelProperty("姓名") + private String name; + + @NotBlank(message = "身份证号为必填项") + @ExcelProperty("身份证号") + private String idCard; + + @NotBlank(message = "手机号为必填项") + @ExcelProperty("手机号") + private String mobile; + + @Data + public static class ErrorRow { + + @ExcelProperty("姓名") + @ColumnWidth(20) + private String name; + + @ColumnWidth(20) + @ExcelProperty("身份证号") + private String idCard; + + @ExcelProperty("手机号") + @ColumnWidth(20) + private String mobile; + + @ColumnWidth(60) + @ExcelProperty("错误信息") + private String errorInfo; + } +} + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatCompareRecordExcelImportListener.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatCompareRecordExcelImportListener.java new file mode 100644 index 0000000000..c501e92a19 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcNatCompareRecordExcelImportListener.java @@ -0,0 +1,152 @@ +package com.epmet.excel.handler; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.read.listener.ReadListener; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; +import com.epmet.commons.tools.dto.result.YtHsjcResDTO; +import com.epmet.commons.tools.dto.result.YtHsjcResDetailDTO; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.ValidateException; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.commons.tools.utils.ObjectUtil; +import com.epmet.commons.tools.utils.YtHsResUtils; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.entity.IcNatCompareRecordEntity; +import com.epmet.excel.data.IcNatCompareRecordExcelData; +import com.epmet.service.impl.IcNatCompareRecordServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @Description + * @Author yzm + * @Date 2022/9/27 9:42 + */ +@Slf4j +public class IcNatCompareRecordExcelImportListener implements ReadListener { + + /** + * 最大条数阈值 + */ + public static final int MAX_THRESHOLD = 200; + /** + * 当前操作用户 + */ + private CustomerStaffInfoCacheResult staffInfo; + private String customerId; + private IcNatCompareRecordServiceImpl icNatCompareRecordService; + /** + * 数据 + */ + private List datas = new ArrayList<>(); + + /** + * 错误项列表 + */ + private List errorRows = new ArrayList<>(); + private Date importTime; + private String importDate; + public IcNatCompareRecordExcelImportListener(String customerId, CustomerStaffInfoCacheResult staffInfo,String importDate,Date importTime, IcNatCompareRecordServiceImpl icNatCompareRecordService) { + this.customerId = customerId; + this.staffInfo = staffInfo; + this.icNatCompareRecordService = icNatCompareRecordService; + this.importDate=importDate; + this.importTime=importTime; + } + + + @Override + public void invoke(IcNatCompareRecordExcelData data, AnalysisContext analysisContext) { + try { + // log.warn("有数据吗?"+JSON.toJSONString(data)); + // 不能为空先校验数据 + ValidatorUtils.validateEntity(data); + // 去除空格 + ObjectUtil.objectToTrim(data); + IcNatCompareRecordEntity compareRecordEntity = ConvertUtils.sourceToTarget(data, IcNatCompareRecordEntity.class); + compareRecordEntity.setCustomerId(customerId); + compareRecordEntity.setLatestNatTime(null); + compareRecordEntity.setNatAddress(StrConstant.EPMETY_STR); + compareRecordEntity.setNatResult(StrConstant.EPMETY_STR); + // 调用烟台api获取核酸检测结果 + YtHsjcResDTO hsjcResDTO = YtHsResUtils.hsjc(data.getIdCard(), 1, 1); + if (null != hsjcResDTO && CollectionUtils.isNotEmpty(hsjcResDTO.getData()) && null != hsjcResDTO.getData().get(0)) { + YtHsjcResDetailDTO ytHsjcResDetailDTO = hsjcResDTO.getData().get(0); + String testTime = ytHsjcResDetailDTO.getTest_time(); + compareRecordEntity.setLatestNatTime(DateUtils.parse(testTime, DateUtils.DATE_PATTERN)); + compareRecordEntity.setNatAddress(StringUtils.isNotBlank(ytHsjcResDetailDTO.getSampling_org_pcr()) ? ytHsjcResDetailDTO.getSample_result_pcr() : StrConstant.EPMETY_STR); + + // "sample_result_pcr":"2",// 核酸检测结果 1:阳性,2:阴性 + String sample_result_pcr = ytHsjcResDetailDTO.getSample_result_pcr(); + if (NumConstant.ONE_STR.equals(sample_result_pcr)) { + compareRecordEntity.setNatResult(NumConstant.ONE_STR); + } else if (NumConstant.TWO_STR.equals(sample_result_pcr)) { + compareRecordEntity.setNatResult(NumConstant.ZERO_STR); + } + compareRecordEntity.setContactAddress(StringUtils.isNotBlank(ytHsjcResDetailDTO.getAddress()) ? ytHsjcResDetailDTO.getAddress() : StrConstant.EPMETY_STR); + } + datas.add(compareRecordEntity); + + if (datas.size() == MAX_THRESHOLD) { + execPersist(); + } + } catch (Exception e) { + String errorMsg = null; + if (e instanceof ValidateException) { + errorMsg = ((ValidateException) e).getMsg(); + } else if (e instanceof EpmetException) { + errorMsg = ((EpmetException) e).getMsg(); + } else { + errorMsg = "未知错误"; + log.error("【未做核酸比对导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); + } + IcNatCompareRecordExcelData.ErrorRow errorRow = new IcNatCompareRecordExcelData.ErrorRow(); + errorRow.setIdCard(data.getIdCard()); + errorRow.setName(data.getName()); + errorRow.setMobile(data.getMobile()); + errorRow.setErrorInfo(errorMsg); + errorRows.add(errorRow); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + // 最后几条达不到阈值,这里必须再调用一次 + execPersist(); + } + + + /** + * 执行持久化 + */ + private void execPersist() { + // ic_nat_compare_record、ic_nat_compare_rec_relation + try { + if (datas != null && datas.size() > 0) { + icNatCompareRecordService.batchPersist(datas, staffInfo, this); + } + } finally { + datas.clear(); + } + } + + + /** + * 获取错误行 + * + * @return + */ + public List getErrorRows() { + return errorRows; + } +} + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatCompareRecordService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatCompareRecordService.java index 29519c5ac7..9568107b1c 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatCompareRecordService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatCompareRecordService.java @@ -6,6 +6,8 @@ import com.epmet.dto.IcNatCompareRecordDTO; import com.epmet.dto.form.yqfk.IcNatCompareRecordPageFormDTO; import com.epmet.entity.IcNatCompareRecordEntity; +import java.nio.file.Path; + /** * 核算比对记录 * @@ -24,4 +26,5 @@ public interface IcNatCompareRecordService extends BaseService page(IcNatCompareRecordPageFormDTO formDTO); + void execAsyncExcelImport(Path fileSavePath, String taskId, String customerId, String userId); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatCompareRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatCompareRecordServiceImpl.java index 596ab8751f..3622f99782 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatCompareRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatCompareRecordServiceImpl.java @@ -1,21 +1,50 @@ package com.epmet.service.impl; +import com.alibaba.excel.EasyExcel; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; +import com.epmet.commons.tools.utils.*; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.IcNatCompareRecordDao; import com.epmet.dto.IcNatCompareRecordDTO; +import com.epmet.dto.IcResiUserDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; import com.epmet.dto.form.yqfk.IcNatCompareRecordPageFormDTO; +import com.epmet.dto.result.UploadImgResultDTO; import com.epmet.entity.IcNatCompareRecordEntity; +import com.epmet.excel.data.IcNatCompareRecordExcelData; +import com.epmet.excel.handler.IcNatCompareRecordExcelImportListener; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.feign.OssFeignClient; import com.epmet.service.IcNatCompareRecordService; +import com.epmet.service.IcResiUserService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.entity.ContentType; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.commons.CommonsMultipartFile; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Date; import java.util.List; +import java.util.UUID; /** * 核算比对记录 @@ -23,8 +52,14 @@ import java.util.List; * @author generator generator@elink-cn.com * @since v1.0.0 2022-09-26 */ +@Slf4j @Service public class IcNatCompareRecordServiceImpl extends BaseServiceImpl implements IcNatCompareRecordService { + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + @Autowired + private OssFeignClient ossFeignClient; + private CustomerStaffInfoCacheResult queryCurrentStaff(String customerId, String userId) { CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); @@ -52,6 +87,134 @@ public class IcNatCompareRecordServiceImpl extends BaseServiceImpl errorRows = listener.getErrorRows(); + + boolean failed = errorRows.size() > 0; + if (failed) { + // 生成并上传错误文件 + try { + // 文件生成 + Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat_compare_record", "import", "error_des"); + String fileName = UUID.randomUUID().toString().concat(".xlsx"); + errorDescFile = errorDescDir.resolve(fileName); + FileItemFactory factory = new DiskFileItemFactory(16, errorDescDir.toFile()); + FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, fileName); + OutputStream os = fileItem.getOutputStream(); + + EasyExcel.write(os, IcNatCompareRecordExcelData.ErrorRow.class).sheet("导入失败列表").doWrite(errorRows); + + // 文件上传oss + Result errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); + if (errorDesFileUploadResult.success()) { + errorDesFileUrl = errorDesFileUploadResult.getData().getUrl(); + } + } finally { + if (Files.exists(errorDescFile)) { + Files.delete(errorDescFile); + } + } + } + + ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); + importFinishTaskForm.setTaskId(importTaskId); + importFinishTaskForm.setProcessStatus(failed ? ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL : ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); + importFinishTaskForm.setOperatorId(userId); + importFinishTaskForm.setResultDesc(""); + importFinishTaskForm.setResultDescFilePath(errorDesFileUrl); + + Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); + if (!result.success()) { + log.error("【未做核酸比对】finishImportTask失败"); + } + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【未做核酸比对】出错:{}", errorMsg); + + ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); + importFinishTaskForm.setTaskId(importTaskId); + importFinishTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + importFinishTaskForm.setOperatorId(userId); + importFinishTaskForm.setResultDesc("导入失败"); + + Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); + if (!result.success()) { + log.error("【未做核酸比对】导入记录状态修改为'完成'失败"); + } + } finally { + // 删除临时文件 + if (Files.exists(filePath)) { + try { + Files.delete(filePath); + } catch (IOException e) { + log.error("method exception", e); + } + } + } + } + + + public IcNatCompareRecordEntity getByIdCard(String customerId, String idCard) { + return baseDao.selectByIdCard(customerId,idCard); + } + + public void batchPersist(List datas,CustomerStaffInfoCacheResult staffInfo, IcNatCompareRecordExcelImportListener listener) { + datas.forEach(entity -> { + try { + persisNat(entity, listener); + } catch (Exception exception) { + String errorMsg = ExceptionUtils.getErrorStackTrace(exception); + log.error(errorMsg); + + IcNatCompareRecordExcelData.ErrorRow errorRow = new IcNatCompareRecordExcelData.ErrorRow(); + errorRow.setName(entity.getName()); + errorRow.setMobile(entity.getMobile()); + errorRow.setIdCard(entity.getIdCard()); + errorRow.setErrorInfo("batchPersist未知系统错误"); + listener.getErrorRows().add(errorRow); + } + }); + } + + + @Transactional(rollbackFor = Exception.class) + public void persisNat(IcNatCompareRecordEntity data, IcNatCompareRecordExcelImportListener listener) { + //判断是否存在 + IcNatCompareRecordEntity existEntity=baseDao.selectByIdCard(data.getCustomerId(),data.getIdCard()); + if (null == existEntity) { + //1、不存在该身份证的基础记录,直接插入ic_nat_compare_record 、ic_nat_compare_rec_relation 插入记录 + IcNatCompareRecordEntity compareRecordEntity = ConvertUtils.sourceToTarget(data, IcNatCompareRecordEntity.class); + //查询是否本辖区居民 + IcResiUserDTO icResiUserDTO = SpringContextUtils.getBean(IcResiUserService.class).getByIdCard(data.getCustomerId(), data.getIdCard(), null); + compareRecordEntity.setIcResiUserId(null == icResiUserDTO ? StrConstant.EPMETY_STR : icResiUserDTO.getId()); + //是否客户下居民(0:否 1:是) + compareRecordEntity.setIsResiUser(StringUtils.isNotBlank(compareRecordEntity.getIcResiUserId()) ? NumConstant.ONE_STR : NumConstant.ZERO_STR); + // todo + }else{ + // todo + } + + + } } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatCompareRecordDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatCompareRecordDao.xml index b027b16fca..08dc3cc163 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatCompareRecordDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatCompareRecordDao.xml @@ -15,7 +15,7 @@ c.NAT_RESULT, ( CASE WHEN c.NAT_RESULT = '1' THEN '阳性' ELSE '阴性' END ) AS natResultDesc, c.IS_RESI_USER, - ( CASE WHEN c.IS_RESI_USER = '0' THEN '否' ELSE '是' END ) AS isResiUserDesc, + ( CASE WHEN r.IS_AGENCY_USER = '0' THEN '否' ELSE '是' END ) AS isResiUserDesc, C.MOBILE AS realMobile, C.ID_CARD AS realIdCard, r.STAFF_ID, @@ -35,7 +35,7 @@ AND r.CUSTOMER_ID = #{customerId} AND c.del_flag='0' - AND c.IS_RESI_USER = #{isResiUser} + AND r.IS_AGENCY_USER = #{isResiUser} AND c.ID_CARD LIKE CONCAT('%',#{idCard},'%') @@ -55,4 +55,15 @@ ORDER BY r.IMPORT_TIME DESC + + \ No newline at end of file