From c2a72ff724f8e1840c8902a74f4bdf5e7160ea3c Mon Sep 17 00:00:00 2001
From: DESKTOP-71BH0QO\L、ming <172680469@qq.com>
Date: 星期五, 09 四月 2021 13:21:29 +0800
Subject: [PATCH] Add:增加问卷删除

---
 springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/questnaire/QuestnaiteSubSelectionVO.java         |    2 
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireAnswerContentDO.java |    5 ++
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubDO.java           |    5 ++
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActQuestnaireServiceImpl.java  |   74 ++++++++++++++++++++++---------------
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubSelectionDO.java  |    9 +++-
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireDO.java              |    5 ++
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActQuestnaireService.java           |    5 ++
 7 files changed, 67 insertions(+), 38 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/questnaire/QuestnaiteSubSelectionVO.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/questnaire/QuestnaiteSubSelectionVO.java
index 2953de2..ee4bd8a 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/questnaire/QuestnaiteSubSelectionVO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/questnaire/QuestnaiteSubSelectionVO.java
@@ -16,7 +16,7 @@
     private Integer sort;
 
     @ApiModelProperty(value = "选项名")
-    private String option;
+    private String optionName;
 
     @ApiModelProperty(value = "选项内容")
     private String content;
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireAnswerContentDO.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireAnswerContentDO.java
index cda420c..e62cb10 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireAnswerContentDO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireAnswerContentDO.java
@@ -5,13 +5,16 @@
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
  * @Author: llming
  * @Description: 问卷回答记录内容
  */
 @Data
 @TableName(value = "com_act_questnaire_answer_content")
