|
|
@@ -14,6 +14,7 @@ package vip.xiaonuo.disk.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
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;
|
|
|
@@ -29,19 +30,20 @@ import vip.xiaonuo.common.pojo.CommonResult;
|
|
|
import vip.xiaonuo.common.pojo.CommonValidList;
|
|
|
import vip.xiaonuo.disk.domain.Chapter;
|
|
|
import vip.xiaonuo.disk.domain.CourseInfo;
|
|
|
+import vip.xiaonuo.disk.domain.ResourceRecordUserRelate;
|
|
|
import vip.xiaonuo.disk.param.ChapterAddParam;
|
|
|
import vip.xiaonuo.disk.param.ChapterEditParam;
|
|
|
import vip.xiaonuo.disk.param.ChapterIdParam;
|
|
|
import vip.xiaonuo.disk.param.ChapterPageParam;
|
|
|
import vip.xiaonuo.disk.service.ChapterService;
|
|
|
+import vip.xiaonuo.disk.service.ClassHourService;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 课程章节表控制器
|
|
|
@@ -57,24 +59,94 @@ public class CourseChapterController {
|
|
|
|
|
|
@Resource
|
|
|
private ChapterService chapterService;
|
|
|
+ @Resource
|
|
|
+ private ClassHourService classHourService;
|
|
|
|
|
|
/**
|
|
|
- * 获取课程章节表分页
|
|
|
+ * 课程章节表-分页列表
|
|
|
*
|
|
|
* @author pans
|
|
|
* @date 2025/07/02 15:34
|
|
|
*/
|
|
|
@ApiOperationSupport(order = 1)
|
|
|
- @ApiOperation("获取课程章节表分页")
|
|
|
+ @ApiOperation("课程章节表-分页列表")
|
|
|
@SaCheckPermission("/disk/chapter/page")
|
|
|
@GetMapping("/disk/chapter/page")
|
|
|
public CommonResult<Page<Map<String,Object>>> page(ChapterPageParam chapterPageParam, HttpServletRequest req) {
|
|
|
Map param =new HashMap();
|
|
|
param.put("courseId", req.getParameter("courseId"));
|
|
|
param.put("name", req.getParameter("name"));
|
|
|
+ //查回章节信息
|
|
|
+ Page<Map<String,Object>> chapterPage=chapterService.queryList(param);
|
|
|
+ List<Map<String,Object>> chapterList=chapterPage.getRecords();
|
|
|
+ //挂上所有章节的课时信息
|
|
|
+ //先取出所有章节id
|
|
|
+ List<String> chapterIdList= chapterList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
+ param.clear();
|
|
|
+ param.put("chapterIdList", chapterIdList);
|
|
|
+ List<Map<String,Object>> classHourList =classHourService.queryAllList(param);
|
|
|
+
|
|
|
+ // 2. 按chapterId分组课程
|
|
|
+ Map<String, List<Map<String, Object>>> classHourByChapter = classHourList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(classHour -> classHour.get("chapterId") != null)
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ classHour -> classHour.get("chapterId").toString()
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 3. 为每个章节添加对应的课程列表
|
|
|
+ chapterList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(chapter -> chapter.get("id") != null)
|
|
|
+ .forEach(chapter -> {
|
|
|
+ String chapterId = chapter.get("id").toString();
|
|
|
+ chapter.put("classHours",
|
|
|
+ classHourByChapter.getOrDefault(chapterId, Collections.emptyList()));
|
|
|
+ });
|
|
|
+
|
|
|
+ return CommonResult.data(chapterPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 课程章节表-全量列表
|
|
|
+ *
|
|
|
+ * @author pans
|
|
|
+ * @date 2025/07/02 15:34
|
|
|
+ */
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation("课程章节表-全量列表")
|
|
|
+ @SaCheckPermission("/disk/chapter/allList")
|
|
|
+ @GetMapping("/disk/chapter/allList")
|
|
|
+ public CommonResult<List<Map<String,Object>>> allList(ChapterPageParam chapterPageParam, HttpServletRequest req) {
|
|
|
+ Map param =new HashMap();
|
|
|
+ param.put("courseId", req.getParameter("courseId"));
|
|
|
+ param.put("name", req.getParameter("name"));
|
|
|
+ List<Map<String,Object>> chapterList=chapterService.queryAllList(param);
|
|
|
+ //挂上所有章节的课时信息
|
|
|
+ //先取出所有章节id
|
|
|
+ List<String> chapterIdList= chapterList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
+ param.clear();
|
|
|
+ param.put("chapterIdList", chapterIdList);
|
|
|
+ List<Map<String,Object>> classHourList =classHourService.queryAllList(param);
|
|
|
+
|
|
|
+ // 2. 按chapterId分组课程
|
|
|
+ Map<String, List<Map<String, Object>>> classHourByChapter = classHourList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(classHour -> classHour.get("chapterId") != null)
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ classHour -> classHour.get("chapterId").toString()
|
|
|
+ ));
|
|
|
|
|
|
- Page<Map<String,Object>> list=chapterService.queryList(param);
|
|
|
- return CommonResult.data(list);
|
|
|
+ // 3. 为每个章节添加对应的课程列表
|
|
|
+ chapterList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(chapter -> chapter.get("id") != null)
|
|
|
+ .forEach(chapter -> {
|
|
|
+ String chapterId = chapter.get("id").toString();
|
|
|
+ chapter.put("classHours",
|
|
|
+ classHourByChapter.getOrDefault(chapterId, Collections.emptyList()));
|
|
|
+ });
|
|
|
+ return CommonResult.data(chapterList);
|
|
|
}
|
|
|
|
|
|
/**
|