From 90de589a0964981f05b1571e441110130f35f4b8 Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期五, 18 二月 2022 11:01:59 +0800
Subject: [PATCH] Merge branch 'volunteer_lyq' into 'dev'

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java
index 1f1f1b0..ae15670 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java
@@ -12,6 +12,7 @@
 import com.google.common.collect.Lists;
 import com.panzhihua.common.model.dtos.community.OperationDetailDTO;
 import com.panzhihua.common.model.dtos.community.reserve.*;
+import com.panzhihua.common.model.helper.AESUtil;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.ComActReserveIndexVo;
 import com.panzhihua.common.model.vos.community.bigscreen.IndexBackReserve;
@@ -19,6 +20,7 @@
 import com.panzhihua.common.model.vos.community.questnaire.QuestnaiteSubSelectionVO;
 import com.panzhihua.common.model.vos.community.questnaire.QuestnaiteSubVO;
 import com.panzhihua.common.model.vos.community.reserve.*;
+import com.panzhihua.common.utlis.Snowflake;
 import com.panzhihua.common.utlis.StringUtils;
 import com.panzhihua.service_community.dao.ComActReserveMapper;
 import com.panzhihua.service_community.dao.ComActReserveSubMapper;
@@ -35,6 +37,7 @@
 import com.panzhihua.service_community.service.ComActReserveSubSelectionService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -45,12 +48,17 @@
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -79,12 +87,23 @@
     private ComActReserveSubSelectionService comActReserveSubSelectionService;
     @Resource
     private ComActReserveRecordService comActReserveRecordService;
+    @Resource
+    private ComMngPopulationDAO comMngPopulationDAO;
+    @Resource
+    private ComMngPopulationHouseDAO comMngPopulationHouseDAO;
+    @Resource
+    private ComMngPopulationCommunityTagsDAO comMngPopulationCommunityTagsDAO;
+    @Resource
+    private ComMngPopulationHouseUserDAO comMngPopulationHouseUserDAO;
+    @Value("${domain.aesKey:}")
+    private String aesKey;
 
     private final static String COMMIT="用户已提交";
     @Override
     @Transactional
     public R commit(ComActReserveCommitVO comActReserveCommitVO) {
         if(comActReserveCommitVO!=null){
+            ComMngPopulationHouseDO comMngPopulationHouseDO=new ComMngPopulationHouseDO();
             Long userId=comActReserveCommitVO.getUserId();
             Date nowDate=DateUtil.date();
             //查询预约登记记录
@@ -99,7 +118,10 @@
                         return R.fail("预约已上限");
                     }
                 }
