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) {
log.info("进入Excel数据导入");
File f = StreamUtils.conversionFile(file);
StringBuilder checkInfo = new StringBuilder();
try {
//判断上传文件类型
String originalFilename = file.getOriginalFilename();
@ -181,33 +180,41 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
List<VaccinationInfoAllExcel> addErrorList = new ArrayList<>();
// 记录单人最高剂次
Map<String, EpidemicUserInfoDTO> maxDoseMap = new HashMap<>();
// 检查重复数据,对旧数据进行覆盖
List<VaccinationInfoEntity> checkList;
log.info("准备进入Excel数据导入循环");
List<VaccineDto> companyList = vaccineCompanyService.compantyList();
List<VaccineDto> siteList = vaccinationSiteService.getSiteList();
// 校验疫苗生产商
String companyName;
// 校验疫苗接种点
String siteName;
List<EpidemicUserInfoEntity> allUserList = epidemicUserInfoDao.selectAllUserInfo();
List<String> 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<Vaccinati
// 校验身份证号是否合法
if (StringUtils.isBlank(idCard) || idCard.length() != 18) {
checkInfo.append("第").append(i + 1).append("条、");
epidemicReportUserInfoAllExcel.setErrorInfo("身份证号不合法");
addErrorList.add(epidemicReportUserInfoAllExcel);
continue;
}
// 校验疫苗生产商
String companyName = epidemicReportUserInfoAllExcel.getCompanyName();
companyName = epidemicReportUserInfoAllExcel.getCompanyName();
if (StringUtils.isNotBlank(companyName)) {
List<VaccineDto> 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<VaccineDto> 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<Vaccinati
addList.add(epidemicReportUserInfoAllExcel);
// 检查重复数据,对旧数据进行覆盖
List<VaccinationInfoEntity> checkList = checkVaccination(vaccinationInfoDTO);
checkList = checkVaccination(vaccinationInfoDTO);
if (!checkList.isEmpty()) {
deleteIdCardArr.addAll(checkList.stream().map(VaccinationInfoEntity::getId).collect(Collectors.toList()));
}
}
log.info("循环结束,判断人员信息是否需要更新");
List<String> idCards = new ArrayList<>(maxDoseMap.keySet());
@ -292,9 +290,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
if (!idCards.isEmpty()) {
List<EpidemicUserInfoDTO> 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<Vaccinati
}
updateList.add(updateDto);
}
});
}
}
log.info("需要更新的人员信息数量为:" + updateList.size());
@ -317,16 +315,13 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
if (!deleteIdCardArr.isEmpty()) {
baseDao.deleteDistinctDose(deleteIdCardArr);
}
// 插入接种数据
List<VaccinationInfoEntity> insertUserList = ConvertUtils.sourceToTarget(addList, VaccinationInfoEntity.class);
insertBatch(insertUserList);
// 更新人员的接种信息
for (EpidemicUserInfoDTO dto : updateList) {
epidemicUserInfoDao.updateVaccinationInfo(dto);
}
// 批量插入错误数据
List<VaccinationErrorEntity> insertErrorList = ConvertUtils.sourceToTarget(addErrorList, VaccinationErrorEntity.class);
Integer insertNo = vaccinationErrorDao.getMaxInsertNo();
@ -336,10 +331,9 @@ public class VaccinationInfoServiceImpl extends BaseVimCurdServiceImpl<Vaccinati
vaccinationErrorService.insertBatch(insertErrorList);
// 提示报错信息
if (checkInfo.length() > 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<Vaccinati
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