From 6d5f67ea34ecafcb5c7266bccf32c7d98e597554 Mon Sep 17 00:00:00 2001
From: puhanshu <a9236326>
Date: 星期三, 19 一月 2022 18:15:07 +0800
Subject: [PATCH] 人员类型历史数据处理接口开发

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 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 468f3b1..6f673aa 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
@@ -7983,6 +7983,66 @@
         return R.ok(indexInfo);
     }
 
+    /**
+     * 历史数据人员类型填充
+     * @param list
+     * @param communityId
+     * @param userId
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R filledPopulationPersonType(List<ComMngPopulationServeExcelVO> list, Long communityId, Long userId) {
+        // 需要修改的人口集合
+        List<ComMngPopulationDO> updateList = new ArrayList<>();
+        log.info("开始处理导入数据");
+        List<ComMngPopulationMistakeExcelVO> mistakes = new ArrayList<>();
+        try {
+            // 查询所有人口数据放入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);
+            });
+            for (ComMngPopulationServeExcelVO vo : list) {
+                // 判断实有人口是否已存在
+                log.info("开始查询实有人口是否已存在");
+                ComMngPopulationDO populationDO = null;
+                String populationKey = vo.getCardNo();
+                if (!isOnly(populationKey, populationMap)) {
+                    // 存在实有人口信息,则更新人员类型
+                    populationDO = (ComMngPopulationDO)populationMap.get(populationKey);
+                    Integer personType = vo.getPersonType();
+                    if (nonNull(personType)) {
+                        populationDO.setPersonType(personType.toString());
+                    }
+                    populationDO.setUpdateBy(userId);
+                    updateList.add(populationDO);
+                } else {
+                    // 不存在实有人口,返回
+                    ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO();
+                    BeanUtils.copyProperties(vo, mistake);
+                    setMistake(mistake, vo);
+                    mistake.setMistake("人口信息不存在,请下载实有人口模板导入");
+                    mistakes.add(mistake);
+                }
+            }
+        } catch (Exception e) {
+            log.info("出现错误,错误原因:" + e.getMessage());
+        }
+        if (!updateList.isEmpty()) {
+            log.info("执行数据库更新人口");
+            this.baseMapper.updateAll(updateList);
+            log.info("数据库更新人口完成");
+        }
+        if (!mistakes.isEmpty()) {
+            log.info("返回错误数据");
+            return R.fail(mistakes);
+        }
+        return R.ok(mistakes);
+    }
+
     private void setMistake(ComMngPopulationMistakeExcelVO mvo, ComMngPopulationServeExcelVO vo) {
         mvo.setPoliticalOutlook(PopulPoliticalOutlookEnum.getCnDescByName(vo.getPoliticalOutlook()));
         mvo.setIsRent(PopulHouseUseEnum.getCnDescByName(vo.getIsRent()));

--
Gitblit v1.7.1