Переглянути джерело

1.修复章节讨论的bug
2.开发统计:根据日期查询发帖和回帖数

jasonk5949 6 місяців тому
батько
коміт
7ffa99a4ad

+ 11 - 2
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postinfo/controller/ForumPostInfoController.java

@@ -180,11 +180,20 @@ public class ForumPostInfoController {
     /**
      * 根据课程id和课时id,查询相关帖子信息
      */
-    @PostMapping("/forum/postinfo/getChapter")
-    public CommonResult<ForumPostInfoVo> getChapter(@RequestBody ChapterDiscussionParam chapterDiscussionParam) {
+    @GetMapping("/forum/postinfo/getChapter")
+    public CommonResult<ForumPostInfoVo> getChapter(@Valid ChapterDiscussionParam chapterDiscussionParam) {
         return CommonResult.data(forumPostInfoService.getChapter(chapterDiscussionParam));
     }
 
+    /**
+     * 统计:根据日期查询发帖和回帖数
+     */
+    @PostMapping("/forum/postinfo/getCountByDate")
+    public CommonResult<JSONObject> getCountByDate(@RequestBody JSONObject json) {
+        return forumPostInfoService.getCountByDate(json);
+    }
+
+
 
 
 }

+ 5 - 0
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postinfo/service/ForumPostInfoService.java

@@ -114,4 +114,9 @@ public interface ForumPostInfoService extends IService<ForumPostInfo> {
      * 根据课程id和课时id,查询相关帖子信息
      */
     ForumPostInfoVo getChapter(ChapterDiscussionParam chapterDiscussionParam);
+
+    /**
+     * 统计:根据日期查询发帖和回帖数
+     */
+    CommonResult<JSONObject> getCountByDate(JSONObject json);
 }

+ 16 - 0
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postinfo/service/impl/ForumPostInfoServiceImpl.java

@@ -714,6 +714,22 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
         return forumPostInfoVo;
     }
 
+    @Override
+    public CommonResult<com.alibaba.fastjson.JSONObject> getCountByDate(com.alibaba.fastjson.JSONObject json) {
+        // 取出起始时间和截止时间
+        String startTime = json.getString("startTime");
+        String endTime = json.getString("endTime");
+        // 计算两个时间段内的发帖数和回帖数
+        // 1.发帖数
+        long postCountByDateAndType = forumPostReplyService.getPostCountByDateAndType(startTime, endTime, 3);
+        // 2.回帖数
+        long replyCountByDateAndType = forumPostReplyService.getReplyCountByDateAndType(startTime, endTime, 3);
+        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
+        result.put("postCount", postCountByDateAndType);
+        result.put("replyCount", replyCountByDateAndType);
+        return CommonResult.data(result);
+    }
+
     /**
      * 自动创建章节讨论类型的帖子
      */

+ 5 - 0
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postreply/entity/ForumPostReply.java

@@ -116,4 +116,9 @@ public class ForumPostReply {
      * 回复用户身份 0管理员,1老师,2学生
      */
     private Integer userEduIdentity;
+
+    /**
+     * 帖子类型
+     */
+    private Integer postType;
 }

+ 9 - 0
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postreply/service/ForumPostReplyService.java

@@ -79,4 +79,13 @@ public interface ForumPostReplyService extends IService<ForumPostReply> {
      **/
     ForumPostReply queryEntity(String id);
 
+    /**
+     * 查询两个时间段内的发帖数
+     */
+    long getPostCountByDateAndType(String startTime, String endTime, Integer postType);
+
+    /**
+     * 查询两个时间段的回帖数
+     */
+    long getReplyCountByDateAndType(String startTime, String endTime, Integer postType);
 }

+ 23 - 0
snowy-plugin/snowy-plugin-forum/snowy-plugin-forum-func/src/main/java/vip/xiaonuo/forum/modular/postreply/service/impl/ForumPostReplyServiceImpl.java

@@ -47,6 +47,7 @@ import vip.xiaonuo.forum.modular.sensitivityrecord.mapper.ForumSensitivityRecord
 import vip.xiaonuo.sys.api.SysUserApi;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 import java.util.Date;
 import java.util.List;
 
@@ -155,6 +156,8 @@ public class ForumPostReplyServiceImpl extends ServiceImpl<ForumPostReplyMapper,
         if (userByIdWithoutException != null) {
             forumPostReply.setUserEduIdentity(userByIdWithoutException.getInt("eduIdentity"));
         }
+        // 设置帖子的类型
+        forumPostReply.setPostType(forumPostInfo.getPostType());
         // 过滤敏感词
         String replyContent = filterSensitivity(forumPostReplyAddParam.getReplyContent(), loginUser, forumPostReplyAddParam.getPostId());
         forumPostReply.setReplyContent(replyContent);
@@ -243,4 +246,24 @@ public class ForumPostReplyServiceImpl extends ServiceImpl<ForumPostReplyMapper,
         return forumPostReply;
     }
 
+    /**
+     * 查询两个时间段的发帖数
+     */
+    public long getPostCountByDateAndType(String startTime, String endTime, Integer postType) {
+        QueryWrapper<ForumPostReply> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(ForumPostReply::getPostType, 3);
+        queryWrapper.lambda().between(ForumPostReply::getCreateTime, startTime, endTime);
+        queryWrapper.lambda().eq(ForumPostReply::getParentId, "-1");
+        return this.count(queryWrapper);
+    }
+
+    @Override
+    public long getReplyCountByDateAndType(String startTime, String endTime, Integer postType) {
+        QueryWrapper<ForumPostReply> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(ForumPostReply::getPostType, 3);
+        queryWrapper.lambda().between(ForumPostReply::getCreateTime, startTime, endTime);
+        queryWrapper.lambda().notIn(ForumPostReply::getParentId, "-1");
+        return this.count(queryWrapper);
+    }
+
 }