|
@@ -0,0 +1,225 @@
|
|
|
|
|
+/*
|
|
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
|
|
+ *
|
|
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
|
|
+ *
|
|
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
|
|
+ */
|
|
|
|
|
+package vip.xiaonuo.disk.controller;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
|
|
+import vip.xiaonuo.common.annotation.CommonLog;
|
|
|
|
|
+import vip.xiaonuo.common.pojo.CommonResult;
|
|
|
|
|
+import vip.xiaonuo.common.pojo.CommonValidList;
|
|
|
|
|
+import vip.xiaonuo.disk.domain.CourseRelate;
|
|
|
|
|
+import vip.xiaonuo.disk.domain.QuestionAnswer;
|
|
|
|
|
+import vip.xiaonuo.disk.param.*;
|
|
|
|
|
+import vip.xiaonuo.disk.service.CourseRelateService;
|
|
|
|
|
+import vip.xiaonuo.disk.service.QuestionAnswerService;
|
|
|
|
|
+import vip.xiaonuo.disk.vo.questionanswer.QuestionAnswerVo;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
+import javax.validation.constraints.NotEmpty;
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 课程问答控制器
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+@Api(tags = "课程问答控制器")
|
|
|
|
|
+@ApiSupport(author = "SNOWY_TEAM", order = 1)
|
|
|
|
|
+@RestController
|
|
|
|
|
+@Validated
|
|
|
|
|
+public class CourseQuestionAnswerController {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private QuestionAnswerService questionAnswerService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private CourseRelateService courseRelateService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取课程问答分页
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
|
|
+ @ApiOperation("获取课程问答分页")
|
|
|
|
|
+ @GetMapping("/disk/answer/page")
|
|
|
|
|
+ public CommonResult<Page<Map<String,Object>>> page(QuestionAnswerPageParam questionAnswerPageParam, HttpServletRequest req) {
|
|
|
|
|
+ Map param =new HashMap();
|
|
|
|
|
+ param.put("courseId", req.getParameter("courseId"));
|
|
|
|
|
+ param.put("hourId", req.getParameter("hourId"));
|
|
|
|
|
+ param.put("userId", StpLoginUserUtil.getLoginUser().getId());
|
|
|
|
|
+ //查询一级评论问题
|
|
|
|
|
+ Page<Map<String,Object>> page=questionAnswerService.queryList(param);
|
|
|
|
|
+ List<Map<String,Object>> recordList=page.getRecords();
|
|
|
|
|
+ List<String> recordIdList= recordList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
|
|
+ param.clear();
|
|
|
|
|
+ param.put("pidList", recordIdList);
|
|
|
|
|
+ //查询二级评论问题
|
|
|
|
|
+ List<Map<String,Object>> recordTwoList=questionAnswerService.queryMapList(param);
|
|
|
|
|
+ // 1. 准备结果:为每个章节添加classHours字段
|
|
|
|
|
+ for (Map<String, Object> record : recordList) {
|
|
|
|
|
+ if (record == null || record.get("id") == null) continue;
|
|
|
|
|
+
|
|
|
|
|
+ String recordId = record.get("id").toString();
|
|
|
|
|
+ List<Map<String, Object>> recordChildList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 倒序遍历课程列表(关键点!)
|
|
|
|
|
+ for (int i = recordTwoList.size() - 1; i >= 0; i--) {
|
|
|
|
|
+ Map<String, Object> recordTwo = recordTwoList.get(i);
|
|
|
|
|
+ if (recordTwo == null || recordTwo.get("pid") == null) continue;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 匹配当前章节
|
|
|
|
|
+ if (recordId.equals(recordTwo.get("pid").toString())) {
|
|
|
|
|
+ recordChildList.add(recordTwo); // 添加到章节
|
|
|
|
|
+ recordTwoList.remove(i); // 从原列表删除(安全操作)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ record.put("recordChildList", recordChildList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return CommonResult.data(page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 添加课程问答
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
|
|
+ @ApiOperation("添加课程问答")
|
|
|
|
|
+ @CommonLog("添加课程问答")
|
|
|
|
|
+ @PostMapping("/disk/answer/add")
|
|
|
|
|
+ public CommonResult<String> add(@RequestBody @Valid QuestionAnswerAddParam questionAnswerAddParam) {
|
|
|
|
|
+ //1.添加问答信息
|
|
|
|
|
+ QuestionAnswer questionAnswer = BeanUtil.toBean(questionAnswerAddParam, QuestionAnswer.class);
|
|
|
|
|
+ questionAnswer=questionAnswerService.addOne(questionAnswer);
|
|
|
|
|
+ //2.添加进课程关联信息
|
|
|
|
|
+ CourseRelate courseRelate=new CourseRelate();
|
|
|
|
|
+ courseRelate.setMainId(questionAnswerAddParam.getHourId());
|
|
|
|
|
+ courseRelate.setRelateId(questionAnswer.getId());
|
|
|
|
|
+ //功能类型,1视频资源,2讲义,3字幕,4作业,5测验,6笔记,7问答
|
|
|
|
|
+ courseRelate.setFuncType("7");
|
|
|
|
|
+ courseRelate.setChapterhourType("1");
|
|
|
|
|
+ courseRelate.setInfoType("1");
|
|
|
|
|
+ courseRelateService.addOne(courseRelate);
|
|
|
|
|
+
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 编辑课程问答
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
|
|
+ @ApiOperation("编辑课程问答")
|
|
|
|
|
+ @CommonLog("编辑课程问答")
|
|
|
|
|
+ @PostMapping("/disk/answer/edit")
|
|
|
|
|
+ public CommonResult<String> edit(@RequestBody @Valid QuestionAnswerEditParam questionAnswerEditParam) {
|
|
|
|
|
+ questionAnswerService.edit(questionAnswerEditParam);
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除课程问答
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
|
|
+ @ApiOperation("删除课程问答")
|
|
|
|
|
+ @CommonLog("删除课程问答")
|
|
|
|
|
+ @PostMapping("/disk/answer/delete")
|
|
|
|
|
+ public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
|
|
|
|
|
+ CommonValidList<QuestionAnswerIdParam> questionAnswerIdParamList) {
|
|
|
|
|
+ questionAnswerService.delete(questionAnswerIdParamList);
|
|
|
|
|
+ //删除课程关联问答信息
|
|
|
|
|
+ List<String> deleteIdList= CollStreamUtil.toList(questionAnswerIdParamList, QuestionAnswerIdParam::getId);
|
|
|
|
|
+ Map param=new HashMap<>();
|
|
|
|
|
+ param.put("relateIdList", deleteIdList);
|
|
|
|
|
+ List<CourseRelate> courseRelateList=courseRelateService.wrapperList(param);
|
|
|
|
|
+ List<String> deleteRelateIdList=CollStreamUtil.toList(courseRelateList, CourseRelate::getId);
|
|
|
|
|
+ courseRelateService.deleteByIdsReal(deleteRelateIdList);
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取课程问答详情
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
|
|
+ @ApiOperation("获取课程问答详情")
|
|
|
|
|
+ @GetMapping("/disk/answer/detail")
|
|
|
|
|
+ public CommonResult<Map<String,Object>> detail(@Valid QuestionAnswerIdParam questionAnswerIdParam, HttpServletRequest req) {
|
|
|
|
|
+ Map param =new HashMap();
|
|
|
|
|
+ param.put("courseId", req.getParameter("courseId"));
|
|
|
|
|
+ Map<String,Object> result=questionAnswerService.queryInfo(param);
|
|
|
|
|
+ return CommonResult.data(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 点赞
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/06/27 11:07
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
|
|
+ @ApiOperation("点赞")
|
|
|
|
|
+ @CommonLog("点赞")
|
|
|
|
|
+ @GetMapping("/disk/answer/give")
|
|
|
|
|
+ public CommonResult<String> edit(@Valid @NotNull(message="主键id不能为空") String id) {
|
|
|
|
|
+ questionAnswerService.give(id);
|
|
|
|
|
+ return CommonResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消点赞
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author pans
|
|
|
|
|
+ * @date 2025/06/27 11:07
|
|
|
|
|
+ */
|
|
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
|
|
+ @ApiOperation("点赞")
|
|
|
|
|
+ @CommonLog("点赞")
|
|
|
|
|
+ @GetMapping("/disk/answer/giveCancel")
|
|
|
|
|
+ public CommonResult<String> giveCancel(@Valid @NotNull(message="主键id不能为空") String id) {
|
|
|
|
|
+ return CommonResult.ok(questionAnswerService.giveCancel(id));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|