| | |
| | | package com.panzhihua.common.listen; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | 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.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.ComMngRealAssetsExcelVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.ListUtils; |
| | | import com.panzhihua.common.utlis.PayUtil; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @description: 实有人口导入监听 |
| | |
| | | @Slf4j |
| | | public class ComMngPopulationConfirmServeExcelListen extends AnalysisEventListener<Map<Integer, String>> { |
| | | |
| | | private CommunityService communityService; |
| | | |
| | | private Long communityId; |
| | | |
| | | private static int headSize = 0; |
| | | |
| | | private Map<Integer, String> headData; |
| | | |
| | | |
| | | public ComMngPopulationConfirmServeExcelListen(CommunityService communityService, Long communityId) { |
| | | this.communityService = communityService; |
| | | this.communityId = communityId; |
| | | } |
| | | |
| | | /** |
| | | * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 |
| | | */ |
| | | private static final int BATCH_COUNT = 5000; |
| | | private static int headSize = 0; |
| | | List<Map<Integer, String>> list = new ArrayList<Map<Integer, String>>(); |
| | | private CommunityService communityService; |
| | | private Long communityId; |
| | | private Map<Integer, String> headData; |
| | | public ComMngPopulationConfirmServeExcelListen(CommunityService communityService, Long communityId) { |
| | | this.communityService = communityService; |
| | | this.communityId = communityId; |
| | | } |
| | | |
| | | @Override |
| | | public void invoke(Map<Integer, String> data, AnalysisContext context) { |
| | |
| | | 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())); |
| | | // } |
| | | |
| | | 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 { |
| | |
| | | List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>(); |
| | | for (Map<Integer, String> oneData : list) { |
| | | ComMngPopulationServeExcelVO vo = new ComMngPopulationServeExcelVO(); |
| | | //姓名和身份证都为空,为空户,无需操作,否则就解析年龄,性别,出生年月日 |
| | | // 姓名和身份证都为空,为空户,无需操作,否则就解析年龄,性别,出生年月日 |
| | | if (StringUtils.isNotEmpty(oneData.get(0)) || StringUtils.isNotEmpty(oneData.get(1))) { |
| | | if (StringUtils.isEmpty(oneData.get(0))) { |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | |
| | | continue; |
| | | } |
| | | |
| | | //判断身份证号码位数 |
| | | // 判断身份证号码位数 |
| | | if (oneData.get(1).length() != 18) { |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第2列" + oneData.get(1)); |
| | |
| | | continue; |
| | | } |
| | | vo.setCardNo(oneData.get(1)); |
| | | //根据身份证号码解析年龄以及性别 |
| | | //获取用户生日 |
| | | // 根据身份证号码解析年龄以及性别 |
| | | // 获取用户生日 |
| | | String birthday = vo.getCardNo().substring(6, 14); |
| | | if (StringUtils.isNotEmpty(birthday)) { |
| | | String year = birthday.substring(0, 4); |
| | |
| | | String day = birthday.substring(6, 8); |
| | | vo.setBirthday(year + "-" + month + "-" + day); |
| | | } |
| | | // //设置用户年龄 |
| | | // vo.setAge(AgeUtils.getAgeFromBirthTime(birthday)); |
| | | //获取用户性别 |
| | | // //设置用户年龄 |
| | | // vo.setAge(AgeUtils.getAgeFromBirthTime(birthday)); |
| | | // 获取用户性别 |
| | | int sex = Integer.parseInt(vo.getCardNo().substring(16, 17)); |
| | | if (sex % 2 == 1) { |
| | | vo.setSex(PopulSexEnum.nan.getCode()); |
| | |
| | | } |
| | | } |
| | | 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))) { |
| | |
| | | } |
| | | if (StringUtils.isNotEmpty(oneData.get(5))) { |
| | | |
| | | // String ra = convertRelation(oneData.get(5)); |
| | | // String ra = convertRelation(oneData.get(5)); |
| | | |
| | | // String relation = dictMap.get(oneData.get(5)); |
| | | // 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)); |
| | | // } |
| | | // String relation = dictMap.get(oneData.get(5)); |
| | | // 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)); |
| | | // } |
| | | Integer isOk = PopulRelationEnum.getCodeByName(oneData.get(5)); |
| | | if (isOk.equals(-1)) { |
| | | // vo.setMarriageStr(ma); |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorPosition("第" + index + "行,第6列"); |
| | | // importErrorVO.setErrorMsg("您填写的与户主关系有误"); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | // continue; |
| | | // vo.setMarriageStr(ma); |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorPosition("第" + index + "行,第6列"); |
| | | // importErrorVO.setErrorMsg("您填写的与户主关系有误"); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | // continue; |
| | | vo.setRelation(6); |
| | | } else { |
| | | vo.setRelation(isOk); |
| | |
| | | vo.setCultureLevel(isOk); |
| | | } |
| | | if (StringUtils.isNotEmpty(oneData.get(19))) { |
| | | // String ma = convertMarriage(oneData.get(19)); |
| | | // String ma = convertMarriage(oneData.get(19)); |
| | | Integer isOk = PopulMarriageEnum.getCodeByName(oneData.get(19)); |
| | | if (isOk.equals(-1)) { |
| | | // vo.setMarriageStr(ma); |
| | | // vo.setMarriageStr(ma); |
| | | ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | importErrorVO.setErrorPosition("第" + index + "行,第20列"); |
| | | importErrorVO.setErrorMsg("您填写的婚姻状况有误"); |
| | |
| | | } |
| | | } |
| | | |
| | | //将重复的数据进行MD5加密实现去重 |
| | | String distinct = vo.getName() + vo.getCardNo() + vo.getRoad() + vo.getDoorNo() + vo.getFloor() + vo.getUnitNo() + vo.getHouseNo(); |
| | | // 将重复的数据进行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)) { |
| | |
| | | voList.add(vo); |
| | | index++; |
| | | } |
| | | //客户需要暂时注释,等客户处理完成需要恢复 |
| | | // 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)); |
| | | // } |
| | | //根据list中的IdCard城市来去重 |
| | | List<ComMngPopulationServeExcelVO> newVoList = voList.stream().filter(ListUtils.distinctByKey(ComMngPopulationServeExcelVO::getDistinctPass)).collect(Collectors.toList()); |
| | | // 客户需要暂时注释,等客户处理完成需要恢复 |
| | | // 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)); |
| | | // } |
| | | // 根据list中的IdCard城市来去重 |
| | | List<ComMngPopulationServeExcelVO> newVoList = |
| | | voList.stream().filter(ListUtils.distinctByKey(ComMngPopulationServeExcelVO::getDistinctPass)) |
| | | .collect(Collectors.toList()); |
| | | R r = communityService.listSavePopulationConfirm(newVoList, communityId); |
| | | if (!R.isOk(r)) { |
| | | String errMsg = r.getMsg(); |
| | | List<ComMngPopulationImportErrorVO> errorList = JSON.parseArray(errMsg, ComMngPopulationImportErrorVO.class); |
| | | List<ComMngPopulationImportErrorVO> errorList = |
| | | JSON.parseArray(errMsg, ComMngPopulationImportErrorVO.class); |
| | | if (!errorList.isEmpty()) { |
| | | populationImportErrorVOList.addAll(errorList); |
| | | } |
| | |
| | | ra = "次子"; |
| | | } else if (Objects.equals(ra, "长男") || ra.contains("长子")) { |
| | | ra = "长子"; |
| | | } else if (Objects.equals(ra, "非亲属") || ra.contains("女友") || ra.contains("女朋友") |
| | | || ra.contains("男友") || ra.contains("男朋友")) { |
| | | } else if (Objects.equals(ra, "非亲属") || ra.contains("女友") || ra.contains("女朋友") || ra.contains("男友") |
| | | || ra.contains("男朋友")) { |
| | | ra = "其他"; |
| | | } else if (Objects.equals(ra, "姐")) { |
| | | ra = "姐姐"; |