From df654c8bbe24a659833d436a2e7e2013e3592142 Mon Sep 17 00:00:00 2001
From: manailin <261030956@qq.com>
Date: 星期三, 04 八月 2021 11:01:57 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/test' into test

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java |  106 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 66 insertions(+), 40 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
index ffe1f9c..14fd587 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
@@ -394,6 +394,37 @@
             areaPath.append(populationActVO.getProvinceName()).append(">").append(populationActVO.getCityName()).append(">").append(populationActVO.getDistrictName()).append(">");
             //处理实有人口信息
             Integer nub = 1;
+
+            //查询所有人口数据放入HashMap中
+            List<ComMngPopulationDO> populationList = this.baseMapper.selectList(null);
+            HashMap<String,Object> populationMap = new HashMap<>();
+            populationList.forEach(population -> {
+                String key = population.getCardNo();
+                populationMap.put(key,population);
+            });
+            //查询所有房屋信息放入到HashMap中
+            List<ComMngPopulationHouseDO> houseLists = comMngPopulationHouseDAO.selectList(null);
+            HashMap<String,Object> houseMap = new HashMap<>();
+            houseLists.forEach(house -> {
+                String key = house.getCommunityId() + house.getVillageId() + house.getFloor() + house.getUnitNo() + house.getHouseNo();
+                houseMap.put(key,house);
+            });
+
+            List<ComMngVillageDO> villageList = comActVillageDAO.selectList(null);
+            HashMap<String,Object> villageMap = new HashMap<>();
+            villageList.forEach(village -> {
+                String key = village.getCommunityId() + village.getAlley() + village.getHouseNum();
+                villageMap.put(key,village);
+            });
+
+            List<ComMngPopulationHouseUserDO> houseUserLists = comMngPopulationHouseUserDAO.selectList(null);
+            HashMap<String,Object> houseUserMap = new HashMap<>();
+            houseUserLists.forEach(houseUser -> {
+                String key = houseUser.getPopulId() + houseUser.getHouseId() + "";
+                houseUserMap.put(key,houseUser);
+            });
+
+
             for (ComMngPopulationServeExcelVO vo : list) {
                 if (vo.getDoorNo().contains("号")) {
                     vo.setDoorNo(vo.getDoorNo().replace("号",""));
@@ -409,13 +440,11 @@
                 }
                 log.info("开始查询小区街路巷是否存在");
                 //查询小区街路巷是否存在
-                ComMngVillageDO comMngVillageDO = comActVillageDAO.selectOne(new QueryWrapper<ComMngVillageDO>().eq("alley", vo.getRoad()).eq("house_num", vo.getDoorNo()).eq("community_id", communityId));
-                log.info("开始导入数据,行数:" + nub + "对象数据:" + vo.toString());
-                nub++;
-                log.info("街路巷对象:" + comMngVillageDO);
-                log.info("街路巷对象是否为空:" + ObjectUtils.isEmpty(comMngVillageDO));
-                log.info("街路巷对象是否为空2:" + (comMngVillageDO == null));
-                if (comMngVillageDO == null) {
+                ComMngVillageDO comMngVillageDO = null;
+                String villageKey = communityId + vo.getRoad() + vo.getDoorNo();
+                if(!isOnly(villageKey,villageMap)){
+                    comMngVillageDO = (ComMngVillageDO)villageMap.get(villageKey);
+                }else{
                     ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO();
                     BeanUtils.copyProperties(vo,mistake);
                     setMistake(mistake, vo);
@@ -434,11 +463,9 @@
 
                 log.info("开始查询房屋是否存在");
                 //先判断房屋是否存在
-                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) {
+                ComMngPopulationHouseDO populationHouseDO = null;
+                String houseKey = communityId + comMngVillageDO.getVillageId() + vo.getFloor() + vo.getUnitNo() + vo.getHouseNo();
+                if(isOnly(houseKey,houseMap)){
                     if(!houseList.isEmpty()){
                         for (ComMngPopulationHouseDO house:houseList) {
                             if(house.getVillageId().equals(comMngVillageDO.getVillageId()) && house.getCommunityId().equals(communityId)
@@ -454,8 +481,10 @@
                         populationHouseDO = savePopulationHouse(vo, comMngVillageDO, communityId, areaPath, populationActVO.getName());
                         houseList.add(populationHouseDO);
                     }
-                    vo.setHouseId(populationHouseDO.getId());
+                }else{
+                    populationHouseDO = (ComMngPopulationHouseDO)houseMap.get(houseKey);
                 }
+                vo.setHouseId(populationHouseDO.getId());
                 log.info("开始查询房屋是否存在完成");
 
                 if (StringUtils.isEmpty(vo.getName()) && StringUtils.isEmpty(vo.getCardNo())) {
@@ -466,39 +495,25 @@
                 //判断实有人口是否已存在
                 log.info("开始查询实有人口是否已存在");
                 ComMngPopulationDO populationDO = null;
-                List<ComMngPopulationDO> populationDOList = this.baseMapper.selectList(new QueryWrapper<ComMngPopulationDO>().lambda()
-                        .eq(ComMngPopulationDO::getCardNo, cardNoAES));
-                if (populationDOList.isEmpty()) {
+                String populationKey = vo.getCardNo();
+                if(!isOnly(populationKey,populationMap)){
+                    //存在实有人口信息,则更新
+                    populationDO = (ComMngPopulationDO)populationMap.get(populationKey);
+                    ComMngPopulationDO updatePopulationDO = updatePopulationDO(vo,populationDO,labelList);
+                    updateList.add(updatePopulationDO);
+                }else{
                     //不存在实有人口,则新增
                     populationDO = savePopulationDO(vo, populationActVO, comMngVillageDO,labelList);
                     saveList.add(populationDO);
-                } else {
-                    //存在则更新
-                    if(populationDOList.size() > 1){
-                        for (ComMngPopulationDO population:populationDOList) {
-                            if(population.getActId().equals(communityId)){
-                                populationDO = population;
-                                break;
-                            }
-                        }
-                        if(populationDO == null){
-                            populationDO = populationDOList.get(0);
-                        }
-                    }else{
-                        populationDO = populationDOList.get(0);
-                    }
-                    ComMngPopulationDO updatePopulationDO = updatePopulationDO(vo,populationDO,labelList);
-                    updateList.add(updatePopulationDO);
                 }
                 log.info("开始查询实有人口是否已存在完成");
 
                 log.info("开始查询实有人口房屋居住信息");
                 //处理实有人口房屋居住信息
                 if (populationDO != null) {
-                    ComMngPopulationHouseUserDO populationHouseUserDO = comMngPopulationHouseUserDAO.selectOne(new QueryWrapper<ComMngPopulationHouseUserDO>()
-                            .lambda().eq(ComMngPopulationHouseUserDO::getHouseId, populationHouseDO.getId())
-                            .eq(ComMngPopulationHouseUserDO::getPopulId, populationDO.getId()));
-                    if (populationHouseUserDO == null) {
+                    ComMngPopulationHouseUserDO populationHouseUserDO = null;
+                    String houseUserKey = populationDO.getId() + populationHouseDO.getId() + "";
+                    if(isOnly(houseUserKey,houseUserMap)){
                         populationHouseUserDO = new ComMngPopulationHouseUserDO();
                         populationHouseUserDO.setId(Snowflake.getId());
                         populationHouseUserDO.setHouseId(populationHouseDO.getId());
@@ -519,17 +534,18 @@
         log.info("开始执行数据库导入");
         if(!houseList.isEmpty()){
             log.info("执行数据库导入房屋");
-            comMngPopulationHouseService.saveBatch(houseList);
+            comMngPopulationHouseDAO.insertAll(houseList);
             log.info("执行数据库导入房屋完成");
         }
         if(!saveList.isEmpty()){
             log.info("执行数据库导入人口");
-            this.saveBatch(saveList);
+            this.baseMapper.insertAll(saveList);
             log.info("执行数据库导入人口完成");
         }
         if(!updateList.isEmpty()){
             log.info("执行数据库更新人口");
-            this.updateBatchById(updateList);
+            this.baseMapper.updateAll(updateList);
+//            this.updateBatchById(updateList);
             log.info("执行数据库更新人口完成");
         }
         if(!houseUserList.isEmpty()){
@@ -1978,4 +1994,14 @@
         mvo.setDeath(PopulOutOrLocalEnum.getCnDescByName(vo.getDeath()));
     }
 
+    /**
+     * 判重方法
+     * @param key   主键
+     * @param hashMap   数据集
+     * @return  存在即为false 不存在则为true
+     */
+    private boolean isOnly(String key,HashMap<String,Object> hashMap){
+        return ObjectUtils.isEmpty(hashMap.get(key));
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.7.1