-
+                if(comActReserveCommitVO.getRecordId()!=null){
+                    comActReserveRecordMapper.deleteById(comActReserveCommitVO.getRecordId());
+                    comActReserveDO.setJoinCount(comActReserveDO.getJoinCount()-1);
+                }
                 List<ComActReserveRecordDO> list=comActReserveRecordMapper.selectList(new QueryWrapper<ComActReserveRecordDO>().eq("reserve_id",comActReserveCommitVO.getId()).eq("user_id",comActReserveCommitVO.getUserId()).in("status",1,2,3));
                 if(!list.isEmpty()&&list.size()>1&&comActReserveDO.getIsRepeat()==ComActReserveDO.isRepeat.no){
                     return R.fail("提交失败,不可重复预约");
@@ -107,6 +129,9 @@
                 else {
                     List<QuestnaiteSubVO> questnaiteSubVOS = JSON.parseArray(comActReserveCommitVO.getJsonObject(),QuestnaiteSubVO.class);
                     if(!questnaiteSubVOS.isEmpty()){
+                        String idCard="";
+                        String houseId="";
+                        String phone="";
                         Long questId=comActReserveCommitVO.getId();
                         List<ComActReserveAnswerContentDO> answerContentList=new ArrayList<>();
                         for(QuestnaiteSubVO questnaiteSub:questnaiteSubVOS){
@@ -164,9 +189,10 @@
                                     answerContentDO.setAnswerContent(subSelectionDO.getContent());
                                     answerContentList.add(answerContentDO);
                                 }
-                            }else{
+                            }
+                            else{
                                 //文字描述不做处理
-                                if(!questnaiteSub.getType().equals(QuestnaiteSubVO.type.describe)){
+                                if(!questnaiteSub.getType().equals(QuestnaiteSubVO.type.describe)&&!questnaiteSub.getType().equals(QuestnaiteSubVO.type.address)){
                                     //问答题处理
                                     String values = questnaiteSub.getValues();
                                     ComActReserveAnswerContentDO answerContentDO = new ComActReserveAnswerContentDO();
@@ -178,9 +204,71 @@
                                     answerContentDO.setAnswerContent(values);
                                     answerContentList.add(answerContentDO);
                                 }
+                                if(questnaiteSub.getType().equals(QuestnaiteSubVO.type.card)){
+                                    idCard=questnaiteSub.getValues();
+                                }
+                                if(questnaiteSub.getType().equals(QuestnaiteSubVO.type.phone)){
+                                    phone=questnaiteSub.getValues();
+                                }
+                                if(questnaiteSub.getType().equals(QuestnaiteSubVO.type.address)){
+                                    houseId=questnaiteSub.getValues();
+                                    comMngPopulationHouseDO=comMngPopulationHouseDAO.selectById(houseId);
+                                    ComActReserveAnswerContentDO answerContentDO = new ComActReserveAnswerContentDO();
+                                    answerContentDO.setUserId(userId);
+                                    answerContentDO.setCreateAt(nowDate);
+                                    answerContentDO.setCreateBy(userId);
+                                    answerContentDO.setReserveSubId(queSubId);
+                                    answerContentDO.setType(2);
+                                    if(comMngPopulationHouseDO!=null){
+                                        answerContentDO.setAnswerContent(comMngPopulationHouseDO.getAddress());
+                                    }
+                                    else {
+                                        answerContentDO.setAnswerContent("");
+                                    }
+                                    answerContentList.add(answerContentDO);
+                                }
                             }
                         }
                         if(!answerContentList.isEmpty()){
+                            //判断实有人口情况
+                            if(StringUtils.isNotEmpty(idCard)&&StringUtils.isNotEmpty(houseId)){
+                                Integer count=comMngPopulationDAO.selectCount(new QueryWrapper<ComMngPopulationDO>().lambda().eq(ComMngPopulationDO::getCardNoStr,idCard));
+                                if(count==0){
+                                    ComMngPopulationDO comMngPopulationDO=savePopulation(idCard);
+                                    if(comMngPopulationHouseDO!=null){
+                                        comMngPopulationDO.setId(Snowflake.getId());
+                                        comMngPopulationDO.setAddress(comMngPopulationHouseDO.getAddress());
+                                        comMngPopulationDO.setActId(comMngPopulationHouseDO.getCommunityId());
+                                        comMngPopulationDO.setStreetId(comMngPopulationHouseDO.getStreetId());
+                                        comMngPopulationDO.setVillageId(comMngPopulationHouseDO.getVillageId());
+                                        comMngPopulationDO.setHouseId(comMngPopulationHouseDO.getId());
+                                        comMngPopulationDO.setOutOrLocal(1);
+                                        comMngPopulationDO.setPhone(phone);
+                                        comMngPopulationDO.setName(comActReserveCommitVO.getName());
+                                        comMngPopulationDO.setRoad(comMngPopulationHouseDO.getAlley());
+                                        comMngPopulationDO.setDoorNo(comMngPopulationHouseDO.getHouseNum());
+                                        comMngPopulationDO.setFloor(comMngPopulationHouseDO.getFloor());
+                                        comMngPopulationDO.setUnitNo(comMngPopulationHouseDO.getUnitNo());
+                                        comMngPopulationDO.setHouseNo(comMngPopulationHouseDO.getHouseNo());
+                                        comMngPopulationDAO.insert(comMngPopulationDO);
+                                        ComMngPopulationCommunityTagsDO comMngPopulationCommunityTagsDO=new ComMngPopulationCommunityTagsDO();
+                                        comMngPopulationCommunityTagsDO.setCommunityId(comMngPopulationDO.getActId());
+                                        comMngPopulationCommunityTagsDO.setPopulationId(comMngPopulationDO.getId());
+                                        comMngPopulationCommunityTagsDO.setId(Snowflake.getId());
+                                        comMngPopulationCommunityTagsDO.setCreateAt(new Date());
+                                        comMngPopulationCommunityTagsDAO.insert(comMngPopulationCommunityTagsDO);
+                                        ComMngPopulationHouseUserDO comMngPopulationHouseUserDO=new ComMngPopulationHouseUserDO();
+                                        comMngPopulationHouseUserDO.setId(Snowflake.getId());
+                                        comMngPopulationHouseUserDO.setPopulId(comMngPopulationDO.getId());
+                                        comMngPopulationHouseUserDO.setHouseId(Long.parseLong(houseId));
+                                        comMngPopulationHouseUserDO.setRelation(1);
+                                        comMngPopulationHouseUserDO.setRelationId(1);
+                                        comMngPopulationHouseUserDO.setResidence(1);
+                                        comMngPopulationHouseUserDO.setCreateAt(new Date());
+                                        comMngPopulationHouseUserDAO.insert(comMngPopulationHouseUserDO);
+                                    }
+                                }
+                            }
                             //更新回答用户数量
                             Integer joinCount = comActReserveDO.getJoinCount();
                             comActReserveDO.setJoinCount(joinCount != null ? joinCount + 1 : 1);
@@ -776,6 +864,28 @@
         return null;
     }
 
+    public ComMngPopulationDO savePopulation(String idCard){
+        ComMngPopulationDO comMngPopulationDO=new ComMngPopulationDO();
+        comMngPopulationDO.setDeath("1");
+        comMngPopulationDO.setCardNoStr(idCard);
+        comMngPopulationDO.setCardNo(idCard);
+        comMngPopulationDO.setSex(getSex(idCard));
+        comMngPopulationDO.setBirthday(getBirthday(idCard));
+        return comMngPopulationDO;
+    }
+    public Integer getSex(String idCard){
+        char c = idCard.charAt(idCard.length() - 2);
+        Integer gender = Integer.parseInt(String.valueOf(c));
+        if(gender % 2 == 1){
+            return 1;
+        }else{
+            return 2;
+        }
+    }
+    public String getBirthday(String idCard){
+        return idCard.substring(6).substring(0, 4)+"-"+idCard.substring(10).substring(0, 2)+"-"+idCard.substring(12).substring(0,2);
+    }
+
 
     public static void getFileByBytes(byte[] bytes, String filePath, String fileName) {
         BufferedOutputStream bos = null;

--
Gitblit v1.7.1