From 07a44db9ba0e4b28a04b6cb12c53885a26b879f0 Mon Sep 17 00:00:00 2001 From: DESKTOP-71BH0QO\L、ming <172680469@qq.com> Date: 星期二, 30 三月 2021 10:09:57 +0800 Subject: [PATCH] ADD:实有房屋excel导入 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java index 6437ed0..227a37a 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java @@ -108,20 +108,36 @@ @Override public R listSaveVillage(List<ComMngVillageServeExcelVO> list, Long communityId) { - //获取社区下所有的实有房屋(小区),打印已经存在的重复数据 + //思路:获取社区下所有的实有房屋(小区),打印已经存在的重复数据 List<ComMngVillageDO> comMngVillageDOs = comActVillageDAO.selectList(new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getCommunityId, communityId)); - List<String> alleyList = list.stream().map(vo -> vo.getAlley()).collect(Collectors.toList()); - List<Integer> houseNumList = list.stream().map(vo -> vo.getHouseNum()).collect(Collectors.toList()); - List<ComMngVillageDO> resultList = comMngVillageDOs.stream().filter(village -> alleyList.contains(village.getAlley()) && houseNumList.contains(village.getAlley())).collect(Collectors.toList()); - if (resultList != null && resultList.size() > 0) { - List<String> repeatList = resultList.stream().map(ComMngVillageDO::getAlley).collect(Collectors.toList()); - return R.fail("导入实有房屋,存在数据重复:" + repeatList.toArray()); + if (list.size() == 0) { + return R.fail("数据为空!"); } + int index = 2; + for (ComMngVillageServeExcelVO vo : list) { + if (vo.getHouseNum() == null) { + return R.fail("门牌号第" + index + "行为空!"); + } + if (vo.getAlley() == null) { + return R.fail("街路巷第" + index + "行为空!"); + } + //判断DB和exel数据重复判断 + boolean result = comMngVillageDOs.stream().allMatch(village -> village.getAlley().equals(vo.getAlley()) && village.getHouseNum().equals(vo.getHouseNum())); + if (result) { + return R.fail("导入街路巷已存在(" + vo.getAlley()+")"); + } + index++; + } + ComActDO comActDO = comActDAO.selectById(communityId); ArrayList<ComMngVillageDO> comMngVillageDOS = Lists.newArrayList(); - BeanUtils.copyProperties(list, comMngVillageDOS); - /*this.saveBatch(comMngCarDOS); - return R.ok("共计导入车辆数量:" + comMngCarDOS.size());*/ - System.out.println(comMngVillageDOS); - return null; + list.forEach(vo -> { + ComMngVillageDO comMngVillageDO = new ComMngVillageDO(); + BeanUtils.copyProperties(vo, comMngVillageDO); + comMngVillageDO.setCommunityId(comActDO.getCommunityId()); + comMngVillageDO.setStreetId(comActDO.getStreetId()); + comMngVillageDOS.add(comMngVillageDO); + }); + this.saveBatch(comMngVillageDOS); + return R.ok("共计导入实有房屋数量:" + comMngVillageDOS.size()); } } -- Gitblit v1.7.1