Procházet zdrojové kódy

完善课程一键复制,修复bug

honorfire před 7 měsíci
rodič
revize
6d5951a348

+ 2 - 0
snowy-base/snowy-common/src/main/java/vip/xiaonuo/common/util/CommonCryptogramUtil.java

@@ -17,6 +17,7 @@ import com.antherd.smcrypto.sm3.Sm3;
 import com.antherd.smcrypto.sm4.Sm4;
 import com.antherd.smcrypto.sm4.Sm4Options;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
 
 /**
  * 加密工具类,本框架目前使用 https://github.com/antherd/sm-crypto 项目中一些加解密方式
@@ -27,6 +28,7 @@ import lombok.extern.slf4j.Slf4j;
  * @date 2022/9/15 21:51
  */
 @Slf4j
+@Component
 public class CommonCryptogramUtil {
 
     /** 公钥 */

+ 79 - 33
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/controller/CourseInfoController.java

@@ -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();
     }

+ 9 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/ChapterService.java

@@ -15,6 +15,7 @@ package vip.xiaonuo.disk.service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import vip.xiaonuo.disk.domain.Chapter;
+import vip.xiaonuo.disk.domain.ClassHour;
 import vip.xiaonuo.disk.domain.CourseInfo;
 import vip.xiaonuo.disk.param.ChapterAddParam;
 import vip.xiaonuo.disk.param.ChapterEditParam;
@@ -58,6 +59,14 @@ public interface ChapterService extends IService<Chapter> {
      */
     Chapter addOne(Chapter chapter);
 
+    /**
+     * 课程章节-批量添加
+     *
+     * @author honorfire
+     * @date  2025/06/20 14:58
+     */
+    void addBatch(List<Chapter> chapterList);
+
     /**
      * 编辑课程章节表
      *

+ 9 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/ClassHourService.java

@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import vip.xiaonuo.disk.domain.Chapter;
 import vip.xiaonuo.disk.domain.ClassHour;
+import vip.xiaonuo.disk.domain.CourseRelate;
 import vip.xiaonuo.disk.param.ClassHourAddParam;
 import vip.xiaonuo.disk.param.ClassHourEditParam;
 import vip.xiaonuo.disk.param.ClassHourIdParam;
@@ -57,6 +58,14 @@ public interface ClassHourService extends IService<ClassHour> {
      */
     ClassHour addOne(ClassHour classHour);
 
+    /**
+     * 课时-批量添加
+     *
+     * @author honorfire
+     * @date  2025/06/20 14:58
+     */
+    void addBatch(List<ClassHour> classHourList);
+
     /**
      * 编辑课时表
      *

+ 8 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/ChapterServiceImpl.java

@@ -25,6 +25,7 @@ import vip.xiaonuo.common.enums.CommonSortOrderEnum;
 import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
 import vip.xiaonuo.disk.domain.Chapter;
+import vip.xiaonuo.disk.domain.ClassHour;
 import vip.xiaonuo.disk.mapper.ChapterMapper;
 import vip.xiaonuo.disk.param.ChapterAddParam;
 import vip.xiaonuo.disk.param.ChapterEditParam;
@@ -75,6 +76,13 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
         return chapter;
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void addBatch(List<Chapter> chapterList)
+    {
+        this.saveBatch(chapterList);
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void edit(ChapterEditParam chapterEditParam) {

+ 8 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/ClassHourServiceImpl.java

@@ -32,6 +32,7 @@ import vip.xiaonuo.disk.param.ClassHourAddParam;
 import vip.xiaonuo.disk.param.ClassHourEditParam;
 import vip.xiaonuo.disk.param.ClassHourIdParam;
 import vip.xiaonuo.disk.param.ClassHourPageParam;
+import vip.xiaonuo.disk.param.shareGroupuser.ShareGroupUser;
 import vip.xiaonuo.disk.service.ClassHourService;
 import vip.xiaonuo.disk.vo.classhour.ClassHourVo;
 
@@ -69,6 +70,13 @@ public class ClassHourServiceImpl extends ServiceImpl<ClassHourMapper, ClassHour
         return classHour;
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void addBatch(List<ClassHour> classHourList)
+    {
+        this.saveBatch(classHourList);
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void edit(ClassHourEditParam classHourEditParam) {

+ 6 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/CourseRelateServiceImpl.java

@@ -77,6 +77,12 @@ public class CourseRelateServiceImpl extends ServiceImpl<CourseRelateMapper, Cou
         {
             queryWrapper.lambda().eq(CourseRelate::getFuncType, param.get("funcType"));
         }
+        if(ObjectUtil.isNotEmpty(param.get("mainIdList")))
+        {
+            List<String> mainIdList= (List<String>) param.get("mainIdList");
+            queryWrapper.lambda().in(CourseRelate::getMainId, mainIdList);
+        }
+
 
         return this.list(queryWrapper);
     }