| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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)); |
| | | //根据身份证号码解析年龄以及性别 |
| | |
| | | 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)); |
| | | } |
| | | } |
| | | } |