|
|
@@ -4075,10 +4075,11 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
//用户额外信息,最大长度 512 字节。
|
|
|
uRLSetsBuilder.setCallbackArgs("");
|
|
|
// 火山云存储路径(文件上传后在火山云的路径)
|
|
|
- String datePath = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
- String fileName = System.currentTimeMillis() + ".mp4";
|
|
|
- String remoteFileName = "fs/" + datePath + "/" + fileName;
|
|
|
- uRLSetsBuilder.setFileName(remoteFileName);
|
|
|
+// String datePath = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
+// String fileName = System.currentTimeMillis() + ".mp4";
|
|
|
+// String remoteFileName = "fs/" + datePath + "/" + fileName;
|
|
|
+
|
|
|
+ uRLSetsBuilder.setFileName(courseVideo.getFileKey());
|
|
|
reqBuilder.addURLSets(uRLSetsBuilder);
|
|
|
|
|
|
VodUrlUploadResponse resp = vodService.uploadMediaByUrl(reqBuilder.build());
|
|
|
@@ -4123,7 +4124,7 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
for (FsUserCourseVideo video : batch) {
|
|
|
uploadExecutor.submit(() -> {
|
|
|
try {
|
|
|
- uploadSingleTaskWithRetry(video);
|
|
|
+ uploadSingleTaskWithRetry(video,1);
|
|
|
} finally {
|
|
|
latch.countDown();
|
|
|
}
|
|
|
@@ -4144,6 +4145,53 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
log.info("全部批次执行完成");
|
|
|
return R.ok();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getVideoInfoByVid() {
|
|
|
+ // 查询有JobId的视频
|
|
|
+ List<FsUserCourseVideo> list = fsUserCourseVideoMapper.selectVideoByVid();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ log.info("没有包含vid的视频");
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ // 按五百一批切割
|
|
|
+ List<List<FsUserCourseVideo>> batches = splitList(list, 500);
|
|
|
+ log.info("总任务 {} 条,分成 {} 批", list.size(), batches.size());
|
|
|
+
|
|
|
+ int batchIndex = 1;
|
|
|
+
|
|
|
+ // 批次顺序执行,每批内部多线程并发执行
|
|
|
+ for (List<FsUserCourseVideo> batch : batches) {
|
|
|
+
|
|
|
+ log.info("开始执行批次 {}/{},本批任务 {} 条", batchIndex, batches.size(), batch.size());
|
|
|
+
|
|
|
+ CountDownLatch latch = new CountDownLatch(batch.size());
|
|
|
+
|
|
|
+ for (FsUserCourseVideo video : batch) {
|
|
|
+ uploadExecutor.submit(() -> {
|
|
|
+ try {
|
|
|
+ uploadSingleTaskWithRetry(video,2);
|
|
|
+ } finally {
|
|
|
+ latch.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 等待这一批全部完成
|
|
|
+ try {
|
|
|
+ latch.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("批次等待异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("批次 {}/{} 执行完成", batchIndex, batches.size());
|
|
|
+ batchIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("全部批次执行完成");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
private final ExecutorService uploadExecutor = new ThreadPoolExecutor(
|
|
|
8, // core
|
|
|
16, // max
|
|
|
@@ -4202,10 +4250,16 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
System.out.println(resp.getResponseMetadata().getError());
|
|
|
System.exit(-1);
|
|
|
}else {
|
|
|
+ //更新小节
|
|
|
FsUserCourseVideo video = new FsUserCourseVideo();
|
|
|
video.setVideoId(courseVideo.getVideoId());
|
|
|
- video.setLineTwo(resp.getResult().getMediaInfoList(0).getSourceInfo().getStoreUri());
|
|
|
+ String url = cloudHostProper.volcengineUrl+"/"+resp.getResult().getMediaInfoList(0).getSourceInfo().getStoreUri();
|
|
|
+ video.setLineTwo(url);
|
|
|
fsUserCourseVideoMapper.updateFsUserCourseVideo(video);
|
|
|
+ //更新视频资源
|
|
|
+ FsVideoResource videoResource = fsVideoResourceMapper.selectByFileKey(courseVideo.getFileKey());
|
|
|
+ videoResource.setLine2(url);
|
|
|
+ fsVideoResourceMapper.updateById(videoResource);
|
|
|
}
|
|
|
System.out.println(resp);
|
|
|
} catch (Exception e) {
|
|
|
@@ -4214,19 +4268,17 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void uploadSingleTaskWithRetry(FsUserCourseVideo courseVideo) {
|
|
|
+ public void uploadSingleTaskWithRetry(FsUserCourseVideo courseVideo,Integer type) {
|
|
|
int maxRetry = 3;
|
|
|
for (int i = 1; i <= maxRetry; i++) {
|
|
|
try {
|
|
|
- //获取上传成功的视频vid,同步到数据库
|
|
|
- getVidByJobId(courseVideo);
|
|
|
- //查询需要上传的视频,上传后将视频任务id存到数据库
|
|
|
-// uploadVideoByUrl(fsUserVideo);
|
|
|
- //根据视频vid获取火山云的视频信息,并同步到数据库
|
|
|
- /**
|
|
|
- * 下面这个方法调用前去润天his_java确认一下,是否一致的
|
|
|
- */
|
|
|
- //getVideoInfoByVid(fsUserVideo);
|
|
|
+ if (type == 1){
|
|
|
+ //获取上传成功的视频vid,同步到数据库
|
|
|
+ getVidByJobId(courseVideo);
|
|
|
+ }else if (type == 2){
|
|
|
+ //获取视频地址同步到线路二
|
|
|
+ getVideoInfoByVid(courseVideo);
|
|
|
+ }
|
|
|
return;
|
|
|
} catch (Exception e) {
|
|
|
log.error("视频 {} 上传失败,第 {} 次重试,原因:{}",
|