| | |
| | | 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.constants.BcDictionaryConstants; |
| | | import com.panzhihua.common.enums.*; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.model.vos.BcDictionaryVO; |
| | | 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.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * 不是固定的列只能手动处理 |
| | | */ |
| | | private void saveData() { |
| | | R<List<BcDictionaryVO>> dictionaryR = communityService.listDictionaryByKey(BcDictionaryConstants.FAMILY); |
| | | |
| | | Map<String,String> dictMap = dictionaryR.getData().stream().collect(Collectors.toMap(BcDictionaryVO::getDictName,BcDictionaryVO::getDictValue)); |
| | | // Map<String,Integer> dictMap = new HashMap<>(); |
| | | // for(BcDictionaryVO vo : dictionaryR.getData()){ |
| | | // dictMap.put(vo.getDictName(),Integer.valueOf(vo.getDictValue())); |
| | | // } |
| | | |
| | | |
| | | int index = 2; |
| | | try { |
| | | ArrayList<ComMngPopulationServeExcelVO> voList = Lists.newArrayList(); |
| | |
| | | vo.setName(oneData.get(0)); |
| | | if(StringUtils.isEmpty(oneData.get(1))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"+oneData.get(1)); |
| | | importErrorVO.setErrorMsg("身份证号不可为空,请填写身份证号"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | |
| | | //判断身份证号码位数 |
| | | if(oneData.get(1).length() != 18){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列"+oneData.get(1)); |
| | | importErrorVO.setErrorMsg("身份证号位数有误,请检查身份证号码是否正确"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | |
| | | } |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(2))){ |
| | | String nation = oneData.get(2); |
| | | if(!nation.contains("族")){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第3列"); |
| | | importErrorVO.setErrorMsg("您填写的民族格式有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | // String nation = oneData.get(2); |
| | | // if(!nation.contains("族")){ |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorPosition("第" + index + "行,第3列"); |
| | | // importErrorVO.setErrorMsg("您填写的民族格式有误"); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | // continue; |
| | | // } |
| | | vo.setNation(oneData.get(2)); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(3))){ |
| | | Integer isOk = PopulPoliticalOutlookEnum.getCodeByName(oneData.get(3)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第4列"); |
| | | importErrorVO.setErrorMsg("您填写的政治面貌有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setPoliticalOutlook(isOk); |
| | | vo.setPoliticalOutlook(PopulPoliticalOutlookEnum.getCodeByName(oneData.get(3))); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(4))){ |
| | | Integer isOk = PopulIsOkEnum.getCodeByName(oneData.get(4)); |
| | | Integer isOk = PopulHouseUseEnum.getCodeByName(oneData.get(4)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第5列"); |
| | |
| | | vo.setIsRent(isOk); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(5))){ |
| | | Integer isOk = PopulRelationEnum.getCodeByName(oneData.get(5)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第6列"); |
| | | importErrorVO.setErrorMsg("您填写的与户主关系有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | |
| | | String ra = convertRelation(oneData.get(5)); |
| | | |
| | | String relation = dictMap.get(ra); |
| | | if(StringUtils.isEmpty(relation)){ |
| | | vo.setRelationStr(ra); |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorPosition("第" + index + "行,第6列"); |
| | | // importErrorVO.setErrorMsg("您填写的与户主关系有误"); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | // continue; |
| | | }else{ |
| | | vo.setRelation(Integer.valueOf(relation)); |
| | | } |
| | | vo.setRelation(isOk); |
| | | |
| | | } |
| | | if(StringUtils.isEmpty(oneData.get(6))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | |
| | | } |
| | | vo.setHouseNo(oneData.get(10).trim()); |
| | | if(StringUtils.isNotEmpty(oneData.get(11))){ |
| | | vo.setPhone(oneData.get(11).trim()); |
| | | vo.setBuildPurpose(oneData.get(11).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(12))){ |
| | | vo.setNativePlace(oneData.get(12).trim()); |
| | | vo.setBuildArea(oneData.get(12).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(13))){ |
| | | Integer isOk = PopulCultureLevelEnum.getCodeByName(oneData.get(13)); |
| | | Integer isOk = PopulHouseStatusEnum.getCodeByName(oneData.get(13).trim()); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第14列"); |
| | | importErrorVO.setErrorMsg("您填写的文化程度有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setCultureLevel(isOk); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(14))){ |
| | | Integer isOk = PopulMarriageEnum.getCodeByName(oneData.get(14)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第14列"); |
| | | importErrorVO.setErrorMsg("您填写的婚姻状况有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setMarriage(isOk); |
| | | } |
| | | 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))){ |
| | | Integer isOk = PopulOutOrLocalEnum.getCodeByName(oneData.get(19)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第20列"); |
| | | importErrorVO.setErrorMsg("您填写的外地or本地有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setOutOrLocal(isOk); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(20))){ |
| | | Integer isOk = PopulHouseStatusEnum.getCodeByName(oneData.get(20)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第21列"); |
| | | importErrorVO.setErrorMsg("您填写的房屋状态有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | |
| | | } |
| | | vo.setHouseStatus(isOk); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(21))){ |
| | | Integer isOk = PopulHousePurposeEnum.getCodeByName(oneData.get(21)); |
| | | if(StringUtils.isNotEmpty(oneData.get(14))){ |
| | | Integer isOk = PopulHousePurposeEnum.getCodeByName(oneData.get(14).trim()); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第22列"); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第15列"); |
| | | importErrorVO.setErrorMsg("您填写的房屋用途有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setHousePurpose(isOk); |
| | | vo.setHousePurpose(PopulHousePurposeEnum.getCodeByName(oneData.get(14).trim())); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(22))){ |
| | | Integer isOk = PopulHouseControlStatusEnum.getCodeByName(oneData.get(22)); |
| | | if(StringUtils.isNotEmpty(oneData.get(15))){ |
| | | Integer isOk = PopulHouseControlStatusEnum.getCodeByName(oneData.get(15)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第23列"); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第16列"); |
| | | importErrorVO.setErrorMsg("您填写的管控状态有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setControlStatus(isOk); |
| | | vo.setHouseStatus(isOk); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(23))){ |
| | | Integer isOk = PopulIsOksEnum.getCodeByName(oneData.get(23)); |
| | | |
| | | if(StringUtils.isNotEmpty(oneData.get(16))){ |
| | | vo.setPhone(oneData.get(16).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(17))){ |
| | | vo.setNativePlace(oneData.get(17).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(18))){ |
| | | vo.setCultureLevel(PopulCultureLevelEnum.getCodeByName(oneData.get(18))); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(19))){ |
| | | String ma = convertMarriage(oneData.get(19)); |
| | | Integer isOk = PopulMarriageEnum.getCodeByName(ma); |
| | | if(isOk.equals(-1)){ |
| | | vo.setMarriageStr(ma); |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorPosition("第" + index + "行,第20列"); |
| | | // importErrorVO.setErrorMsg("您填写的婚姻状况有误"); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | // continue; |
| | | }else{ |
| | | vo.setMarriage(isOk); |
| | | } |
| | | |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(20))){ |
| | | vo.setHealthy(oneData.get(20).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(21))){ |
| | | vo.setWorkCompany(oneData.get(21).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(22))){ |
| | | Integer isOk = PopulOutOrLocalEnum.getCodeByName(oneData.get(22)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第23列"); |
| | | importErrorVO.setErrorMsg("您填写的是否是居住地有误"); |
| | | importErrorVO.setErrorMsg("您填写的外地or本地有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setIsResidence(isOk); |
| | | vo.setOutOrLocal(isOk); |
| | | } |
| | | for (int i = 24; i < headSize; i++) { |
| | | if(StringUtils.isNotEmpty(oneData.get(23))){ |
| | | vo.setCensusRegister(oneData.get(23).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(24))){ |
| | | vo.setRemark(oneData.get(24).trim()); |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(oneData.get(25))){ |
| | | vo.setIdCardPositive(oneData.get(25).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(26))){ |
| | | vo.setIdCardBack(oneData.get(26).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(27))){ |
| | | vo.setHouseHold(oneData.get(27).trim()); |
| | | } |
| | | for (int i = 28; i < headSize; i++) { |
| | | if (oneData.get(i) != null && oneData.get(i).equals("是")) { |
| | | vo.getUserTagStr().add(headData.get(i).substring(0,headData.get(i).indexOf("("))); |
| | | } |
| | |
| | | throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList)); |
| | | } |
| | | } |
| | | |
| | | private String convertMarriage(String ma) { |
| | | |
| | | if(Objects.equals("已",ma) || Objects.equals("一",ma)){ |
| | | ma = "已婚"; |
| | | }else if(Objects.equals("未",ma) || Objects.equals("未婚婚",ma)){ |
| | | ma = "未婚"; |
| | | }else if(Objects.equals("初",ma)){ |
| | | ma = "初婚"; |
| | | }else if(Objects.equals("再",ma)){ |
| | | ma = "再婚"; |
| | | }else if(Objects.equals("复",ma)){ |
| | | ma = "复婚"; |
| | | }else if(Objects.equals("丧",ma) || Objects.equals("丧偶偶",ma)){ |
| | | ma = "丧偶"; |
| | | }else if(Objects.equals("离",ma) || Objects.equals("离异",ma) || Objects.equals("离异婚",ma)){ |
| | | ma = "离婚"; |
| | | }else if(Objects.equals("分",ma)){ |
| | | ma = "分居"; |
| | | } |
| | | |
| | | return ma; |
| | | } |
| | | |
| | | private String convertRelation(String ra) { |
| | | if(ra.contains("户主")){ |
| | | ra = "户主"; |
| | | }else if(Objects.equals(ra,"女儿")){ |
| | | ra = "女"; |
| | | }else if(Objects.equals(ra,"儿子") || Objects.equals(ra,"儿")){ |
| | | ra = "子"; |
| | | }else if(Objects.equals(ra,"大女")){ |
| | | ra = "长女"; |
| | | }else if(Objects.equals(ra,"二女") || Objects.equals(ra,"此女")){ |
| | | ra = "次女"; |
| | | }else if(Objects.equals(ra,"二子")){ |
| | | ra = "次子"; |
| | | }else if(Objects.equals(ra,"长男") || ra.contains("长子")){ |
| | | ra = "长子"; |
| | | }else if(Objects.equals(ra,"非亲属") || ra.contains("女友") || ra.contains("女朋友") |
| | | || ra.contains("男友") || ra.contains("男朋友")){ |
| | | ra = "其他"; |
| | | }else if(Objects.equals(ra,"姐")){ |
| | | ra = "姐姐"; |
| | | }else if(Objects.equals(ra,"户主")){ |
| | | ra = "本人"; |
| | | }else if(Objects.equals(ra,"妻子") || Objects.equals(ra,"媳妇")){ |
| | | ra = "妻"; |
| | | }else if(Objects.equals(ra,"哥") || Objects.equals(ra,"哥哥")){ |
| | | ra = "兄"; |
| | | }else if(Objects.equals(ra,"丈夫")){ |
| | | ra = "夫"; |
| | | }else if(Objects.equals(ra,"丈母娘")){ |
| | | ra = "岳母"; |
| | | }else if(Objects.equals(ra,"继子") || Objects.equals(ra,"养子")){ |
| | | ra = "养子或继子"; |
| | | }else if(Objects.equals(ra,"继女") || Objects.equals(ra,"养女")){ |
| | | ra = "养女或继女"; |
| | | }else if(ra.contains("儿媳")||ra.contains("长媳")){ |
| | | ra = "儿媳"; |
| | | }else if(Objects.equals(ra,"三姨") || Objects.equals(ra,"姨姨")){ |
| | | ra = "姨母"; |
| | | }else if(Objects.equals(ra,"二外孙女")){ |
| | | ra = "外孙女"; |
| | | }else if(Objects.equals(ra,"外孙")){ |
| | | ra = "外孙子"; |
| | | }else if(Objects.equals(ra,"侄儿")){ |
| | | ra = "侄子"; |
| | | }else if(ra.contains("表")){ |
| | | ra = "表兄弟、表姐妹"; |
| | | }else if(Objects.equals(ra,"继父") || Objects.equals(ra,"养父")){ |
| | | ra = "继父或养父"; |
| | | }else if(Objects.equals(ra,"父")){ |
| | | ra = "父亲"; |
| | | }else if(Objects.equals(ra,"弟弟")){ |
| | | ra = "弟"; |
| | | }else if(Objects.equals(ra,"孙")){ |
| | | ra = "孙子"; |
| | | }else if(Objects.equals(ra,"孙媳妇") || Objects.equals(ra,"外孙媳妇")){ |
| | | ra = "孙媳妇或外孙媳妇"; |
| | | }else if(Objects.equals(ra,"妹")){ |
| | | ra = "妹妹"; |
| | | }else if(Objects.equals(ra,"祖父母")){ |
| | | ra = "祖父母或外祖父母"; |
| | | }else if(Objects.equals(ra,"姐妹") || Objects.equals(ra,"兄弟")){ |
| | | ra = "兄弟姐妹"; |
| | | }else if(Objects.equals(ra,"其他姐妹") || Objects.equals(ra,"其他兄弟")){ |
| | | ra = "其他兄弟姐妹"; |
| | | }else if(Objects.equals(ra,"奶奶")){ |
| | | ra = "祖母"; |
| | | }else if(Objects.equals(ra,"爷爷")){ |
| | | ra = "祖父"; |
| | | }else if(Objects.equals(ra,"爷爷")){ |
| | | ra = "祖父"; |
| | | }else if(ra.contains("堂")){ |
| | | ra = "堂兄弟、堂姐妹"; |
| | | } |
| | | |
| | | return ra; |
| | | } |
| | | } |