From 94c34f08015c3f5f4d839354958aea88b31473a0 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期五, 21 一月 2022 11:13:07 +0800
Subject: [PATCH] Merge branch 'test' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ into test

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java |   68 ++++++++++++++++++++++++++++++++++
 1 files changed, 68 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 7b7121a..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
@@ -4479,6 +4479,10 @@
     private ComMngPopulationDO updatePopulationDO(ComMngPopulationServeExcelVO vo, ComMngPopulationDO populationDO,
         Long communityId, Long userId) {
         BeanUtils.copyProperties(vo, populationDO);
+        Integer personType = vo.getPersonType();
+        if (nonNull(personType)) {
+            populationDO.setPersonType(personType.toString());
+        }
         // List<String> userTag = vo.getUserTagStr().stream().map(userTagStr ->
         // userTagStr.split("\\(")[0]).collect(Collectors.toList());
         // //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
@@ -5010,6 +5014,10 @@
         ComMngVillageDO comMngVillageDO, Long userId) {
         ComMngPopulationDO populationDO = new ComMngPopulationDO();
         BeanUtils.copyProperties(vo, populationDO);
+        Integer personType = vo.getPersonType();
+        if (nonNull(personType)) {
+            populationDO.setPersonType(personType.toString());
+        }
         populationDO.setId(Snowflake.getId());
         // List<String> userTag = vo.getUserTagStr().stream().map(userTagStr ->
         // userTagStr.split("\\(")[0]).collect(Collectors.toList());
@@ -7975,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