zyp 2 months ago
parent
commit
d0eac2068a
1 changed files with 125 additions and 0 deletions
  1. 125 0
      fs-user-app/src/main/java/com/fs/app/controller/CourseH5Controller.java

+ 125 - 0
fs-user-app/src/main/java/com/fs/app/controller/CourseH5Controller.java

@@ -0,0 +1,125 @@
+package com.fs.app.controller;
+
+
+import cn.hutool.json.JSONUtil;
+import com.fs.common.core.domain.R;
+import com.fs.course.config.CourseConfig;
+import com.fs.course.domain.FsCourseWatchLog;
+import com.fs.course.param.FsUserCourseVideoFinishUParam;
+import com.fs.course.service.IFsCourseLinkService;
+import com.fs.course.service.IFsCourseWatchLogService;
+import com.fs.course.service.IFsUserCourseService;
+import com.fs.course.service.IFsUserCourseVideoService;
+import com.fs.course.vo.FsUserCourseVideoH5DVO;
+import com.fs.course.vo.FsUserCourseVideoH5VO;
+import com.fs.system.service.ISysConfigService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+@Api("h5课堂接口")
+@RestController
+@RequestMapping(value="/app/course/h5")
+public class CourseH5Controller extends  AppBaseController{
+    Logger logger= LoggerFactory.getLogger(getClass());
+    @Autowired
+    private IFsUserCourseService courseService;
+
+    @Autowired
+    private IFsUserCourseVideoService courseVideoService;
+
+    @Autowired
+    private ISysConfigService configService;
+    @Autowired
+    private IFsCourseLinkService courseLinkService;
+
+    @Autowired
+    private IFsCourseWatchLogService courseWatchLogService;
+
+
+    @ApiOperation("h5课程简介")
+    @GetMapping("/getH5CourseByVideoId")
+    public R getCourseByVideoId(@RequestParam("videoId") Long videoId,HttpServletRequest request)
+    {
+        FsUserCourseVideoH5VO course = courseService.selectFsUserCourseVideoH5VOByVideoId(videoId);
+        return R.ok().put("data",course);
+    }
+
+    @ApiOperation("h5课程详情")
+    @GetMapping("/getH5CourseVideoDetails")
+    public R getCourseVideoDetails(FsUserCourseVideoFinishUParam param)
+    {
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+        FsUserCourseVideoH5DVO course = courseService.selectFsUserCourseVideoH5DVOByVideoId(param.getVideoId());
+
+        Long duration = 0L;
+        long tipsTime = 0L;
+        int isFinish = 0;
+        if (param.getLinkType()!=null&&param.getLinkType()==1){
+            return R.ok().put("course",course).put("config",config).put("playDuration",duration).put("tipsTime",tipsTime).put("maxBufferLength",config.getMaxBufferLength());
+        }
+        // 从Redis中获取观看时长
+        String redisKey = "h5user:watch:duration:" + param.getQwUserId()+ ":" + param.getQwExternalId() + ":" + param.getVideoId();
+        String durationStr = redisCache.getCacheObject(redisKey);
+        FsCourseWatchLog log = courseWatchLogService.getWatchCourseVideoH5(param.getVideoId(),param.getQwUserId(),param.getQwExternalId());
+        //redis取不到查库
+        if (durationStr != null) {
+            duration = Long.parseLong(durationStr);
+        }else {
+            duration = log.getDuration();
+        }
+
+        if (course.getDuration()!=null){
+            tipsTime = course.getDuration()/2;
+        }
+        //判断是否完课
+        if (log.getLogType()==2){
+           isFinish=1;
+        }
+
+        //将视频时长也存到redis
+        String videoRedisKey = "h5user:video:duration:" + param.getVideoId();
+        Long videoDuration = redisCache.getCacheObject(videoRedisKey);
+        if (videoDuration==null){
+            redisCache.setCacheObject(videoRedisKey,course.getDuration());
+        }
+
+        return R.ok().put("course",course).put("config",config).put("playDuration",duration).put("tipsTime",tipsTime).put("maxBufferLength",config.getMaxBufferLength()).put("isFinish",isFinish);
+    }
+
+
+
+    @ApiOperation("获取真实链接")
+    @GetMapping("/getRealLink")
+    public R getRealLink(@RequestParam("sortLink")String link)
+    {
+        return courseLinkService.getRealLink(link);
+    }
+
+
+    @ApiOperation("更新看课时长")
+    @PostMapping("/updateWatchDuration")
+    public R updateWatchDuration(@RequestBody FsUserCourseVideoFinishUParam param)
+    {
+        return courseVideoService.updateWatchDuration(param);
+    }
+
+
+    @ApiOperation("获取缓冲流量")
+    @PostMapping("/getInternetTraffic")
+    public R getInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param) {
+        return courseVideoService.getInternetTraffic(param);
+    }
+
+    @PostMapping("/getErrMsg")
+    public void getErrMsg(@RequestParam("msg") String msg) {
+        logger.error("zyp \n【h5看课中途报错】:{}",msg);
+    }
+
+}