From 49429bad1036c81c056faeadfa009c53ba777fad Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期二, 07 五月 2024 18:02:11 +0800
Subject: [PATCH] feat:反馈保存、展示、处理、删除

---
 src/main/java/com/mindskip/xzs/repository/FeedbackMapper.java               |   24 ++++
 src/main/java/com/mindskip/xzs/viewmodel/admin/question/ExamQuestionVO.java |    1 
 src/main/resources/mapper/FeedbackMapper.xml                                |   32 ++++++
 src/main/java/com/mindskip/xzs/controller/admin/DepartmentController.java   |    6 +
 src/main/java/com/mindskip/xzs/domain/Feedback.java                         |   38 +++++++
 src/main/java/com/mindskip/xzs/service/FeedbackService.java                 |   20 ++++
 src/main/java/com/mindskip/xzs/controller/admin/FeedBackController.java     |   38 +++++++
 src/main/java/com/mindskip/xzs/domain/vo/FeedbackVO.java                    |   39 +++++++
 src/main/java/com/mindskip/xzs/service/impl/FeedbackServiceImpl.java        |   57 +++++++++++
 9 files changed, 254 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/mindskip/xzs/controller/admin/DepartmentController.java b/src/main/java/com/mindskip/xzs/controller/admin/DepartmentController.java
index 103f7e8..5228899 100644
--- a/src/main/java/com/mindskip/xzs/controller/admin/DepartmentController.java
+++ b/src/main/java/com/mindskip/xzs/controller/admin/DepartmentController.java
@@ -17,6 +17,7 @@
 import com.mindskip.xzs.utility.PageInfoHelper;
 import com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -107,7 +108,10 @@
                     List<UserDepartment> userDepartments = userDepartmentMapper.selectByDepartmentId(e.getId());
                     List<User> list = new ArrayList<>();
                     for (UserDepartment userDepartment : userDepartments) {
-                        list.add(userService.getUserById(userDepartment.getUserId()));
+                        User user = userService.getUserById(userDepartment.getUserId());
+                        if (ObjectUtils.isNotEmpty(user)) {
+                            list.add(user);
+                        }
                     }
                     departmentVO.setUserList(list);
                     departmentVO.setDepartment(e);
