| | |
| | | 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.Objects; |
| | | 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++; |
| | |
| | | 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 = PopulHouseUseEnum.getCodeByName(oneData.get(4)); |
| | |
| | | } |
| | | vo.setIsRent(isOk); |
| | | } |
| | | //TODO 先存中文后期改为枚举 |
| | | 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 = oneData.get(5); |
| | | if(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,"非亲属")){ |
| | | 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 = "兄"; |
| | | } |
| | | vo.setRelation(isOk); |
| | | |
| | | |
| | | 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)); |
| | | } |
| | | |
| | | } |
| | | if(StringUtils.isEmpty(oneData.get(6))){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | |
| | | vo.setNativePlace(oneData.get(17).trim()); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(18))){ |
| | | Integer isOk = PopulCultureLevelEnum.getCodeByName(oneData.get(18)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第19列"); |
| | | importErrorVO.setErrorMsg("您填写的文化程度有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | } |
| | | vo.setCultureLevel(isOk); |
| | | vo.setCultureLevel(PopulCultureLevelEnum.getCodeByName(oneData.get(18))); |
| | | } |
| | | if(StringUtils.isNotEmpty(oneData.get(19))){ |
| | | Integer isOk = PopulMarriageEnum.getCodeByName(oneData.get(19)); |
| | | if(isOk.equals(-1)){ |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第20列"); |
| | | importErrorVO.setErrorMsg("您填写的婚姻状况有误"); |
| | | populationImportErrorVOList.add(importErrorVO); |
| | | index++; |
| | | continue; |
| | | String ma = oneData.get(19); |
| | | |
| | | if(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)){ |
| | | ma = "复婚"; |
| | | }else if(Objects.equals("丧",ma)){ |
| | | ma = "丧偶"; |
| | | }else if(Objects.equals("离",ma)){ |
| | | ma = "离婚"; |
| | | }else if(Objects.equals("分",ma)){ |
| | | ma = "分居"; |
| | | } |
| | | vo.setMarriage(isOk); |
| | | 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()); |