From 02f18587bd8860b305e2c688e20465be166bb48c Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期四, 22 七月 2021 15:14:03 +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/ComActQuestnaireServiceImpl.java |   72 +++++++++++++++++++++++++++++-------
 1 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActQuestnaireServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActQuestnaireServiceImpl.java
index 6044fa0..498e8f2 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActQuestnaireServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActQuestnaireServiceImpl.java
@@ -3,6 +3,7 @@
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -15,8 +16,10 @@
 import com.panzhihua.common.model.dtos.community.PageQuestnaireDTO;
 import com.panzhihua.common.model.dtos.community.PageQuestnaireSubDetailsDTO;
 import com.panzhihua.common.model.dtos.community.QuestnaireAnswersDTO;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.questnaire.*;
+import com.panzhihua.common.service.user.UserService;
 import com.panzhihua.service_community.dao.*;
 import com.panzhihua.service_community.model.dos.*;
 import com.panzhihua.service_community.service.ComActQuestnaireService;
@@ -52,6 +55,8 @@
     ComActQuestnaireSubSelectionServiceImpl subSelectionService;
     @Resource
     ComActQuestnaireAnswerContentServiceImpl answerContentService;
+    @Resource
+    UserService userService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -82,16 +87,25 @@
                 int subId = questnaireSubDAO.insert(comActQuestnaireSubDO);
 
                 ArrayList<ComActQuestnaireSubSelectionDO> subSelectionList = Lists.newArrayList();
-                sub.getQuestnaiteSubSelectionVOS().forEach(subSelect -> {
-                    ComActQuestnaireSubSelectionDO subSelectionDO = new ComActQuestnaireSubSelectionDO();
-                    subSelectionDO.setQueSubId(comActQuestnaireSubDO.getId());
-                    subSelectionDO.setOptionName(subSelect.getOptionName());
-                    subSelectionDO.setSort(subSelect.getSort());
-                    subSelectionDO.setContent(subSelect.getContent());
-                    subSelectionDO.setCreateBy(userId);
-                    subSelectionDO.setType(subSelect.getType());
-                    subSelectionList.add(subSelectionDO);
-                });
+                if(sub.getQuestnaiteSubSelectionVOS()!=null) {
+                    List<QuestnaiteSubSelectionVO> l = sub.getQuestnaiteSubSelectionVOS();
+                    for(int i=0; i<l.size(); i++){
+                        QuestnaiteSubSelectionVO subSelect = l.get(i);
+                        ComActQuestnaireSubSelectionDO subSelectionDO = new ComActQuestnaireSubSelectionDO();
+                        subSelectionDO.setQueSubId(comActQuestnaireSubDO.getId());
+                        if(subSelect.getType()==1){
+                            //添加选项名称
+                            subSelectionDO.setOptionName(subSelect.getOptionName());
+                        }else {
+                            subSelectionDO.setOptionName(String.valueOf(Character.toChars('A' + i)));
+                        }
+                        subSelectionDO.setSort(subSelect.getSort());
+                        subSelectionDO.setContent(subSelect.getContent());
+                        subSelectionDO.setCreateBy(userId);
+                        subSelectionDO.setType(subSelect.getType());
+                        subSelectionList.add(subSelectionDO);
+                    }
+                }
                 subSelectionService.saveBatch(subSelectionList);
             });
         }
@@ -131,8 +145,8 @@
             if (questnaireDO == null) {
                 return R.fail(500, "id有误!");
             }
-            questnaireDO.setTitle(questnaireDO.getTitle());
-            questnaireDO.setQueDescribe(questnaireDO.getQueDescribe());
+            questnaireDO.setTitle(questnaireVO.getQueTitle());
+            questnaireDO.setQueDescribe(questnaireVO.getQueDescribe());
             //保存问卷调查
             questnaireDAO.updateById(questnaireDO);
             questnaireVO.getQuestnaiteSubVOS().forEach(sub -> {
@@ -157,6 +171,8 @@
                 });
             });
 
