Kaynağa Gözat

国际看课调整直播

yfh 1 gün önce
ebeveyn
işleme
3212e94fb5

+ 15 - 0
fs-service/src/main/java/com/fs/course/service/IFsUserCourseVideoService.java

@@ -245,4 +245,19 @@ public interface IFsUserCourseVideoService extends IService<FsUserCourseVideo> {
     R createRoomMiniLinkByCourse(FsCourseLinkRoomNewParam param);
 
     void updateMediaPublishStatus(String vid);
+
+    /**
+     * 国际看课详情
+     * @param param
+     * @return
+     */
+    ResponseResult<FsUserCourseVideoLinkDetailsVO> getCourseGjVideoDetails(FsUserCourseVideoLinkParam param);
+
+    /**
+     * 国际看课流量
+     *
+     * @param param
+     * @return
+     */
+    R getGjInternetTraffic(FsUserCourseVideoFinishUParam param);
 }

+ 90 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1284,6 +1284,61 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
         return R.ok();
     }
 
+    @Transactional
+    @Override
+    public R getGjInternetTraffic(FsUserCourseVideoFinishUParam param) {
+        try {
+            if (param.getBufferRate() == null) {
+                logger.error("【缓冲值空】参数: {}", param);
+                return R.error("缓冲值空");
+            }
+            FsCourseTrafficLog trafficLog = new FsCourseTrafficLog();
+            trafficLog.setCreateTime(new Date());
+            BeanUtils.copyProperties(param, trafficLog);
+
+            FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
+            if (video == null) {
+                return R.error("视频不存在");
+            }
+            Company company = companyMapper.selectCompanyById(param.getCompanyId());
+            if (company == null) {
+                return R.error("公司不存在");
+            }
+
+            // 实际流量传输消耗是大于文件的,添加倍数计算流量消耗 配置 course.data.usage.multiple
+            BigDecimal multiple = new BigDecimal("1"); // 默认一倍
+            String config=configService.selectConfigByKey("course.data.usage.multiple");
+            if(StringUtils.isNotEmpty(config)){
+                multiple=new BigDecimal(config);
+            }
+
+            // 计算流量
+            BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
+            BigDecimal longAsBigDecimal = BigDecimal.valueOf(video.getFileSize());
+            long roundedResult = result.multiply(longAsBigDecimal).multiply(multiple).setScale(0, RoundingMode.HALF_UP).longValue();
+            trafficLog.setInternetTraffic(roundedResult);
+            // 获取课程所属项目id
+            FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(param.getCourseId());
+            if (fsUserCourse != null) {
+                trafficLog.setProject(fsUserCourse.getProject());
+            }
+
+            // 处理 UUID 为空的情况
+            if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
+                // 插入或更新
+                fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
+                asyncDeductTraffic(company, trafficLog);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            // 打印参数param和异常信息
+            logger.error("【插入或更新流量失败】参数: {}, 错误信息:{}", param, e.getMessage(), e);
+            return R.error();
+        }
+        return R.ok();
+    }
+
+
     public void asyncDeductTraffic(Company company, FsCourseTrafficLog trafficLog) {
         try {
             //根据uuid查询
@@ -2916,6 +2971,41 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
         return ResponseResult.ok(vo);
     }
 
+
+    @Override
+    public ResponseResult<FsUserCourseVideoLinkDetailsVO> getCourseGjVideoDetails(FsUserCourseVideoLinkParam param) {
+
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+
+        // 1、获取视频详情、问题详情
+        ResponseResult<FsUserCourseVideoDetailsVO> videoDetails = this.getVideoDetails(param.getVideoId());
+        FsUserCourseVideoDetailsVO courseVideoDetails = videoDetails.getData() != null ? videoDetails.getData() : null;
+
+        //课程logo
+        if (param.getPeriodId() != null) {
+            FsUserCoursePeriod fsUserCoursePeriod = fsUserCoursePeriodMapper.selectFsUserCoursePeriodById(param.getPeriodId());
+            if (fsUserCoursePeriod != null) {
+                config.setCourseLogo(fsUserCoursePeriod.getCourseLogo());
+            }
+        }
+
+        long duration = 0L;
+        long tipsTime = 0L;
+        long tipsTime2 = 0L;
+        int isFinish = 0;
+        FsUserCourseVideoLinkDetailsVO vo = new FsUserCourseVideoLinkDetailsVO();
+        vo.setCourseVideoDetails(courseVideoDetails);
+        vo.setCourseConfig(config);
+        vo.setIsFinish(isFinish);
+        vo.setPlayDuration(duration);
+        vo.setTipsTime(tipsTime);
+        vo.setTipsTime2(tipsTime2);
+        vo.setIsFinish(isFinish);
+        vo.setPlayDuration(duration);
+        return ResponseResult.ok(vo);
+    }
+
     /**
      * @Description: 是否看课中断
      * @Param:

+ 16 - 0
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -112,6 +112,14 @@ public class CourseFsUserController extends AppBaseController {
         return courseVideoService.getLinkCourseVideoDetails(param);
     }
 
+    @Login
+    @ApiOperation("H5国际课程详情")
+    @GetMapping("/getCourseGjVideoDetails")
+    @UserOperationLog(operationType = FsUserOperationEnum.STUDY)
+    public ResponseResult<FsUserCourseVideoLinkDetailsVO> getCourseGjVideoDetails(FsUserCourseVideoLinkParam param) {
+        return courseVideoService.getCourseGjVideoDetails(param);
+    }
+
     @ApiOperation("获取真实链接")
     @GetMapping("/getRealLink")
     public R getRealLink(@RequestParam("sortLink")String link)
@@ -138,6 +146,14 @@ public class CourseFsUserController extends AppBaseController {
     }
 
 
+    @ApiOperation("获取国际缓冲流量")
+    @PostMapping("/getInternetTraffic")
+    @Login
+    public R getGjInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param) {
+        return courseVideoService.getGjInternetTraffic(param);
+    }
+
+
     @ApiOperation("答题")
     @PostMapping("/courseAnswer")
     @UserOperationLog(operationType = FsUserOperationEnum.ANSWER)