-public class ComActQuestnaireAnswerContentDO extends BaseDO {
+public class ComActQuestnaireAnswerContentDO extends BaseDO implements Serializable {
+    private static final long serialVersionUID = 7648337436253280726L;
     @TableId(type= IdType.AUTO)
     private Long id;
     /**
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireDO.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireDO.java
index e5b71b9..35b8a09 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireDO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireDO.java
@@ -5,13 +5,16 @@
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
  * @Author: llming
  * @Description:调查问卷 问卷表
  */
 @Data
 @TableName(value = "com_act_questnaire")
-public class ComActQuestnaireDO extends BaseDO {
+public class ComActQuestnaireDO extends BaseDO implements Serializable {
+    private static final long serialVersionUID = 4525826123672211880L;
     @TableId(type= IdType.AUTO)
     private Long id;
     /**
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubDO.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubDO.java
index c04f000..b4fbe3a 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubDO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubDO.java
@@ -5,13 +5,16 @@
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
  * @Author: llming
  * @Description: 问卷题目
  */
 @Data
 @TableName(value = "com_act_questnaire_sub")
-public class ComActQuestnaireSubDO extends BaseDO {
+public class ComActQuestnaireSubDO extends BaseDO implements Serializable {
+    private static final long serialVersionUID = 914683789736719693L;
     @TableId(type= IdType.AUTO)
     private Long id;
     /**
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubSelectionDO.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubSelectionDO.java
index b2d387f..2f4b101 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubSelectionDO.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComActQuestnaireSubSelectionDO.java
@@ -5,13 +5,16 @@
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
  * @Author: llming
  * @Description: 问卷题目选项
  */
 @Data
 @TableName(value = "com_act_questnaire_sub_selection")
-public class ComActQuestnaireSubSelectionDO extends BaseDO {
+public class ComActQuestnaireSubSelectionDO extends BaseDO implements Serializable {
+    private static final long serialVersionUID = -2083705916360506830L;
     @TableId(type= IdType.AUTO)
     private Long id;
     /**
@@ -23,9 +26,9 @@
      */
     private Integer sort;
     /**
-     * 选项
+     * 选项名
      */
-    private String option;
+    private String optionName;
     /**
      * 选项内容
      */
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActQuestnaireService.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActQuestnaireService.java
index 5595a49..a00f332 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActQuestnaireService.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActQuestnaireService.java
@@ -3,6 +3,7 @@
 import com.panzhihua.common.model.dtos.community.PageQuestnaireDTO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.questnaire.QuestnaireVO;
+import io.swagger.annotations.ApiModelProperty;
 
 /**
  * @Author: llming
@@ -28,8 +29,10 @@
 
     /**
      * 删除问卷
+     * @param queId 问卷调查ID
+     * @return
      */
-    R deleteQuestnaire();
+    R deleteQuestnaire(Long queId);
 
     /**
      * 问卷详情
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 46e90ac..ff1e229 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
@@ -34,6 +34,7 @@
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @Author: llming
@@ -77,7 +78,7 @@
             sub.getQuestnaiteSubSelectionVOS().forEach(subSelect -> {
                 ComActQuestnaireSubSelectionDO subSelectionDO = new ComActQuestnaireSubSelectionDO();
                 subSelectionDO.setQueSubId((long) subId);
-                subSelectionDO.setOption(subSelect.getOption());
+                subSelectionDO.setOptionName(subSelect.getOptionName());
                 subSelectionDO.setSort(subSelect.getSort());
                 subSelectionDO.setContent(subSelect.getContent());
                 subSelectionDO.setCreateBy(userId);
@@ -130,6 +131,7 @@
                     throw new ServiceException("500", "修改问卷题目数据有误!");
                 }
                 subDO.setContent(sub.getContent());
+                //更新问卷题目
                 questnaireSubDAO.updateById(subDO);
                 sub.getQuestnaiteSubSelectionVOS().forEach(subSelection -> {
                     if (subSelection.getQueSubSelectionId() == null || subSelection.getContent() == null) {
@@ -137,6 +139,7 @@
                     }
                     ComActQuestnaireSubSelectionDO subSelectionDO = questnaireSubSelectionDAO.selectById(subSelection.getQueSubSelectionId());
                     subSelectionDO.setContent(subSelection.getContent());
+                    //更新问卷选项
                     questnaireSubSelectionDAO.updateById(subSelectionDO);
                 });
             });
@@ -146,8 +149,19 @@
     }
 
     @Override
-    public R deleteQuestnaire() {
-        return null;
+    public R deleteQuestnaire(Long queId) {
+        int queDeleteResult = questnaireDAO.deleteById(queId);
+        if (queDeleteResult > 0) {
+            LambdaQueryWrapper<ComActQuestnaireSubDO> subParam = new QueryWrapper<ComActQuestnaireSubDO>().lambda();
+            subParam.eq(ComActQuestnaireSubDO::getQueId, queId);
+            List<Long> subIds = questnaireSubDAO.selectList(subParam).stream().map(ComActQuestnaireSubDO::getId).collect(Collectors.toList());
+            int subDeleteResult = questnaireSubDAO.delete(subParam);
+            if (subDeleteResult > 0) {
+                LambdaQueryWrapper<ComActQuestnaireSubSelectionDO> subSelectParam = new LambdaQueryWrapper<ComActQuestnaireSubSelectionDO>().in(ComActQuestnaireSubSelectionDO::getQueSubId, subIds);
+                questnaireSubSelectionDAO.delete(subSelectParam);
+            }
+        }
+        return R.ok();
     }
 
     @Override
@@ -159,8 +173,8 @@
     public R answerInfoQuestnaire(Long userId, Long questId) {
 
         ComActQuestnaireDO comActQuestnaireDO = questnaireDAO.selectById(questId);
-        if(comActQuestnaireDO==null){
-            return  R.fail("问卷不存在!");
+        if (comActQuestnaireDO == null) {
+            return R.fail("问卷不存在!");
         }
 
         UsersAnswerVO usersAnswerVO = new UsersAnswerVO();
@@ -171,35 +185,35 @@
         List<ComActQuestnaireSubDO> list = questnaireSubDAO.selectList(new QueryWrapper<ComActQuestnaireSubDO>().lambda().eq(ComActQuestnaireSubDO::getQueId, questId));
         List<UsersSubAnswerVO> usersSubAnswerVOList = new ArrayList<>();
 
-        list.forEach(comActQuestnaireSubDO ->{
-            UsersSubAnswerVO usersSubAnswerVO = new UsersSubAnswerVO();
-            Long subId = comActQuestnaireSubDO.getId();
-            List<ComActQuestnaireSubSelectionDO> comActQuestnaireSubSelectionDOs =
-                    questnaireSubSelectionDAO.selectList(new QueryWrapper<ComActQuestnaireSubSelectionDO>().lambda().eq(ComActQuestnaireSubSelectionDO::getQueSubId, subId));
+        list.forEach(comActQuestnaireSubDO -> {
+                    UsersSubAnswerVO usersSubAnswerVO = new UsersSubAnswerVO();
+                    Long subId = comActQuestnaireSubDO.getId();
+                    List<ComActQuestnaireSubSelectionDO> comActQuestnaireSubSelectionDOs =
+                            questnaireSubSelectionDAO.selectList(new QueryWrapper<ComActQuestnaireSubSelectionDO>().lambda().eq(ComActQuestnaireSubSelectionDO::getQueSubId, subId));
 
 
-            List<ComActQuestnaireSubSelectionVO> comActQuestnaireSubSelectionVOs = new ArrayList<>();
-            comActQuestnaireSubSelectionDOs.forEach(comActQuestnaireSubSelectionDO -> {
-                ComActQuestnaireSubSelectionVO comActQuestnaireSubSelectionVO = new ComActQuestnaireSubSelectionVO();
-                BeanUtils.copyProperties(comActQuestnaireSubSelectionDO, comActQuestnaireSubSelectionVO);
-                comActQuestnaireSubSelectionVOs.add(comActQuestnaireSubSelectionVO);
-            });
-            usersSubAnswerVO.setQuestSelectionList(comActQuestnaireSubSelectionVOs);
-            //用户回答
-            List<ComActQuestnaireAnswerContentDO> questnaireAnswerContentDOList =
-                    questnaireAnswerContentDAO.selectList(new QueryWrapper<ComActQuestnaireAnswerContentDO>().lambda().eq(ComActQuestnaireAnswerContentDO::getUserId, userId)
-                            .eq(ComActQuestnaireAnswerContentDO::getSubId, subId));
+                    List<ComActQuestnaireSubSelectionVO> comActQuestnaireSubSelectionVOs = new ArrayList<>();
+                    comActQuestnaireSubSelectionDOs.forEach(comActQuestnaireSubSelectionDO -> {
+                        ComActQuestnaireSubSelectionVO comActQuestnaireSubSelectionVO = new ComActQuestnaireSubSelectionVO();
+                        BeanUtils.copyProperties(comActQuestnaireSubSelectionDO, comActQuestnaireSubSelectionVO);
+                        comActQuestnaireSubSelectionVOs.add(comActQuestnaireSubSelectionVO);
+                    });
+                    usersSubAnswerVO.setQuestSelectionList(comActQuestnaireSubSelectionVOs);
+                    //用户回答
+                    List<ComActQuestnaireAnswerContentDO> questnaireAnswerContentDOList =
+                            questnaireAnswerContentDAO.selectList(new QueryWrapper<ComActQuestnaireAnswerContentDO>().lambda().eq(ComActQuestnaireAnswerContentDO::getUserId, userId)
+                                    .eq(ComActQuestnaireAnswerContentDO::getSubId, subId));
 
-            List<ComActQuestnaireAnswerContentVO> questnaireAnswerContentVOList = new ArrayList<>();
-            questnaireAnswerContentDOList.forEach(questnaireAnswerContentDO->{
-                ComActQuestnaireAnswerContentVO comActQuestnaireSubSelectionVO = new ComActQuestnaireAnswerContentVO();
-                BeanUtils.copyProperties(questnaireAnswerContentDO, comActQuestnaireSubSelectionVO);
-                questnaireAnswerContentVOList.add(comActQuestnaireSubSelectionVO);
-            });
+                    List<ComActQuestnaireAnswerContentVO> questnaireAnswerContentVOList = new ArrayList<>();
+                    questnaireAnswerContentDOList.forEach(questnaireAnswerContentDO -> {
+                        ComActQuestnaireAnswerContentVO comActQuestnaireSubSelectionVO = new ComActQuestnaireAnswerContentVO();
+                        BeanUtils.copyProperties(questnaireAnswerContentDO, comActQuestnaireSubSelectionVO);
+                        questnaireAnswerContentVOList.add(comActQuestnaireSubSelectionVO);
+                    });
 
-            usersSubAnswerVO.setUsersAnswer(questnaireAnswerContentVOList);
-            usersSubAnswerVOList.add(usersSubAnswerVO);
-            }
+                    usersSubAnswerVO.setUsersAnswer(questnaireAnswerContentVOList);
+                    usersSubAnswerVOList.add(usersSubAnswerVO);
+                }
         );
         usersAnswerVO.setUsersSubAnswer(usersSubAnswerVOList);
 

--
Gitblit v1.7.1