From cdc087c78307586f6f5957cfa199baabe332d0b3 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期五, 21 一月 2022 16:16:36 +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 |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 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 2dd5ceb..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
@@ -507,6 +507,19 @@
             }
         }
 
+        if(comMngPopulationVO.getType()!=null){
+            switch (comMngPopulationVO.getType()){
+                case 1 : comMngPopulationVO.setAgeStart("80");
+                         comMngPopulationVO.setAgeEnd("89");
+                         break;
+                case 2 : comMngPopulationVO.setAgeStart("90");
+                         comMngPopulationVO.setAgeEnd("99");
+                         break;
+                case 3 : comMngPopulationVO.setAgeStart("100");
+                         break;
+            }
+        }
+
         if (StringUtils.isNotEmpty(comMngPopulationVO.getAgeStart())) {
             String ageStartTime = DateUtils.getDateFormatString(
                 DateUtils.yearAddNum(new Date(), -(Integer.parseInt(comMngPopulationVO.getAgeStart()))), "yyyy-MM-dd");
@@ -4466,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());
         // //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
@@ -4997,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());
@@ -7962,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