|
@@ -194,6 +194,9 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsCourseLinkMapper fsCourseLinkMapper;
|
|
private FsCourseLinkMapper fsCourseLinkMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsUserVideoMapper fsUserVideoMapper;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedissonClient redissonClient;
|
|
private RedissonClient redissonClient;
|
|
@@ -1322,20 +1325,53 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
trafficLog.setCreateTime(new Date());
|
|
trafficLog.setCreateTime(new Date());
|
|
|
BeanUtils.copyProperties(param, trafficLog);
|
|
BeanUtils.copyProperties(param, trafficLog);
|
|
|
|
|
|
|
|
- FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
|
|
- if (video == null) {
|
|
|
|
|
- return R.error("视频不存在");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Long fileSize = 0L;
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(param.getIsPublic()) && param.getIsPublic().equals(0)) {
|
|
|
|
|
+ FsUserVideo video = fsUserVideoMapper.selectFsUserVideoByVideoId(String.valueOf(param.getVideoId()));
|
|
|
|
|
+ if (video == null) {
|
|
|
|
|
+ return R.error("视频不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 优先从Redis缓存获取文件大小
|
|
|
|
|
+ String fileSizeRedisKey = "public:course:video:fileSize:" + param.getVideoId();
|
|
|
|
|
+ String cachedFileSize = redisCache.getCacheObject(fileSizeRedisKey);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(cachedFileSize)) {
|
|
|
|
|
+ fileSize = Long.parseLong(cachedFileSize);
|
|
|
|
|
+ } else if (StringUtils.isNotEmpty(video.getUrl())) {
|
|
|
|
|
+ // 缓存未命中,通过视频URL的HEAD请求获取文件大小
|
|
|
|
|
+ try {
|
|
|
|
|
+ java.net.HttpURLConnection conn = (java.net.HttpURLConnection) new java.net.URL(video.getUrl()).openConnection();
|
|
|
|
|
+ conn.setRequestMethod("HEAD");
|
|
|
|
|
+ conn.setConnectTimeout(5000);
|
|
|
|
|
+ conn.setReadTimeout(5000);
|
|
|
|
|
+ int contentLength = conn.getContentLength();
|
|
|
|
|
+ conn.disconnect();
|
|
|
|
|
+ if (contentLength > 0) {
|
|
|
|
|
+ fileSize = (long) contentLength;
|
|
|
|
|
+ // 写入Redis缓存,7天过期
|
|
|
|
|
+ redisCache.setCacheObject(fileSizeRedisKey, String.valueOf(fileSize), 7, java.util.concurrent.TimeUnit.DAYS);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ logger.warn("【公开课】通过URL获取文件大小失败, videoId: {}, url: {}, error: {}", param.getVideoId(), video.getUrl(), ex.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
|
|
+ if (video == null) {
|
|
|
|
|
+ return R.error("视频不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ fileSize = video.getFileSize();
|
|
|
// Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
// Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
// if (company == null) {
|
|
// if (company == null) {
|
|
|
// return R.error("公司不存在");
|
|
// return R.error("公司不存在");
|
|
|
// }
|
|
// }
|
|
|
- FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(param.getCourseId());
|
|
|
|
|
- if (fsUserCourse != null) {
|
|
|
|
|
- trafficLog.setProjectId(fsUserCourse.getProject());
|
|
|
|
|
|
|
+ FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(param.getCourseId());
|
|
|
|
|
+ if (fsUserCourse != null) {
|
|
|
|
|
+ trafficLog.setProjectId(fsUserCourse.getProject());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
|
|
BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
|
|
|
- BigDecimal longAsBigDecimal = BigDecimal.valueOf(video.getFileSize());
|
|
|
|
|
|
|
+ BigDecimal longAsBigDecimal = BigDecimal.valueOf(fileSize);
|
|
|
long roundedResult = result.multiply(longAsBigDecimal).setScale(0, RoundingMode.HALF_UP).longValue();
|
|
long roundedResult = result.multiply(longAsBigDecimal).setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
trafficLog.setInternetTraffic(roundedResult);
|
|
trafficLog.setInternetTraffic(roundedResult);
|
|
|
|
|
|