+        }else{
+            return R.fail("参数有误");
         }
         return R.ok();
     }
@@ -191,6 +207,10 @@
     public R statQuestnaire(Long questId) {
         ComActQuestnaireDO comActQuestnaireDO = questnaireDAO.selectOne(new QueryWrapper<ComActQuestnaireDO>().lambda().eq(ComActQuestnaireDO::getId, questId).eq(ComActQuestnaireDO::getIsHide, 0));
 
+        if(comActQuestnaireDO==null){
+            return R.fail("问卷已删除!");
+        }
+
         QuestnaireAnswerStatVO usersAnswerStatVO = new QuestnaireAnswerStatVO();
         //问卷信息
         ComActQuestnaireVO comActQuestnaireVO = new ComActQuestnaireVO();
@@ -216,7 +236,8 @@
             usersSubAnswerStatVO.setTotal(0);
 
             usearSubAnswerSelectionStatVOList.forEach(stat -> {
-                if (stat.getSubId() == comActQuestnaireSubDO.getId()) {
+                if (stat.getSubId().equals(comActQuestnaireSubDO.getId())
+                        && stat.getTotal()>0) {
                     userSubAnswerSelectionStatVOList.add(stat);
                 }
             });
@@ -334,6 +355,12 @@
 
     @Override
     public R pageQuestnaireAnswer(PageQuestnaireAnswerDTO pageQuestnaireAnswerDTO) {
+        if(pageQuestnaireAnswerDTO.getPageNum()==null||pageQuestnaireAnswerDTO.getPageNum().longValue()==0){
+            pageQuestnaireAnswerDTO.setPageNum(1l);
+        }
+        if(pageQuestnaireAnswerDTO.getPageSize()==null||pageQuestnaireAnswerDTO.getPageSize().longValue()==0){
+            pageQuestnaireAnswerDTO.setPageSize(10l);
+        }
         Page userPage = new Page(pageQuestnaireAnswerDTO.getPageNum(), pageQuestnaireAnswerDTO.getPageSize());
         IPage<ComActQuestnaireAnswerContentVO> doPager = questnaireAnswerContentDAO.selectAnswersByPage(userPage, pageQuestnaireAnswerDTO);
         return R.ok(doPager);
@@ -347,6 +374,15 @@
         ComActQuestnaireDO questnaireDO = questnaireDAO.selectById(answerQuestnaireVO.getQuestId());
         if (questnaireDO == null) {
             return R.fail(500, "调查问卷不存在!");
+        }
+        R r = userService.getUserInfoByUserId(userId+"");
+        if(!R.isOk(r)){
+            return R.fail("用户信息错误");
+        }
+        LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginUserInfoVO.class);
+        Long userCommunityId = loginUserInfoVO.getCommunityId();
+        if(questnaireDO.getCommunityId()!=null && questnaireDO.getCommunityId().longValue()!=userCommunityId.longValue()){
+            return R.fail(500, "您目前所属社区无法填写当前社区的调查问卷,请切换社区后重试");
         }
         LambdaQueryWrapper<ComActQuestnaireSubDO> subQuery = new LambdaQueryWrapper<ComActQuestnaireSubDO>();
         subQuery.eq(ComActQuestnaireSubDO::getQueId,answerQuestnaireVO.getQuestId());
@@ -364,7 +400,15 @@
             answerContentDO.setUserId(userId);
             answerContentDOList.add(answerContentDO);
         }
-        answerContentService.saveBatch(answerContentDOList);
+        boolean batchAddSuccess = answerContentService.saveBatch(answerContentDOList);
+        if(batchAddSuccess) {
+            /**
+             * 更新回答用户数量
+             */
+            Integer joinCount = questnaireDO.getJoinCount();
+            questnaireDO.setJoinCount(joinCount != null ? joinCount + 1 : 1);
+            questnaireDAO.updateById(questnaireDO);
+        }
         return R.ok();
     }
 }

--
Gitblit v1.7.1