|
|
@@ -15,6 +15,7 @@ package vip.xiaonuo.disk.controller;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
|
@@ -30,19 +31,13 @@ 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.Chapter;
|
|
|
-import vip.xiaonuo.disk.domain.ClassHour;
|
|
|
-import vip.xiaonuo.disk.domain.CourseAuditRecord;
|
|
|
-import vip.xiaonuo.disk.domain.CourseInfo;
|
|
|
+import vip.xiaonuo.disk.domain.*;
|
|
|
import vip.xiaonuo.disk.param.courseInfo.CourseInfoAddParam;
|
|
|
import vip.xiaonuo.disk.param.courseInfo.CourseInfoEditParam;
|
|
|
import vip.xiaonuo.disk.param.courseInfo.CourseInfoIdParam;
|
|
|
import vip.xiaonuo.disk.param.courseInfo.CourseInfoPageParam;
|
|
|
import vip.xiaonuo.disk.param.courseauditrecord.CourseAuditRecordEditParam;
|
|
|
-import vip.xiaonuo.disk.service.ChapterService;
|
|
|
-import vip.xiaonuo.disk.service.ClassHourService;
|
|
|
-import vip.xiaonuo.disk.service.CourseAuditRecordService;
|
|
|
-import vip.xiaonuo.disk.service.CourseInfoService;
|
|
|
+import vip.xiaonuo.disk.service.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -71,6 +66,8 @@ public class CourseInfoController {
|
|
|
private ChapterService chapterService;
|
|
|
@Resource
|
|
|
private ClassHourService classHourService;
|
|
|
+ @Resource
|
|
|
+ private CourseRelateService courseRelateService;
|
|
|
|
|
|
/**
|
|
|
* 课程信息-分页列表
|
|
|
@@ -301,37 +298,51 @@ public class CourseInfoController {
|
|
|
* @date 2025/06/20 15:00
|
|
|
*/
|
|
|
@ApiOperationSupport(order = 3)
|
|
|
- @ApiOperation("课程信息-编辑")
|
|
|
- @CommonLog("课程信息-编辑")
|
|
|
+ @ApiOperation("课程信息-复制课程")
|
|
|
+ @CommonLog("课程信息-复制课程")
|
|
|
@SaCheckPermission("/disk/courseinfo/copy")
|
|
|
@PostMapping("/disk/courseinfo/copy")
|
|
|
public CommonResult<String> copy(@RequestBody @Valid CourseInfoEditParam courseInfoEditParam) {
|
|
|
//查回课程基础信息
|
|
|
CourseInfo courseInfo=courseInfoService.queryEntity(courseInfoEditParam.getCourseId());
|
|
|
- //查回课程所有章节信息
|
|
|
+ //1.查回课程所有章节信息
|
|
|
Map param =new HashMap();
|
|
|
param.put("courseId", courseInfoEditParam.getCourseId());
|
|
|
- List<Map<String,Object>> chapterList=chapterService.queryAllList(param);
|
|
|
- //查回课程所有课时信息进行复制
|
|
|
- List<String> chapterIdList= chapterList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
+ List<Map<String,Object>> oldChapterList=chapterService.queryAllList(param);
|
|
|
+ //2.查回课程所有课时信息进行复制
|
|
|
+ List<String> oldChapterIdList= oldChapterList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
param.clear();
|
|
|
- param.put("chapterIdList", chapterIdList);
|
|
|
+ param.put("chapterIdList", oldChapterIdList);
|
|
|
//只查出资源审核通过的课时
|
|
|
param.put("verifyPass", "1");
|
|
|
- List<Map<String,Object>> classHourList =classHourService.queryAllList(param);
|
|
|
+ List<Map<String,Object>> oldClassHourList =classHourService.queryAllList(param);
|
|
|
+ //3.再查出对应章节以及课时共同的关联信息
|
|
|
+ List<String> oldClassHourIdList= oldClassHourList.stream().map(map -> (String) map.get("id")).collect(Collectors.toList());
|
|
|
+ param.clear();
|
|
|
+ param.put("mainIdList", oldChapterIdList);
|
|
|
+ param.put("chapterhourType", 0);
|
|
|
+ //根据chapterhourType章节课时类型进行进一步区分
|
|
|
+ List<CourseRelate> oldChapterRelateList=courseRelateService.wrapperList(param);
|
|
|
+ param.clear();
|
|
|
+ param.put("mainIdList", oldClassHourIdList);
|
|
|
+ param.put("chapterhourType", 1);
|
|
|
+ List<CourseRelate> oldClassHourRelateList=courseRelateService.wrapperList(param);
|
|
|
+
|
|
|
//进行复制步骤
|
|
|
//1.添加课程信息
|
|
|
CourseInfo newCourseInfo=new CourseInfo();
|
|
|
BeanUtil.copyProperties(courseInfo, newCourseInfo);
|
|
|
newCourseInfo.setCourseId(null);
|
|
|
newCourseInfo=courseInfoService.addOne(newCourseInfo);
|
|
|
- //2.添加章节和对应课时信息
|
|
|
+ //2.添加章节和对应课时信息,以及关联信息
|
|
|
//预添加章节列表
|
|
|
List<Chapter> chapterAddList=new ArrayList<>();
|
|
|
//预添加课时列表
|
|
|
List<ClassHour> classHourAddList=new ArrayList<>();
|
|
|
+ //预添加关联表
|
|
|
+ List<CourseRelate> courseRelateAddList=new ArrayList<>();
|
|
|
|
|
|
- for (Map<String, Object> chapter : chapterList) {
|
|
|
+ for (Map<String, Object> chapter : oldChapterList) {
|
|
|
if (chapter == null || chapter.get("id") == null) continue;
|
|
|
//先预先准备该章节信息
|
|
|
Chapter addChapter=new Chapter();
|
|
|
@@ -339,39 +350,74 @@ public class CourseInfoController {
|
|
|
addChapter.setId(willAddChapterId);
|
|
|
addChapter.setCourseId(newCourseInfo.getCourseId());
|
|
|
addChapter.setName(chapter.get("name").toString());
|
|
|
- addChapter.setPid(chapter.get("pid").toString());
|
|
|
+ if(ObjectUtil.isNotEmpty(chapter.get("pid")))addChapter.setPid(chapter.get("pid").toString());
|
|
|
+ //预添加章节列表增加一条章节信息
|
|
|
chapterAddList.add(addChapter);
|
|
|
|
|
|
- String chapterId = chapter.get("id").toString();
|
|
|
- List<Map<String, Object>> chapterClassHours = new ArrayList<>();
|
|
|
+ //准备章节关联信息
|
|
|
+ String oldChapterId = chapter.get("id").toString();
|
|
|
+ for (int i = oldChapterRelateList.size() - 1; i >= 0; i--) {
|
|
|
+ CourseRelate chapterRelate = oldChapterRelateList.get(i);
|
|
|
+ // 匹配当前章节
|
|
|
+ if (oldChapterId.equals(chapterRelate.getMainId())) {
|
|
|
+ CourseRelate addChapterRelate =new CourseRelate();
|
|
|
+ addChapterRelate.setId(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ addChapterRelate.setMainId(willAddChapterId);
|
|
|
+ addChapterRelate.setRelateId(chapterRelate.getRelateId());
|
|
|
+ addChapterRelate.setFuncType(chapterRelate.getFuncType());
|
|
|
+ addChapterRelate.setChapterhourType(chapterRelate.getChapterhourType());
|
|
|
+ addChapterRelate.setInfoType(chapterRelate.getInfoType());
|
|
|
+ //预添加关联表增加一条章节关联信息
|
|
|
+ courseRelateAddList.add(addChapterRelate);
|
|
|
+ //为效率,匹配完的从列表中剔除
|
|
|
+ oldChapterRelateList.remove(i); // 从原列表删除(安全操作)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 2. 倒序遍历课程列表(关键点!)
|
|
|
- for (int i = classHourList.size() - 1; i >= 0; i--) {
|
|
|
- Map<String, Object> classHour = classHourList.get(i);
|
|
|
+ for (int i = oldClassHourList.size() - 1; i >= 0; i--) {
|
|
|
+ Map<String, Object> classHour = oldClassHourList.get(i);
|
|
|
if (classHour == null || classHour.get("chapterId") == null) continue;
|
|
|
|
|
|
// 3. 匹配当前章节
|
|
|
- if (chapterId.equals(classHour.get("chapterId").toString())) {
|
|
|
+ if (oldChapterId.equals(classHour.get("chapterId").toString())) {
|
|
|
//预先准备该课时信息
|
|
|
ClassHour addClassHour=new ClassHour();
|
|
|
addClassHour.setId(IdUtil.getSnowflakeNextIdStr());
|
|
|
addClassHour.setChapterId(willAddChapterId);
|
|
|
addClassHour.setName(classHour.get("name").toString());
|
|
|
- if(StringUtils.isEmpty(classHour.get("startTime").toString()))addClassHour.setStartTime(new Date(classHour.get("startTime").toString()));
|
|
|
- if(StringUtils.isEmpty(classHour.get("endTime").toString()))addClassHour.setEndTime(new Date(classHour.get("endTime").toString()));
|
|
|
- addClassHour.setVideoResource(classHour.get("videoResource").toString());
|
|
|
- addClassHour.setTeachmaterialsFile(classHour.get("teachmaterialsFile").toString());
|
|
|
- addClassHour.setSubtitleFile(classHour.get("subtitleFile").toString());
|
|
|
- addClassHour.setRemark(classHour.get("remark").toString());
|
|
|
+ if(ObjectUtil.isNotEmpty(classHour.get("startTime")))addClassHour.setStartTime(new Date(classHour.get("startTime").toString()));
|
|
|
+ if(ObjectUtil.isNotEmpty(classHour.get("endTime")))addClassHour.setEndTime(new Date(classHour.get("endTime").toString()));
|
|
|
+ if(ObjectUtil.isNotEmpty(classHour.get("remark")))addClassHour.setRemark(classHour.get("remark").toString());
|
|
|
classHourAddList.add(addClassHour);
|
|
|
|
|
|
+ //准备课时关联信息
|
|
|
+ String oldClassHourId = classHour.get("id").toString();
|
|
|
+ for (int j = oldClassHourRelateList.size() - 1; j >= 0; j--) {
|
|
|
+ CourseRelate classHourRelate = oldClassHourRelateList.get(j);
|
|
|
+ if (oldClassHourId.equals(classHourRelate.getMainId())) {
|
|
|
+ CourseRelate addClassHourRelate =new CourseRelate();
|
|
|
+ addClassHourRelate.setId(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ addClassHourRelate.setMainId(addClassHour.getId());
|
|
|
+ addClassHourRelate.setRelateId(classHourRelate.getRelateId());
|
|
|
+ addClassHourRelate.setFuncType(classHourRelate.getFuncType());
|
|
|
+ addClassHourRelate.setChapterhourType(classHourRelate.getChapterhourType());
|
|
|
+ addClassHourRelate.setInfoType(classHourRelate.getInfoType());
|
|
|
+ //预添加关联表增加一条课时关联信息
|
|
|
+ courseRelateAddList.add(addClassHourRelate);
|
|
|
+ //为效率,匹配完的从列表中剔除
|
|
|
+ oldClassHourRelateList.remove(j);// 从原列表删除(安全操作)
|
|
|
+ }
|
|
|
+ }
|
|
|
//为效率,匹配完的从列表中剔除
|
|
|
- classHourList.remove(i); // 从原列表删除(安全操作)
|
|
|
+ oldClassHourList.remove(i); // 从原列表删除(安全操作)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- chapter.put("classHours", chapterClassHours);
|
|
|
}
|
|
|
+ //存储章节和课时以及关联信息
|
|
|
+ chapterService.addBatch(chapterAddList);
|
|
|
+ classHourService.addBatch(classHourAddList);
|
|
|
+ courseRelateService.addBatch(courseRelateAddList);
|
|
|
|
|
|
return CommonResult.ok();
|
|
|
}
|