From e4636b43d19c8f288962cd44c9d61ea89a9239fb Mon Sep 17 00:00:00 2001 From: DESKTOP-71BH0QO\L、ming <172680469@qq.com> Date: 星期日, 25 四月 2021 18:44:37 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 40 insertions(+), 8 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java index 36fd6b8..00b482f 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java +++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java @@ -2,6 +2,7 @@ import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import com.panzhihua.common.enums.PopulIsOkEnum; @@ -9,11 +10,13 @@ import com.panzhihua.common.enums.PopulSexEnum; import com.panzhihua.common.exceptions.ServiceException; import com.panzhihua.common.model.vos.R; +import com.panzhihua.common.model.vos.community.ComMngPopulationImportErrorVO; import com.panzhihua.common.model.vos.community.ComMngPopulationServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngVillageServeExcelVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.utlis.AgeUtils; import com.panzhihua.common.utlis.IdCardUtil; +import com.panzhihua.common.utlis.StringUtils; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,18 +85,37 @@ int index = 2; try { ArrayList<ComMngPopulationServeExcelVO> voList = Lists.newArrayList(); + List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>(); for (Map<Integer, String> oneData : list) { ComMngPopulationServeExcelVO vo = new ComMngPopulationServeExcelVO(); if(oneData.get(0) == null){ - throw new ServiceException("500", "名字不可为空:第" + index + "行,第1列"); + ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); + importErrorVO.setErrorPosition("第" + index + "行,第1列"); + importErrorVO.setErrorMsg("名字不可为空,请填写姓名"); + populationImportErrorVOList.add(importErrorVO); + index++; + continue; } vo.setName(oneData.get(0)); - if(oneData.get(1) == null){ - throw new ServiceException("500", "身份证号不可为空:第" + index + "行,第2列"); + if(StringUtils.isEmpty(oneData.get(1))){ + ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); + importErrorVO.setErrorPosition("第" + index + "行,第2列"); + importErrorVO.setErrorMsg("身份证号不可为空,请填写身份证号"); + populationImportErrorVOList.add(importErrorVO); + index++; + continue; } +// if(!IdCardUtil.identityValidator(oneData.get(1))){ +// throw new ServiceException("500", "身份证号格式错误:第" + index + "行,第2列"); +// } //判断身份证号码位数 if(oneData.get(1).length() != 18){ - throw new ServiceException("500", "身份证号位数不正确:第" + index + "行,第2列"); + ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); + importErrorVO.setErrorPosition("第" + index + "行,第2列"); + importErrorVO.setErrorMsg("身份证号位数有误,请检查身份证号码是否正确"); + populationImportErrorVOList.add(importErrorVO); + index++; + continue; } vo.setCardNo(oneData.get(1)); //根据身份证号码解析年龄以及性别 @@ -164,12 +186,22 @@ voList.add(vo); index++; } - R r = communityService.listSavePopulationServeExcelVO(voList, communityId); - if (!R.isOk(r)) { - throw new ServiceException(r.getMsg()); + if(populationImportErrorVOList.isEmpty()){ + R r = communityService.listSavePopulationServeExcelVO(voList, communityId); + if (!R.isOk(r)) { + throw new ServiceException(r.getMsg()); + } + }else{ + throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList)); } } catch (NumberFormatException e) { - throw new ServiceException("500", "填写数据格式错误:第" + index + "行" + e.getMessage()); + List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>(); + ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); + importErrorVO.setErrorPosition("第" + index + "行"); + importErrorVO.setErrorMsg("数据格式有误,请检查文档内数据"); + populationImportErrorVOList.add(importErrorVO); + index++; + throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList)); } } } -- Gitblit v1.7.1