| | |
| | | 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.ListUtils; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.common.utlis.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>(); |
| | | for (Map<Integer, String> oneData : list) { |
| | | ComMngPopulationServeExcelVO vo = new ComMngPopulationServeExcelVO(); |
| | | if(oneData.get(0) == null){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第1列"); |
| | | importErrorVO.setErrorMsg("名字不可为空,请填写姓名"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setName(oneData.get(0)); |
| | | 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){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"); |
| | | importErrorVO.setErrorMsg("身份证号位数有误,请检查身份证号码是否正确"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setCardNo(oneData.get(1)); |
| | | //根据身份证号码解析年龄以及性别 |
| | | //获取用户生日 |
| | | String birthday = vo.getCardNo().substring(6, 14); |
| | | //设置用户年龄 |
| | | vo.setAge(AgeUtils.getAgeFromBirthTime(birthday)); |
| | | //获取用户性别 |
| | | int sex = Integer.parseInt(vo.getCardNo().substring(16, 17)); |
| | | if(sex%2 == 1){ |
| | | vo.setSex(PopulSexEnum.nan.getCode()); |
| | | }else{ |
| | | vo.setSex(PopulSexEnum.nv.getCode()); |
| | | } |
| | | if(oneData.get(2) != null){ |
| | | vo.setNation(oneData.get(2)); |
| | | } |
| | | if(oneData.get(3) != null){ |
| | | vo.setPoliticalOutlook(PopulPoliticalOutlookEnum.getCodeByName(oneData.get(3))); |
| | | } |
| | | if(oneData.get(4) != null){ |
| | | vo.setIsRent(PopulIsOkEnum.getCodeByName(oneData.get(4))); |
| | | } |
| | | if(oneData.get(5) != null){ |
| | | vo.setRelation(PopulRelationEnum.getCodeByName(oneData.get(5))); |
| | | } |
| | | if(oneData.get(6) != null){ |
| | | vo.setRoad(oneData.get(6)); |
| | | } |
| | | if(oneData.get(7) != null){ |
| | | vo.setDoorNo(Integer.valueOf(oneData.get(7))); |
| | | } |
| | | if(oneData.get(8) != null){ |
| | | vo.setFloor(oneData.get(8)); |
| | | } |
| | | if(oneData.get(9) != null){ |
| | | vo.setUnitNo(Integer.valueOf(oneData.get(9))); |
| | | } |
| | | if(oneData.get(10) != null){ |
| | | vo.setHouseNo(Integer.valueOf(oneData.get(10).trim())); |
| | | } |
| | | if(oneData.get(11) != null){ |
| | | vo.setPhone(oneData.get(11)); |
| | | } |
| | | if(oneData.get(12) != null){ |
| | | vo.setNativePlace(oneData.get(12)); |
| | | } |
| | | if(oneData.get(13) != null){ |
| | | vo.setCultureLevel(PopulCultureLevelEnum.getCodeByName(oneData.get(13))); |
| | | } |
| | | if(oneData.get(14) != null){ |
| | | vo.setMarriage(PopulMarriageEnum.getCodeByName(oneData.get(14))); |
| | | } |
| | | if(oneData.get(15) != null){ |
| | | vo.setHealthy(oneData.get(15)); |
| | | } |
| | | if(oneData.get(16) != null){ |
| | | vo.setWorkCompany(oneData.get(16)); |
| | | } |
| | | //姓名和身份证都为空,为空户,无需操作,否则就解析年龄,性别,出生年月日 |
| | | if(StringUtils.isNotEmpty(oneData.get(0)) || StringUtils.isNotEmpty(oneData.get(1))){ |
| | | if(StringUtils.isEmpty(oneData.get(0))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第1列"); |
| | | importErrorVO.setErrorMsg("名字不可为空,请填写姓名"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setName(oneData.get(0)); |
| | | if(StringUtils.isEmpty(oneData.get(1))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"); |
| | | importErrorVO.setErrorMsg("身份证号不可为空,请填写身份证号"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | |
| | | if(oneData.get(17) != null && StringUtils.isNotEmpty(oneData.get(17))){ |
| | | String outOrLocal = oneData.get(17); |
| | | if(outOrLocal.equals(ComMngPopulationServeExcelVO.outOrLocal.bd)){ |
| | | vo.setOutOrLocal(1); |
| | | }else if(outOrLocal.equals(ComMngPopulationServeExcelVO.outOrLocal.wd)){ |
| | | vo.setOutOrLocal(2); |
| | | //判断身份证号码位数 |
| | | if(oneData.get(1).length() != 18){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"); |
| | | importErrorVO.setErrorMsg("身份证号位数有误,请检查身份证号码是否正确"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setCardNo(oneData.get(1)); |
| | | //根据身份证号码解析年龄以及性别 |
| | | //获取用户生日 |
| | | String birthday = vo.getCardNo().substring(6, 14); |
| | | if(StringUtils.isNotEmpty(birthday)){ |
| | | String year = birthday.substring(0,4); |
| | | String month = birthday.substring(4,6); |
| | | String day = birthday.substring(6,8); |
| | | vo.setBirthday(year + "-" + month + "-" + day); |
| | | } |
| | | //设置用户年龄 |
| | | // vo.setAge(AgeUtils.getAgeFromBirthTime(birthday)); |
| | | //获取用户性别 |
| | | int sex = Integer.parseInt(vo.getCardNo().substring(16, 17)); |
| | | if(sex%2 == 1){ |
| | | vo.setSex(PopulSexEnum.nan.getCode()); |
| | | }else{ |
| | | vo.setSex(PopulSexEnum.nv.getCode()); |
| | | } |
| | | } |
| | | if(oneData.get(18) != null){ |
| | | vo.setCensusRegister(oneData.get(18)); |
| | | if(StringUtils.isNotEmpty(oneData.get(2))){ |
| | | vo.setNation(oneData.get(2)); |
| | | } |
| | | if(oneData.get(19) != null){ |
| | | vo.setRemark(oneData.get(19)); |
| | | if(StringUtils.isNotEmpty(oneData.get(3))){ |
| | | vo.setPoliticalOutlook(PopulPoliticalOutlookEnum.getCodeByName(oneData.get(3))); |
| | | } |
| | | for (int i = 20; i < headSize; i++) { |
| | | if(StringUtils.isNotEmpty(oneData.get(4))){ |
| | | vo.setIsRent(PopulIsOkEnum.getCodeByName(oneData.get(4))); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(5))){ |
| | | vo.setRelation(PopulRelationEnum.getCodeByName(oneData.get(5))); |
| | | } |
| | | if(StringUtils.isEmpty(oneData.get(6))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第7列"); |
| | | importErrorVO.setErrorMsg("街路巷不可为空"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setRoad(oneData.get(6)); |
| | | if(StringUtils.isEmpty(oneData.get(7))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第8列"); |
| | | importErrorVO.setErrorMsg("小区号不可为空"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setDoorNo(oneData.get(7).trim()); |
| | | if(StringUtils.isEmpty(oneData.get(8))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第9列"); |
| | | importErrorVO.setErrorMsg("楼排号不可为空"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setFloor(oneData.get(8).trim()); |
| | | if(StringUtils.isEmpty(oneData.get(9))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第10列"); |
| | | importErrorVO.setErrorMsg("单元号不可为空"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setUnitNo(oneData.get(9).trim()); |
| | | if(StringUtils.isEmpty(oneData.get(10))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第11列"); |
| | | importErrorVO.setErrorMsg("户室不可为空"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setHouseNo(oneData.get(10).trim()); |
| | | if(StringUtils.isNotEmpty(oneData.get(11))){ |
| | | vo.setPhone(oneData.get(11).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(12))){ |
| | | vo.setNativePlace(oneData.get(12).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(13))){ |
| | | vo.setCultureLevel(PopulCultureLevelEnum.getCodeByName(oneData.get(13).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(14))){ |
| | | vo.setMarriage(PopulMarriageEnum.getCodeByName(oneData.get(14).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(15))){ |
| | | vo.setHealthy(oneData.get(15).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(16))){ |
| | | vo.setWorkCompany(oneData.get(16).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(17))){ |
| | | vo.setRemark(oneData.get(17).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(18))){ |
| | | vo.setCensusRegister(oneData.get(18).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(19))){ |
| | | vo.setOutOrLocal(PopulOutOrLocalEnum.getCodeByName(oneData.get(19).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(20))){ |
| | | vo.setHouseStatus(PopulHouseStatusEnum.getCodeByName(oneData.get(20).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(21))){ |
| | | vo.setHousePurpose(PopulHousePurposeEnum.getCodeByName(oneData.get(21).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(22))){ |
| | | vo.setControlStatus(PopulHouseControlStatusEnum.getCodeByName(oneData.get(22).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(23))){ |
| | | vo.setIsResidence(PopulIsOksEnum.getCodeByName(oneData.get(23).trim())); |
| | | } |
| | | for (int i = 24; i < headSize; i++) { |
| | | if (oneData.get(i) != null && oneData.get(i).equals("是")) { |
| | | vo.getUserTagStr().add(headData.get(i).substring(0,headData.get(i).indexOf("("))); |
| | | } |
| | | } |
| | | |
| | | //将重复的数据进行MD5加密实现去重 |
| | | String distinct = vo.getName() + vo.getCardNo() + vo.getRoad() + vo.getDoorNo() + vo.getFloor() + vo.getUnitNo() + vo.getHouseNo(); |
| | | try { |
| | | String distinctPass = PayUtil.MD5(distinct); |
| | | if(StringUtils.isNotEmpty(distinctPass)){ |
| | | vo.setDistinctPass(distinctPass); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("组装MD5加密字段失败,数据表格行数:" + index); |
| | | continue; |
| | | } |
| | | voList.add(vo); |
| | | index++; |
| | | } |
| | |
| | | // throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList)); |
| | | // } |
| | | //根据list中的IdCard城市来去重 |
| | | List<ComMngPopulationServeExcelVO> newVoList = voList.stream().filter(ListUtils.distinctByKey(ComMngPopulationServeExcelVO::getCardNo)).collect(Collectors.toList()); |
| | | List<ComMngPopulationServeExcelVO> newVoList = voList.stream().filter(ListUtils.distinctByKey(ComMngPopulationServeExcelVO::getDistinctPass)).collect(Collectors.toList()); |
| | | R r = communityService.listSavePopulationServeExcelVO(newVoList, communityId); |
| | | if (!R.isOk(r)) { |
| | | String errMsg = r.getMsg(); |
| | |
| | | importErrorVO.setErrorPosition("第" + index + "行"); |
| | | importErrorVO.setErrorMsg("数据格式有误,请检查文档内数据"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList)); |
| | | } |
| | | } |