From e023eded17da561f7ba7a56a76ddd57055b60266 Mon Sep 17 00:00:00 2001 From: yujt Date: Mon, 10 May 2021 17:31:37 +0800 Subject: [PATCH] update --- .../impl/VaccinationInfoServiceImpl.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/epdc-cloud-vim-yushan/src/main/java/com/elink/esua/epdc/vaccine/vim/service/impl/VaccinationInfoServiceImpl.java b/epdc-cloud-vim-yushan/src/main/java/com/elink/esua/epdc/vaccine/vim/service/impl/VaccinationInfoServiceImpl.java index 41795f5..1a5a3d7 100644 --- a/epdc-cloud-vim-yushan/src/main/java/com/elink/esua/epdc/vaccine/vim/service/impl/VaccinationInfoServiceImpl.java +++ b/epdc-cloud-vim-yushan/src/main/java/com/elink/esua/epdc/vaccine/vim/service/impl/VaccinationInfoServiceImpl.java @@ -160,7 +160,6 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl addErrorList = new ArrayList<>(); // 记录单人最高剂次 Map maxDoseMap = new HashMap<>(); + + // 检查重复数据,对旧数据进行覆盖 + List checkList; + log.info("准备进入Excel数据导入循环"); List companyList = vaccineCompanyService.compantyList(); List siteList = vaccinationSiteService.getSiteList(); + // 校验疫苗生产商 + String companyName; + // 校验疫苗接种点 + String siteName; + List allUserList = epidemicUserInfoDao.selectAllUserInfo(); List allUserIdCards = allUserList.stream().map(EpidemicUserInfoEntity::getIdCard).collect(Collectors.toList()); VaccinationInfoAllExcel epidemicReportUserInfoAllExcel; VaccinationInfoDTO vaccinationInfoDTO; + VaccineDto vimCompanyOrSiteByExcel; String idCard; Integer maxDose; + for (int i = 0; i < recordList.size(); i++) { epidemicReportUserInfoAllExcel = recordList.get(i); vaccinationInfoDTO = ConvertUtils.sourceToTarget(epidemicReportUserInfoAllExcel, VaccinationInfoDTO.class); // 校验是否存在空单元格(校验必填) if (checkNullCell(epidemicReportUserInfoAllExcel)) { - checkInfo.append("第").append(i + 1).append("条、"); + // checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("存在空单元格"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; } - idCard = epidemicReportUserInfoAllExcel.getIdentityNo(); - // 人员校验 if (!allUserIdCards.contains(idCard)) { - checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("查无此人"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; @@ -215,46 +222,39 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl company = companyList.stream().filter(item -> companyName.equals(item.getLabel())).collect(Collectors.toList()); - if (!company.isEmpty()) { - epidemicReportUserInfoAllExcel.setCompanyId(company.get(0).getValue()); - maxDose = company.get(0).getMaxDose(); + vimCompanyOrSiteByExcel = filterCompanyOrSiteByExcel(companyList, companyName); + if (null != vimCompanyOrSiteByExcel) { + epidemicReportUserInfoAllExcel.setCompanyId(vimCompanyOrSiteByExcel.getValue()); + maxDose = vimCompanyOrSiteByExcel.getMaxDose(); } else { - checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗生产商"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; } } else { - checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗生产商"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; } - // 校验疫苗接种点 - String siteName = epidemicReportUserInfoAllExcel.getSiteName(); + siteName = epidemicReportUserInfoAllExcel.getSiteName(); if (StringUtils.isNotBlank(siteName)) { - List site = siteList.stream().filter(item -> siteName.equals(item.getLabel())).collect(Collectors.toList()); - if (!site.isEmpty()) { - epidemicReportUserInfoAllExcel.setSiteId(site.get(0).getValue()); + vimCompanyOrSiteByExcel = filterCompanyOrSiteByExcel(siteList, siteName); + if (null != vimCompanyOrSiteByExcel) { + epidemicReportUserInfoAllExcel.setSiteId(vimCompanyOrSiteByExcel.getValue()); } else { - checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗接种点"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; } } else { - checkInfo.append("第").append(i + 1).append("条、"); epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗接种点"); addErrorList.add(epidemicReportUserInfoAllExcel); continue; @@ -278,13 +278,11 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl checkList = checkVaccination(vaccinationInfoDTO); + checkList = checkVaccination(vaccinationInfoDTO); if (!checkList.isEmpty()) { deleteIdCardArr.addAll(checkList.stream().map(VaccinationInfoEntity::getId).collect(Collectors.toList())); } - } - log.info("循环结束,判断人员信息是否需要更新"); List idCards = new ArrayList<>(maxDoseMap.keySet()); @@ -292,9 +290,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl existUserList = epidemicUserInfoDao.selectByIdCards(idCards); - - existUserList.forEach(item -> { - EpidemicUserInfoDTO updateDto = new EpidemicUserInfoDTO(); + EpidemicUserInfoDTO updateDto; + for (EpidemicUserInfoDTO item : existUserList) { + updateDto = new EpidemicUserInfoDTO(); // 已经接种完的不需要处理,excel的剂次数据小于数据库时不需要处理,已经接种完的不需要处理 if (item.getVaccinationState() != NumConstant.TWO && item.getVaccinationNum() <= maxDoseMap.get(item.getIdCard()).getVaccinationNum()) { @@ -308,7 +306,7 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl insertUserList = ConvertUtils.sourceToTarget(addList, VaccinationInfoEntity.class); insertBatch(insertUserList); - // 更新人员的接种信息 for (EpidemicUserInfoDTO dto : updateList) { epidemicUserInfoDao.updateVaccinationInfo(dto); } - // 批量插入错误数据 List insertErrorList = ConvertUtils.sourceToTarget(addErrorList, VaccinationErrorEntity.class); Integer insertNo = vaccinationErrorDao.getMaxInsertNo(); @@ -336,10 +331,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl 0) { + if (CollUtil.isNotEmpty(addErrorList)) { return new Result().ok("数据异常,请下载Excel后重新导入!"); } - } catch (Exception e) { return new Result().error("数据异常,解析Excel文件失败"); } finally { @@ -349,6 +343,12 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl companyOrSiteList, String companyOrSiteName) { + List company = companyOrSiteList.stream().filter(item -> item.getLabel().equals(companyOrSiteName)).collect(Collectors.toList()); + return CollUtil.isNotEmpty(company) ? company.get(0) : null; + } + /** * 校验是否存在空单元格 * 校验必填项 (用户名、身份证号、接种剂次)