|
|
@@ -55,11 +55,15 @@ import vip.xiaonuo.forum.modular.supportenv.mapper.ForumSupportEnvMapper;
|
|
|
import vip.xiaonuo.sys.api.SysUserApi;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -100,6 +104,9 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
@Resource
|
|
|
private ForumChapterDiscussionMapper forumChapterDiscussionMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ForumPostInfoMapper forumPostInfoMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Page<ForumPostInfo> page(ForumPostInfoPageParam forumPostInfoPageParam) {
|
|
|
@@ -730,6 +737,96 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
return CommonResult.data(result);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResult<com.alibaba.fastjson.JSONObject> getCountByCourseAndDate(com.alibaba.fastjson.JSONObject json) {
|
|
|
+ // 取出课程id,查询日期类型 最近7天、最近30天、最近90天、最近一年
|
|
|
+ String courseId = json.getString("courseId");
|
|
|
+ Integer dateType = json.getInteger("dateType");
|
|
|
+ // 查询讨论总数、回帖总数、平均回帖数
|
|
|
+ Map<String, Long> postCountAndReplyCount = forumPostInfoMapper.getPostCountAndReplyCountByCourse(courseId, dateType);
|
|
|
+ com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
|
|
|
+ Long replyCount = postCountAndReplyCount.getOrDefault("replyCount", 0L);
|
|
|
+ Long postCount = postCountAndReplyCount.getOrDefault("postCount", 0L);
|
|
|
+ result.put("postCount", postCount);
|
|
|
+ result.put("replyCount", replyCount);
|
|
|
+ // 计算平均回帖数 回帖数除以发帖数 并四舍五入后面只留一位小数
|
|
|
+ double avgReplyCount = 0.0;
|
|
|
+ if (postCount > 0) {
|
|
|
+ // 使用BigDecimal保证计算精度
|
|
|
+ BigDecimal reply = new BigDecimal(replyCount);
|
|
|
+ BigDecimal post = new BigDecimal(postCount);
|
|
|
+ avgReplyCount = reply.divide(post, 2, RoundingMode.HALF_UP).setScale(1, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
+ result.put("avgReplyCount", avgReplyCount);
|
|
|
+ return CommonResult.data(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult<com.alibaba.fastjson.JSONObject> getStudentAndTeacherCount(com.alibaba.fastjson.JSONObject json) {
|
|
|
+ // 取出课程id,查询日期类型 最近7天、最近30天、最近90天、最近一年
|
|
|
+ String courseId = json.getString("courseId");
|
|
|
+ Integer dateType = json.getInteger("dateType");
|
|
|
+ // 分别查询学员和教员的讨论总数、回帖总数
|
|
|
+ Map<String, Long> studentAndTeacher = forumPostInfoMapper.getStudentAndTeacherCount(courseId, dateType);
|
|
|
+ // 封装参数
|
|
|
+ com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
|
|
|
+ // 学员
|
|
|
+ Long studentPostCount = studentAndTeacher.getOrDefault("studentPostCount", 0L);
|
|
|
+ Long studentReplyCount = studentAndTeacher.getOrDefault("studentReplyCount", 0L);
|
|
|
+ // 计算学员日均回帖数
|
|
|
+ double studentAvgReplyCount = 0.0;
|
|
|
+ if (studentPostCount > 0) {
|
|
|
+ // 使用BigDecimal保证计算精度
|
|
|
+ BigDecimal reply = new BigDecimal(studentReplyCount);
|
|
|
+ BigDecimal post = new BigDecimal(studentPostCount);
|
|
|
+ studentAvgReplyCount = reply.divide(post, 2, RoundingMode.HALF_UP).setScale(1, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
+ // 教员
|
|
|
+ Long teacherPostCount = studentAndTeacher.getOrDefault("teacherPostCount", 0L);
|
|
|
+ Long teacherReplyCount = studentAndTeacher.getOrDefault("teacherReplyCount", 0L);
|
|
|
+ // 计算教员日均回帖数
|
|
|
+ double teacherAvgReplyCount = 0.0;
|
|
|
+ if (teacherPostCount > 0) {
|
|
|
+ // 使用BigDecimal保证计算精度
|
|
|
+ BigDecimal reply = new BigDecimal(teacherReplyCount);
|
|
|
+ BigDecimal post = new BigDecimal(teacherPostCount);
|
|
|
+ teacherAvgReplyCount = reply.divide(post, 2, RoundingMode.HALF_UP).setScale(1, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
+ result.put("studentPostCount", studentPostCount);
|
|
|
+ result.put("studentReplyCount", studentReplyCount);
|
|
|
+ result.put("studentAvgReplyCount", studentAvgReplyCount);
|
|
|
+ result.put("teacherPostCount", teacherPostCount);
|
|
|
+ result.put("teacherReplyCount", teacherReplyCount);
|
|
|
+ result.put("teacherAvgReplyCount", teacherAvgReplyCount);
|
|
|
+ return CommonResult.data(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult<com.alibaba.fastjson.JSONObject> getStudentPostInfoList(com.alibaba.fastjson.JSONObject json) {
|
|
|
+ com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
|
|
|
+ // 取出课程id,查询日期类型 最近7天、最近30天、最近90天、最近一年
|
|
|
+ String courseId = json.getString("courseId");
|
|
|
+ Integer dateType = json.getInteger("dateType");
|
|
|
+ // 根据课程id查询出 讨论的用户
|
|
|
+ List<Map<String, String>> studentAndTeacher = forumPostInfoMapper.getStudentPostInfoList(courseId, dateType);
|
|
|
+ // 封装参数
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (studentAndTeacher.size() > 0) {
|
|
|
+ for (Map<String, String> dataMap : studentAndTeacher) {
|
|
|
+ com.alibaba.fastjson.JSONObject info = new com.alibaba.fastjson.JSONObject();
|
|
|
+ info.put("postTitle", dataMap.getOrDefault("postTitle", ""));
|
|
|
+ info.put("userName", dataMap.getOrDefault("userName", ""));
|
|
|
+ info.put("createTime", dataMap.getOrDefault("latest_create_time", ""));
|
|
|
+ info.put("replyCount", dataMap.getOrDefault("total_replies", "0"));
|
|
|
+ info.put("lastReplyTime", dataMap.getOrDefault("last_child_reply_time", ""));
|
|
|
+ jsonArray.add(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.put("list", jsonArray);
|
|
|
+ return CommonResult.data(result);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 自动创建章节讨论类型的帖子
|
|
|
*/
|