| | |
| | | public R listSavePopulation(List<ComMngPopulationServeExcelVO> list, Long communityId) throws Exception { |
| | | log.info("开始处理导入数据"); |
| | | List<ComMngPopulationMistakeExcelVO> mistakes = new ArrayList<>(); |
| | | try { |
| | | // List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>(); |
| | | //查询社区信息 |
| | | ComPopulationActVO populationActVO = comActDAO.getPopulationActById(communityId); |
| | | if(populationActVO == null){ |
| | | log.error("未查询到社区信息"); |
| | | return R.fail("未查询到社区信息"); |
| | | } |
| | | //查询该社区 |
| | | //查询社区信息 |
| | | ComPopulationActVO populationActVO = comActDAO.getPopulationActById(communityId); |
| | | if(populationActVO == null){ |
| | | log.error("未查询到社区信息"); |
| | | return R.fail("未查询到社区信息"); |
| | | } |
| | | //查询该社区 |
| | | // ComActDO comActDO = comActDAO.selectById(communityId); |
| | | //查询该社区的省市区地址 |
| | | //查询该社区的省市区地址 |
| | | // AreaAddressVO areaAddressVO = populationDAO.getAreaAddress(comActDO.getProvinceCode(), comActDO.getCityCode(), comActDO.getAreaCode()); |
| | | //查询社区上街道信息 |
| | | String streetName = populationActVO.getStreetName(); |
| | | //查询社区上街道信息 |
| | | String streetName = populationActVO.getStreetName(); |
| | | // if (comActDO.getStreetId() != null) { |
| | | // ComStreetDO streetDO = comStreetDAO.selectById(comActDO.getStreetId()); |
| | | // if (streetDO != null) { |
| | | // streetName = streetDO.getName(); |
| | | // } |
| | | // } |
| | | StringBuilder areaPath = new StringBuilder(); |
| | | areaPath.append(populationActVO.getProvinceName()).append(">").append(populationActVO.getCityName()).append(">").append(populationActVO.getDistrictName()).append(">"); |
| | | //处理实有人口信息 |
| | | for (ComMngPopulationServeExcelVO vo : list) { |
| | | if (vo.getDoorNo().contains("号")) { |
| | | vo.setDoorNo(vo.getDoorNo().replace("号","")); |
| | | } |
| | | if(vo.getFloor().contains("栋")){ |
| | | vo.setFloor(vo.getFloor().replace("栋","")); |
| | | } |
| | | if(vo.getUnitNo().contains("单元")){ |
| | | vo.setUnitNo(vo.getUnitNo().replace("单元","")); |
| | | } |
| | | if(vo.getHouseNo().contains("号")){ |
| | | vo.setHouseNo(vo.getHouseNo().replace("号","")); |
| | | } |
| | | //查询小区街路巷是否存在 |
| | | ComMngVillageDO comMngVillageDO = comActVillageDAO.selectOne(new QueryWrapper<ComMngVillageDO>().eq("alley", vo.getRoad()).eq("house_num", vo.getDoorNo()).eq("community_id", communityId)); |
| | | if (comMngVillageDO == null) { |
| | | StringBuilder areaPath = new StringBuilder(); |
| | | areaPath.append(populationActVO.getProvinceName()).append(">").append(populationActVO.getCityName()).append(">").append(populationActVO.getDistrictName()).append(">"); |
| | | //处理实有人口信息 |
| | | for (ComMngPopulationServeExcelVO vo : list) { |
| | | if (vo.getDoorNo().contains("号")) { |
| | | vo.setDoorNo(vo.getDoorNo().replace("号","")); |
| | | } |
| | | if(vo.getFloor().contains("栋")){ |
| | | vo.setFloor(vo.getFloor().replace("栋","")); |
| | | } |
| | | if(vo.getUnitNo().contains("单元")){ |
| | | vo.setUnitNo(vo.getUnitNo().replace("单元","")); |
| | | } |
| | | if(vo.getHouseNo().contains("号")){ |
| | | vo.setHouseNo(vo.getHouseNo().replace("号","")); |
| | | } |
| | | //查询小区街路巷是否存在 |
| | | ComMngVillageDO comMngVillageDO = comActVillageDAO.selectOne(new QueryWrapper<ComMngVillageDO>().eq("alley", vo.getRoad()).eq("house_num", vo.getDoorNo()).eq("community_id", communityId)); |
| | | if (comMngVillageDO == null) { |
| | | // ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); |
| | | // importErrorVO.setErrorMsg("街路巷或小区号不存在,请先在“小区管理”中添加该小区"); |
| | | // importErrorVO.setErrorPosition("街路巷:" + vo.getRoad() + ",小区号:" + vo.getDoorNo()); |
| | | // populationImportErrorVOList.add(importErrorVO); |
| | | // index++; |
| | | ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO(); |
| | | BeanUtils.copyProperties(vo,mistake); |
| | | setMistake(mistake, vo); |
| | | mistake.setMistake("街路巷或小区号不存在,请先在“小区管理”中添加该小区:街路巷:"+ vo.getRoad() +",小区号:" + vo.getDoorNo()); |
| | | mistakes.add(mistake); |
| | | continue; |
| | | } |
| | | ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO(); |
| | | BeanUtils.copyProperties(vo,mistake); |
| | | setMistake(mistake, vo); |
| | | mistake.setMistake("街路巷或小区号不存在,请先在“小区管理”中添加该小区:街路巷:"+ vo.getRoad() +",小区号:" + vo.getDoorNo()); |
| | | mistakes.add(mistake); |
| | | continue; |
| | | } |
| | | |
| | | StringBuilder address = new StringBuilder(); |
| | | address.append(populationActVO.getProvinceName()).append(populationActVO.getCityName()).append(populationActVO.getDistrictName()) |
| | | .append(streetName).append(comMngVillageDO.getAlley()).append(vo.getDoorNo()).append("号").append(vo.getFloor()).append("栋") |
| | | .append(vo.getUnitNo()).append("单元").append(vo.getHouseNo()).append("号"); |
| | | StringBuilder address = new StringBuilder(); |
| | | address.append(populationActVO.getProvinceName()).append(populationActVO.getCityName()).append(populationActVO.getDistrictName()) |
| | | .append(streetName).append(comMngVillageDO.getAlley()).append(vo.getDoorNo()).append("号").append(vo.getFloor()).append("栋") |
| | | .append(vo.getUnitNo()).append("单元").append(vo.getHouseNo()).append("号"); |
| | | |
| | | vo.setAddress(address.toString()); |
| | | vo.setAddress(address.toString()); |
| | | |
| | | //todo 后期优化改为批量 |
| | | //先判断房屋是否存在 |
| | | ComMngPopulationHouseDO populationHouseDO = comMngPopulationHouseDAO.selectOne(new QueryWrapper<ComMngPopulationHouseDO>().lambda() |
| | | .eq(ComMngPopulationHouseDO::getCommunityId, communityId).eq(ComMngPopulationHouseDO::getVillageId, comMngVillageDO.getVillageId()) |
| | | .eq(ComMngPopulationHouseDO::getFloor, vo.getFloor()).eq(ComMngPopulationHouseDO::getUnitNo, vo.getUnitNo()) |
| | | .eq(ComMngPopulationHouseDO::getHouseNo, vo.getHouseNo())); |
| | | if (populationHouseDO == null) { |
| | | //房屋信息不存在建立房屋信息 |
| | | populationHouseDO = savePopulationHouse(vo, comMngVillageDO, communityId, areaPath, populationActVO.getName()); |
| | | vo.setHouseId(populationHouseDO.getId()); |
| | | } |
| | | //todo 后期优化改为批量 |
| | | //先判断房屋是否存在 |
| | | ComMngPopulationHouseDO populationHouseDO = comMngPopulationHouseDAO.selectOne(new QueryWrapper<ComMngPopulationHouseDO>().lambda() |
| | | .eq(ComMngPopulationHouseDO::getCommunityId, communityId).eq(ComMngPopulationHouseDO::getVillageId, comMngVillageDO.getVillageId()) |
| | | .eq(ComMngPopulationHouseDO::getFloor, vo.getFloor()).eq(ComMngPopulationHouseDO::getUnitNo, vo.getUnitNo()) |
| | | .eq(ComMngPopulationHouseDO::getHouseNo, vo.getHouseNo())); |
| | | if (populationHouseDO == null) { |
| | | //房屋信息不存在建立房屋信息 |
| | | populationHouseDO = savePopulationHouse(vo, comMngVillageDO, communityId, areaPath, populationActVO.getName()); |
| | | vo.setHouseId(populationHouseDO.getId()); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(vo.getName()) && StringUtils.isEmpty(vo.getCardNo())) { |
| | | //空户处理完房屋信息,直接返回 |
| | | continue; |
| | | } |
| | | String cardNoAES = AESUtil.encrypt128(vo.getCardNo(), aesKey); |
| | | //判断实有人口是否已存在 |
| | | ComMngPopulationDO populationDO = null; |
| | | List<ComMngPopulationDO> populationDOList = this.baseMapper.selectList(new QueryWrapper<ComMngPopulationDO>().lambda() |
| | | .eq(ComMngPopulationDO::getCardNo, cardNoAES)); |
| | | if (StringUtils.isEmpty(vo.getName()) && StringUtils.isEmpty(vo.getCardNo())) { |
| | | //空户处理完房屋信息,直接返回 |
| | | continue; |
| | | } |
| | | String cardNoAES = AESUtil.encrypt128(vo.getCardNo(), aesKey); |
| | | //判断实有人口是否已存在 |
| | | ComMngPopulationDO populationDO = null; |
| | | List<ComMngPopulationDO> populationDOList = this.baseMapper.selectList(new QueryWrapper<ComMngPopulationDO>().lambda() |
| | | .eq(ComMngPopulationDO::getCardNo, cardNoAES)); |
| | | |
| | | if (populationDOList.isEmpty()) { |
| | | //不存在实有人口,则新增 |
| | | populationDO = savePopulationDO(vo, populationActVO, comMngVillageDO); |
| | | if (populationDOList.isEmpty()) { |
| | | //不存在实有人口,则新增 |
| | | populationDO = savePopulationDO(vo, populationActVO, comMngVillageDO); |
| | | // ComMngPopulationHouseUserDO comMngPopulationHouseUserDO = savePopulationHouseUser(vo, populationDO, populationHouseDO); |
| | | } else { |
| | | //如果存在人口信息,且是自用房,则更新人口默认的房屋信息 |
| | | } else { |
| | | //如果存在人口信息,且是自用房,则更新人口默认的房屋信息 |
| | | // if (vo.getIsRent() != null && vo.getIsRent().equals(PopulHouseUseEnum.SELF.getCode())) { |
| | | // populationDO = updatePopulationDO(vo, populationDO); |
| | | // } |
| | | populationDO = updatePopulationDO(vo, populationActVO, populationDOList.get(0)); |
| | | } |
| | | populationDO = updatePopulationDO(vo, populationActVO, populationDOList.get(0)); |
| | | } |
| | | |
| | | //处理实有人口房屋居住信息 |
| | | if (populationDO != null) { |
| | | ComMngPopulationHouseUserDO populationHouseUserDO = comMngPopulationHouseUserDAO.selectOne(new QueryWrapper<ComMngPopulationHouseUserDO>() |
| | | .lambda().eq(ComMngPopulationHouseUserDO::getHouseId, populationHouseDO.getId()) |
| | | .eq(ComMngPopulationHouseUserDO::getPopulId, populationDO.getId())); |
| | | if (populationHouseUserDO == null) { |
| | | populationHouseUserDO = new ComMngPopulationHouseUserDO(); |
| | | populationHouseUserDO.setId(Snowflake.getId()); |
| | | populationHouseUserDO.setHouseId(populationHouseDO.getId()); |
| | | populationHouseUserDO.setPopulId(populationDO.getId()); |
| | | populationHouseUserDO.setRelation(vo.getRelation()); |
| | | populationHouseUserDO.setRelationId(vo.getIsRent()); |
| | | populationHouseUserDO.setResidence(vo.getResidence()); |
| | | comMngPopulationHouseUserDAO.insert(populationHouseUserDO); |
| | | //处理实有人口房屋居住信息 |
| | | if (populationDO != null) { |
| | | ComMngPopulationHouseUserDO populationHouseUserDO = comMngPopulationHouseUserDAO.selectOne(new QueryWrapper<ComMngPopulationHouseUserDO>() |
| | | .lambda().eq(ComMngPopulationHouseUserDO::getHouseId, populationHouseDO.getId()) |
| | | .eq(ComMngPopulationHouseUserDO::getPopulId, populationDO.getId())); |
| | | if (populationHouseUserDO == null) { |
| | | populationHouseUserDO = new ComMngPopulationHouseUserDO(); |
| | | populationHouseUserDO.setId(Snowflake.getId()); |
| | | populationHouseUserDO.setHouseId(populationHouseDO.getId()); |
| | | populationHouseUserDO.setPopulId(populationDO.getId()); |
| | | populationHouseUserDO.setRelation(vo.getRelation()); |
| | | populationHouseUserDO.setRelationId(vo.getIsRent()); |
| | | populationHouseUserDO.setResidence(vo.getResidence()); |
| | | comMngPopulationHouseUserDAO.insert(populationHouseUserDO); |
| | | } |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.info("出现错误,错误原因:" + e.getMessage()); |
| | | } |
| | | |
| | | //如果有错误,返回错误 |
| | | //暂时注释,等客户完成任务需要恢复 |
| | | /*if(!populationImportErrorVOList.isEmpty()){ |