diff --git a/src/main/java/com/mindskip/xzs/controller/admin/FeedBackController.java b/src/main/java/com/mindskip/xzs/controller/admin/FeedBackController.java
new file mode 100644
index 0000000..5714cd0
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/controller/admin/FeedBackController.java
@@ -0,0 +1,38 @@
+package com.mindskip.xzs.controller.admin;
+
+import com.mindskip.xzs.base.BaseApiController;
+import com.mindskip.xzs.base.RestResponse;
+import com.mindskip.xzs.domain.vo.FeedbackVO;
+import com.mindskip.xzs.service.FeedbackService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author gonghl
+ * @since 2024/5/7 涓嬪崍 3:57
+ */
+
+@RequiredArgsConstructor
+@RestController("studentFeedBackController")
+@RequestMapping("/api/student/feedback")
+public class FeedBackController extends BaseApiController {
+
+    private final FeedbackService feedbackService;
+
+    /**
+     * 淇濆瓨鍙嶉
+     *
+     * @param feedbackVO 鏁版嵁
+     * @return 鎿嶄綔缁撴灉
+     */
+    @PostMapping("saveFeedback")
+    public RestResponse<String> saveFeedback(@RequestBody FeedbackVO feedbackVO) {
+        feedbackVO.setUserId(getCurrentUser().getId());
+        feedbackService.saveFeedback(feedbackVO);
+        return RestResponse.ok("鎿嶄綔鎴愬姛");
+    }
+
+}
diff --git a/src/main/java/com/mindskip/xzs/domain/Feedback.java b/src/main/java/com/mindskip/xzs/domain/Feedback.java
new file mode 100644
index 0000000..7cbb4d0
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/domain/Feedback.java
@@ -0,0 +1,38 @@
+package com.mindskip.xzs.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+/**
+ * @author gonghl
+ * @TableName t_feedback
+ */
+@TableName(value = "t_feedback")
+@Data
+public class Feedback implements Serializable {
+
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+
+    private Integer questionId;
+
+    private Integer contentId;
+
+    @TableField(value = "`describe`")
+    private String describe;
+
+    private Integer userId;
+
+    private Boolean fix;
+
+    private LocalDateTime fixTime;
+
+    private static final long serialVersionUID = 1L;
+}
\ No newline at end of file
diff --git a/src/main/java/com/mindskip/xzs/domain/vo/FeedbackVO.java b/src/main/java/com/mindskip/xzs/domain/vo/FeedbackVO.java
new file mode 100644
index 0000000..8f77119
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/domain/vo/FeedbackVO.java
@@ -0,0 +1,39 @@
+package com.mindskip.xzs.domain.vo;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
+
+/**
+ * @author gonghl
+ * @since 2024/5/7 涓嬪崍 4:00
+ */
+
+@Data
+public class FeedbackVO {
+
+    private Integer id;
+
+    @NotNull
+    private Integer questionId;
+
+    @NotNull
+    private Integer contentId;
+
+    private String describe;
+
+    private Integer userId;
+
+    private Boolean fix;
+
+    private LocalDateTime fixTime;
+
+    private Integer pageIndex;
+
+    private Integer pageSize;
+
+    private String questionTitle;
+
+    private String userName;
+}
diff --git a/src/main/java/com/mindskip/xzs/repository/FeedbackMapper.java b/src/main/java/com/mindskip/xzs/repository/FeedbackMapper.java
new file mode 100644
index 0000000..18c0dea
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/repository/FeedbackMapper.java
@@ -0,0 +1,24 @@
+package com.mindskip.xzs.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.mindskip.xzs.domain.Feedback;
+import com.mindskip.xzs.domain.vo.FeedbackVO;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author gonghl
+ * @description 閽堝琛ㄣ�恡_feedback(閿欓鍙嶉)銆戠殑鏁版嵁搴撴搷浣淢apper
+ * @createDate 2024-05-07 15:52:33
+ * @Entity com.mindskip.xzs.feedback.TFeedback
+ */
+@Mapper
+public interface FeedbackMapper extends BaseMapper<Feedback> {
+
+    List<FeedbackVO> feedbackPage();
+}
+
+
+
+
diff --git a/src/main/java/com/mindskip/xzs/service/FeedbackService.java b/src/main/java/com/mindskip/xzs/service/FeedbackService.java
new file mode 100644
index 0000000..ee91f95
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/service/FeedbackService.java
@@ -0,0 +1,20 @@
+package com.mindskip.xzs.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.github.pagehelper.PageInfo;
+import com.mindskip.xzs.domain.Feedback;
+import com.mindskip.xzs.domain.vo.FeedbackVO;
+
+/**
+ * @author gonghl
+ * @description 閽堝琛ㄣ�恡_feedback(閿欓鍙嶉)銆戠殑鏁版嵁搴撴搷浣淪ervice
+ * @createDate 2024-05-07 15:52:33
+ */
+public interface FeedbackService extends IService<Feedback> {
+
+    void saveFeedback(FeedbackVO feedbackVO);
+
+    PageInfo<FeedbackVO> feedbackPage(FeedbackVO feedbackVO);
+
+    void settleFeedback(Integer id);
+}
diff --git a/src/main/java/com/mindskip/xzs/service/impl/FeedbackServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/FeedbackServiceImpl.java
new file mode 100644
index 0000000..06be31e
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/service/impl/FeedbackServiceImpl.java
@@ -0,0 +1,57 @@
+package com.mindskip.xzs.service.impl;
+
+import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.mindskip.xzs.domain.Feedback;
+import com.mindskip.xzs.domain.question.QuestionObject;
+import com.mindskip.xzs.domain.vo.FeedbackVO;
+import com.mindskip.xzs.repository.FeedbackMapper;
+import com.mindskip.xzs.service.FeedbackService;
+import com.mindskip.xzs.utility.JsonUtil;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.time.DateUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.stream.Collectors;
+
+/**
+ * @author gonghl
+ * @description 閽堝琛ㄣ�恡_feedback(閿欓鍙嶉)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+ * @createDate 2024-05-07 15:52:33
+ */
+@Service
+@RequiredArgsConstructor
+public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {
+
+    private final FeedbackMapper feedbackMapper;
+
+    @Override
+    public void saveFeedback(FeedbackVO feedbackVO) {
+        Feedback feedback = new Feedback();
+        BeanUtils.copyProperties(feedbackVO, feedback);
+        feedbackMapper.insert(feedback);
+    }
+
+    @Override
+    public PageInfo<FeedbackVO> feedbackPage(FeedbackVO feedbackVO) {
+        return PageHelper.startPage(feedbackVO.getPageIndex(), feedbackVO.getPageSize()).doSelectPageInfo(() ->
+                feedbackMapper.feedbackPage().stream().peek(f -> f.setQuestionTitle(JsonUtil.toJsonObject(f.getQuestionTitle(), QuestionObject.class).getTitleContent())).collect(Collectors.toList()));
+    }
+
+    @Override
+    public void settleFeedback(Integer id) {
+        new LambdaUpdateChainWrapper<>(feedbackMapper)
+                .set(Feedback::getFix, true)
+                .set(Feedback::getFixTime, LocalDateTime.now())
+                .eq(Feedback::getId, id)
+                .update();
+    }
+}
+
+
+
+
diff --git a/src/main/java/com/mindskip/xzs/viewmodel/admin/question/ExamQuestionVO.java b/src/main/java/com/mindskip/xzs/viewmodel/admin/question/ExamQuestionVO.java
index 44d8eea..9401826 100644
--- a/src/main/java/com/mindskip/xzs/viewmodel/admin/question/ExamQuestionVO.java
+++ b/src/main/java/com/mindskip/xzs/viewmodel/admin/question/ExamQuestionVO.java
@@ -66,5 +66,6 @@
 
     private String department;
 
+    private Integer infoTextContentId;
 
 }
diff --git a/src/main/resources/mapper/FeedbackMapper.xml b/src/main/resources/mapper/FeedbackMapper.xml
new file mode 100644
index 0000000..6b6c8d0
--- /dev/null
+++ b/src/main/resources/mapper/FeedbackMapper.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.mindskip.xzs.repository.FeedbackMapper">
+
+    <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Feedback">
+        <id property="id" column="id" jdbcType="INTEGER"/>
+        <result property="questionId" column="question_id" jdbcType="INTEGER"/>
+        <result property="contentId" column="content_id" jdbcType="INTEGER"/>
+        <result property="describe" column="describe" jdbcType="VARCHAR"/>
+        <result property="userId" column="user_id" jdbcType="INTEGER"/>
+        <result property="fix" column="fix" jdbcType="BIT"/>
+        <result property="fixTime" column="fix_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,question_id,content_id,
+        describe,user_id,fix,
+            fix_time
+    </sql>
+
+    <select id="feedbackPage" resultType="com.mindskip.xzs.domain.vo.FeedbackVO">
+        select a.*,
+               b.content as questionTitle,
+               c.real_name as userName
+        from t_feedback a
+                 left join t_text_content b on a.content_id = b.id
+                 left join t_user c on a.user_id = c.id and deleted = 0
+        order by id desc
+    </select>
+</mapper>

--
Gitblit v1.8.0