Browse Source

update

feature/yujt_vim
yujt 4 years ago
parent
commit
e023eded17
  1. 66
      epdc-cloud-vim-yushan/src/main/java/com/elink/esua/epdc/vaccine/vim/service/impl/VaccinationInfoServiceImpl.java

66
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<Vaccinati
public Result importManualScoreExcel(MultipartFile file) { public Result importManualScoreExcel(MultipartFile file) {
log.info("进入Excel数据导入"); log.info("进入Excel数据导入");
File f = StreamUtils.conversionFile(file); File f = StreamUtils.conversionFile(file);
StringBuilder checkInfo = new StringBuilder();
try { try {
//判断上传文件类型 //判断上传文件类型
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
@ -181,33 +180,41 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
List<VaccinationInfoAllExcel> addErrorList = new ArrayList<>(); List<VaccinationInfoAllExcel> addErrorList = new ArrayList<>();
// 记录单人最高剂次 // 记录单人最高剂次
Map<String, EpidemicUserInfoDTO> maxDoseMap = new HashMap<>(); Map<String, EpidemicUserInfoDTO> maxDoseMap = new HashMap<>();
// 检查重复数据,对旧数据进行覆盖
List<VaccinationInfoEntity> checkList;
log.info("准备进入Excel数据导入循环"); log.info("准备进入Excel数据导入循环");
List<VaccineDto> companyList = vaccineCompanyService.compantyList(); List<VaccineDto> companyList = vaccineCompanyService.compantyList();
List<VaccineDto> siteList = vaccinationSiteService.getSiteList(); List<VaccineDto> siteList = vaccinationSiteService.getSiteList();
// 校验疫苗生产商
String companyName;
// 校验疫苗接种点
String siteName;
List<EpidemicUserInfoEntity> allUserList = epidemicUserInfoDao.selectAllUserInfo(); List<EpidemicUserInfoEntity> allUserList = epidemicUserInfoDao.selectAllUserInfo();
List<String> allUserIdCards = allUserList.stream().map(EpidemicUserInfoEntity::getIdCard).collect(Collectors.toList()); List<String> allUserIdCards = allUserList.stream().map(EpidemicUserInfoEntity::getIdCard).collect(Collectors.toList());
VaccinationInfoAllExcel epidemicReportUserInfoAllExcel; VaccinationInfoAllExcel epidemicReportUserInfoAllExcel;
VaccinationInfoDTO vaccinationInfoDTO; VaccinationInfoDTO vaccinationInfoDTO;
VaccineDto vimCompanyOrSiteByExcel;
String idCard; String idCard;
Integer maxDose; Integer maxDose;
for (int i = 0; i < recordList.size(); i++) { for (int i = 0; i < recordList.size(); i++) {
epidemicReportUserInfoAllExcel = recordList.get(i); epidemicReportUserInfoAllExcel = recordList.get(i);
vaccinationInfoDTO = ConvertUtils.sourceToTarget(epidemicReportUserInfoAllExcel, VaccinationInfoDTO.class); vaccinationInfoDTO = ConvertUtils.sourceToTarget(epidemicReportUserInfoAllExcel, VaccinationInfoDTO.class);
// 校验是否存在空单元格(校验必填) // 校验是否存在空单元格(校验必填)
if (checkNullCell(epidemicReportUserInfoAllExcel)) { if (checkNullCell(epidemicReportUserInfoAllExcel)) {
checkInfo.append("第").append(i + 1).append("条、"); // checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("存在空单元格"); epidemicReportUserInfoAllExcel.setErrorInfo("存在空单元格");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
} }
idCard = epidemicReportUserInfoAllExcel.getIdentityNo(); idCard = epidemicReportUserInfoAllExcel.getIdentityNo();
// 人员校验 // 人员校验
if (!allUserIdCards.contains(idCard)) { if (!allUserIdCards.contains(idCard)) {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("查无此人"); epidemicReportUserInfoAllExcel.setErrorInfo("查无此人");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
@ -215,46 +222,39 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
// 校验身份证号是否合法 // 校验身份证号是否合法
if (StringUtils.isBlank(idCard) || idCard.length() != 18) { if (StringUtils.isBlank(idCard) || idCard.length() != 18) {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("身份证号不合法"); epidemicReportUserInfoAllExcel.setErrorInfo("身份证号不合法");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
} }
// 校验疫苗生产商 // 校验疫苗生产商
String companyName = epidemicReportUserInfoAllExcel.getCompanyName(); companyName = epidemicReportUserInfoAllExcel.getCompanyName();
if (StringUtils.isNotBlank(companyName)) { if (StringUtils.isNotBlank(companyName)) {
List<VaccineDto> company = companyList.stream().filter(item -> companyName.equals(item.getLabel())).collect(Collectors.toList()); vimCompanyOrSiteByExcel = filterCompanyOrSiteByExcel(companyList, companyName);
if (!company.isEmpty()) { if (null != vimCompanyOrSiteByExcel) {
epidemicReportUserInfoAllExcel.setCompanyId(company.get(0).getValue()); epidemicReportUserInfoAllExcel.setCompanyId(vimCompanyOrSiteByExcel.getValue());
maxDose = company.get(0).getMaxDose(); maxDose = vimCompanyOrSiteByExcel.getMaxDose();
} else { } else {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗生产商"); epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗生产商");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
} }
} else { } else {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗生产商"); epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗生产商");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
} }
// 校验疫苗接种点 // 校验疫苗接种点
String siteName = epidemicReportUserInfoAllExcel.getSiteName(); siteName = epidemicReportUserInfoAllExcel.getSiteName();
if (StringUtils.isNotBlank(siteName)) { if (StringUtils.isNotBlank(siteName)) {
List<VaccineDto> site = siteList.stream().filter(item -> siteName.equals(item.getLabel())).collect(Collectors.toList()); vimCompanyOrSiteByExcel = filterCompanyOrSiteByExcel(siteList, siteName);
if (!site.isEmpty()) { if (null != vimCompanyOrSiteByExcel) {
epidemicReportUserInfoAllExcel.setSiteId(site.get(0).getValue()); epidemicReportUserInfoAllExcel.setSiteId(vimCompanyOrSiteByExcel.getValue());
} else { } else {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗接种点"); epidemicReportUserInfoAllExcel.setErrorInfo("不存在的疫苗接种点");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
} }
} else { } else {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗接种点"); epidemicReportUserInfoAllExcel.setErrorInfo("未填写疫苗接种点");
addErrorList.add(epidemicReportUserInfoAllExcel); addErrorList.add(epidemicReportUserInfoAllExcel);
continue; continue;
@ -278,13 +278,11 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
addList.add(epidemicReportUserInfoAllExcel); addList.add(epidemicReportUserInfoAllExcel);
// 检查重复数据,对旧数据进行覆盖 // 检查重复数据,对旧数据进行覆盖
List<VaccinationInfoEntity> checkList = checkVaccination(vaccinationInfoDTO); checkList = checkVaccination(vaccinationInfoDTO);
if (!checkList.isEmpty()) { if (!checkList.isEmpty()) {
deleteIdCardArr.addAll(checkList.stream().map(VaccinationInfoEntity::getId).collect(Collectors.toList())); deleteIdCardArr.addAll(checkList.stream().map(VaccinationInfoEntity::getId).collect(Collectors.toList()));
} }
} }
log.info("循环结束,判断人员信息是否需要更新"); log.info("循环结束,判断人员信息是否需要更新");
List<String> idCards = new ArrayList<>(maxDoseMap.keySet()); List<String> idCards = new ArrayList<>(maxDoseMap.keySet());
@ -292,9 +290,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
if (!idCards.isEmpty()) { if (!idCards.isEmpty()) {
List<EpidemicUserInfoDTO> existUserList = epidemicUserInfoDao.selectByIdCards(idCards); List<EpidemicUserInfoDTO> existUserList = epidemicUserInfoDao.selectByIdCards(idCards);
EpidemicUserInfoDTO updateDto;
existUserList.forEach(item -> { for (EpidemicUserInfoDTO item : existUserList) {
EpidemicUserInfoDTO updateDto = new EpidemicUserInfoDTO(); updateDto = new EpidemicUserInfoDTO();
// 已经接种完的不需要处理,excel的剂次数据小于数据库时不需要处理,已经接种完的不需要处理 // 已经接种完的不需要处理,excel的剂次数据小于数据库时不需要处理,已经接种完的不需要处理
if (item.getVaccinationState() != NumConstant.TWO && item.getVaccinationNum() <= maxDoseMap.get(item.getIdCard()).getVaccinationNum()) { if (item.getVaccinationState() != NumConstant.TWO && item.getVaccinationNum() <= maxDoseMap.get(item.getIdCard()).getVaccinationNum()) {
@ -308,7 +306,7 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
} }
updateList.add(updateDto); updateList.add(updateDto);
} }
}); }
} }
log.info("需要更新的人员信息数量为:" + updateList.size()); log.info("需要更新的人员信息数量为:" + updateList.size());
@ -317,16 +315,13 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
if (!deleteIdCardArr.isEmpty()) { if (!deleteIdCardArr.isEmpty()) {
baseDao.deleteDistinctDose(deleteIdCardArr); baseDao.deleteDistinctDose(deleteIdCardArr);
} }
// 插入接种数据 // 插入接种数据
List<VaccinationInfoEntity> insertUserList = ConvertUtils.sourceToTarget(addList, VaccinationInfoEntity.class); List<VaccinationInfoEntity> insertUserList = ConvertUtils.sourceToTarget(addList, VaccinationInfoEntity.class);
insertBatch(insertUserList); insertBatch(insertUserList);
// 更新人员的接种信息 // 更新人员的接种信息
for (EpidemicUserInfoDTO dto : updateList) { for (EpidemicUserInfoDTO dto : updateList) {
epidemicUserInfoDao.updateVaccinationInfo(dto); epidemicUserInfoDao.updateVaccinationInfo(dto);
} }
// 批量插入错误数据 // 批量插入错误数据
List<VaccinationErrorEntity> insertErrorList = ConvertUtils.sourceToTarget(addErrorList, VaccinationErrorEntity.class); List<VaccinationErrorEntity> insertErrorList = ConvertUtils.sourceToTarget(addErrorList, VaccinationErrorEntity.class);
Integer insertNo = vaccinationErrorDao.getMaxInsertNo(); Integer insertNo = vaccinationErrorDao.getMaxInsertNo();
@ -336,10 +331,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
vaccinationErrorService.insertBatch(insertErrorList); vaccinationErrorService.insertBatch(insertErrorList);
// 提示报错信息 // 提示报错信息
if (checkInfo.length() > 0) { if (CollUtil.isNotEmpty(addErrorList)) {
return new Result().ok("数据异常,请下载Excel后重新导入!"); return new Result().ok("数据异常,请下载Excel后重新导入!");
} }
} catch (Exception e) { } catch (Exception e) {
return new Result().error("数据异常,解析Excel文件失败"); return new Result().error("数据异常,解析Excel文件失败");
} finally { } finally {
@ -349,6 +343,12 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
return new Result(); return new Result();
} }
private VaccineDto filterCompanyOrSiteByExcel(List<VaccineDto> companyOrSiteList, String companyOrSiteName) {
List<VaccineDto> company = companyOrSiteList.stream().filter(item -> item.getLabel().equals(companyOrSiteName)).collect(Collectors.toList());
return CollUtil.isNotEmpty(company) ? company.get(0) : null;
}
/** /**
* 校验是否存在空单元格 * 校验是否存在空单元格
* 校验必填项 (用户名身份证号接种剂次) * 校验必填项 (用户名身份证号接种剂次)

Loading…
Cancel
Save