Browse Source

1.课程管理新增复制课程功能

jzp 4 ngày trước cách đây
mục cha
commit
9130f6ef5d

+ 12 - 0
fs-admin/src/main/java/com/fs/course/controller/FsUserCourseController.java

@@ -164,6 +164,18 @@ public class FsUserCourseController extends BaseController
         return toAjax(1);
     }
 
+    /**
+     * 复制课程
+     */
+    @PreAuthorize("@ss.hasPermi('course:userCourse:copy')")
+    @Log(title = "课程", businessType = BusinessType.DELETE)
+    @GetMapping("/copy/{courseId}")
+    public AjaxResult copy(@PathVariable Long courseId)
+    {
+        int i = fsUserCourseService.copyFsUserCourse(courseId);
+        return toAjax(i);
+    }
+
     /**
      * 删除课程
      */

+ 1 - 1
fs-service/src/main/java/com/fs/course/mapper/FsUserCourseMapper.java

@@ -217,7 +217,7 @@ public interface FsUserCourseMapper
             "<if test = ' maps.isShow !=null '> " +
             "and c.is_show = #{maps.isShow} " +
             "</if>" +
-            " order by c.course_id  "+
+            " order by c.sort,c.course_id  "+
             "</script>"})
     List<FsUserCourseListPVO> selectFsUserCourseListCompanyPVO(@Param("maps")FsUserCourseParam fsUserCourse);
 

+ 3 - 0
fs-service/src/main/java/com/fs/course/service/IFsUserCourseService.java

@@ -122,4 +122,7 @@ public interface IFsUserCourseService
     String createCourseImageQR(String url, String backgroundImagePath, InputStream file, String outputFormat, String title, String duration) throws Exception;
 
     String createUserImageQR(@NotNull(message = "链接不能为空") String realLink, String backgroundImagePath, InputStream inputStream, String png, @NotNull(message = "销售id不能为空") Long companyUserId) throws Exception;
+
+    int copyFsUserCourse(Long courseId);
+
 }

+ 34 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseServiceImpl.java

@@ -25,6 +25,7 @@ import com.fs.course.domain.*;
 import com.fs.course.mapper.*;
 import com.fs.course.param.*;
 import com.fs.course.param.newfs.FsUserCourseListParam;
+import com.fs.course.service.IFsUserCourseVideoService;
 import com.fs.course.vo.*;
 import com.fs.course.vo.newfs.FsUserCourseListVO;
 import com.fs.his.config.IntegralConfig;
@@ -102,6 +103,12 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
     @Autowired
     private QwApiService qwApiService;
 
+    @Autowired
+    private IFsUserCourseService fsUserCourseService;
+
+    @Autowired
+    private IFsUserCourseVideoService fsUserCourseVideoService;
+
     @Autowired
     private RedisCache redisCache;
     private static final String realLink = "/courseH5/pages/course/learning?course=";
@@ -609,6 +616,33 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
         return convertToBase64(combined, outputFormat);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class) // 显式声明事务
+    public int copyFsUserCourse(Long courseId) {
+        FsUserCourse fsUserCourse = fsUserCourseService.selectFsUserCourseByCourseId(courseId);
+        if(fsUserCourse != null){
+            fsUserCourse.setCourseId(null);
+            fsUserCourseService.insertFsUserCourse(fsUserCourse);
+            Long newCourseId = fsUserCourse.getCourseId();
+
+            if (newCourseId == null) {
+                throw new RuntimeException("课程插入失败,无法获取新课程ID");
+            }
+
+            FsUserCourseVideo fsUserCourseVideo = new FsUserCourseVideo();
+            fsUserCourseVideo.setCourseId(courseId);
+            List<FsUserCourseVideo> list = fsUserCourseVideoService.selectFsUserCourseVideoListByCourseId(fsUserCourseVideo);
+            for (FsUserCourseVideo courseVideo : list) {
+                courseVideo.setVideoId(null);
+                courseVideo.setCourseId(newCourseId);
+                fsUserCourseVideoService.insertFsUserCourseVideo(courseVideo);
+            }
+            return 1;
+        }
+
+        return 0;
+    }
+
 
     private Graphics2D initializeGraphics(BufferedImage combined) {
         Graphics2D graphics = combined.createGraphics();