Преглед изворни кода

fix:课程视频关联小黄车

ct пре 1 недеља
родитељ
комит
e649101d74

+ 13 - 10
fs-admin/src/main/java/com/fs/course/controller/FsUserCourseVideoController.java

@@ -128,41 +128,44 @@ public class FsUserCourseVideoController extends BaseController
     @PreAuthorize("@ss.hasPermi('course:userCourseVideo:add')")
     @Log(title = "课堂视频", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody FsUserCourseVideoAddAndUpdateParam param)
-    {
-        Long count = fsUserCourseVideoMapper.selectFsUserCourseVideoByCourseSort(param.getCourseId(),param.getCourseSort());
-        if (count>0){
+    public AjaxResult add(@RequestBody FsUserCourseVideoAddAndUpdateParam param) {
+        Long count = fsUserCourseVideoMapper.selectFsUserCourseVideoByCourseSort(param.getCourseId(), param.getCourseSort());
+        if (count > 0) {
             return AjaxResult.error("课程排序重复");
         }
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         Long userId = loginUser.getUser().getUserId();
         String json = configService.selectConfigByKey("course.config");
         CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
-        if (ObjectUtil.isNotEmpty(config.getIsBound())&&config.getIsBound()){
+        if (ObjectUtil.isNotEmpty(config.getIsBound()) && config.getIsBound()) {
             param.setUserId(userId);
         }
         // 设置项目ID
         FsUserCourse fsUserCourse = fsUserCourseService.selectFsUserCourseByCourseId(param.getCourseId());
         param.setProjectId(fsUserCourse.getProject());
         Integer showTreatment = param.getShowTreatment();
-        if (showTreatment != null){
+        FsUserCourseVideo fsUserCourseVideo = BeanUtil.copyProperties(param, FsUserCourseVideo.class);
+        int result = fsUserCourseVideoService.insertFsUserCourseVideo(fsUserCourseVideo);
+        if (showTreatment != null && result > 0) {
             // 先检查是否存在相同记录
             QueryWrapper<FsDepVideoShow> queryWrapper = new QueryWrapper<>();
-            Long videoId = param.getVideoId();
+            Long videoId = fsUserCourseVideo.getVideoId();
             queryWrapper.eq("video_id", videoId);
             FsDepVideoShow fsDepVideoShow = fsDepVideoShowMapper.selectOne(queryWrapper);
-            int result;
+
             if (fsDepVideoShow != null) {
                 // 更新现有记录
                 fsDepVideoShow.setIsShow(showTreatment.toString());
                 fsDepVideoShowMapper.updateByVideoId(fsDepVideoShow);
             } else {
                 // 插入新记录
+                fsDepVideoShow =  new FsDepVideoShow();
+                fsDepVideoShow.setIsShow(showTreatment.toString());
+                fsDepVideoShow.setVideoId(videoId);
                 fsDepVideoShowMapper.insertFsDepVideoShowByVideoId(fsDepVideoShow);
             }
         }
-        FsUserCourseVideo fsUserCourseVideo = BeanUtil.copyProperties(param, FsUserCourseVideo.class);
-        return toAjax(fsUserCourseVideoService.insertFsUserCourseVideo(fsUserCourseVideo));
+        return toAjax(result);
     }
 
     /**