zhaowenyu
2026-01-06 4e8a1c02b45f72f6377603778e8c8746ed82f374
ard-quartz/src/main/java/com/ard/quartz/task/MediaTask.java
@@ -113,7 +113,12 @@
    }
    private void processOneVideo(ArdMediaVideo video) {
        try {
        int maxRetries = 3;       // 最大重试次数
        int retryDelay = 3000;    // 每次重试等待 3 秒
        int attempt = 0;
        while (attempt < maxRetries) {
            attempt++;
            try (InputStream is = openUrlInputStream(video.getSourceUrl())) {
                if (is != null) {
                    String mediaUrl = ossServiceContext.upload(
@@ -123,26 +128,46 @@
                            MimeTypeUtils.VIDEO_MP4
                    );
                    video.setMediaUrl(mediaUrl);
                    // 生成视频缩略图
                    processVideoThumbnail(video);
                    video.setSyncStatus(2); // 成功
                    break; // 上传成功,退出循环
                } else {
                    log.warn("视频尚未生成,尝试重试 {}/{}", attempt, maxRetries);
                }
            } catch (Exception e) {
                log.error("视频同步异常 videoId={}, 尝试 {}/{}", video.getId(), attempt, maxRetries, e);
            }
            processVideoThumbnail(video);
            video.setSyncStatus(2);
        } catch (Exception e) {
            video.setSyncStatus(3);
            log.error("视频处理失败 videoId={}", video.getId(), e);
        } finally {
            video.setUpdateTime(new Date());
            try {
                ardMediaVideoMapper.updateArdMediaVideo(video);
            } catch (Exception e) {
                log.error("更新视频状态失败 videoId={}", video.getId(), e);
            if (attempt < maxRetries) {
                try {
                    Thread.sleep(retryDelay);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    break;
                }
            } else {
                video.setSyncStatus(3); // 达到最大重试仍失败
            }
        }
        video.setUpdateTime(new Date());
        try {
            ardMediaVideoMapper.updateArdMediaVideo(video);
        } catch (Exception e) {
            log.error("更新视频状态失败 videoId={}", video.getId(), e);
        }
    }
    private void processOnePic(ArdMediaPic pic) {
        try {
        int maxRetries = 3; // 最大重试次数
        int retryDelay = 2000; // 每次重试等待 2 秒
        int attempt = 0;
        while (attempt < maxRetries) {
            attempt++;
            try (InputStream inputStream = openUrlInputStream(pic.getSourceUrl())) {
                if (inputStream != null) {
                    String url = ossServiceContext.upload(
@@ -153,20 +178,31 @@
                    );
                    pic.setMediaUrl(url);
                    pic.setSyncStatus(2); // 成功
                    break; // 上传成功,退出循环
                } else {
                    pic.setSyncStatus(3); // 下载失败
                    log.warn("图片尚未生成,尝试重试 {}/{}", attempt, maxRetries);
                }
            }
        } catch (Exception e) {
            log.error("图片同步失败 taskId={}, photoId={}", pic.getTaskId(), pic.getId(), e);
            pic.setSyncStatus(3); // 异常
        } finally {
            pic.setUpdateTime(new Date());
            try {
                ardMediaPicMapper.updatePic(pic);
            } catch (Exception e) {
                log.error("更新图片状态失败 photoId={}", pic.getId(), e);
                log.error("图片同步异常 taskId={}, photoId={}, 尝试 {}/{}", pic.getTaskId(), pic.getId(), attempt, maxRetries, e);
            }
            if (attempt < maxRetries) {
                try {
                    Thread.sleep(retryDelay);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    break;
                }
            } else {
                pic.setSyncStatus(3); // 达到最大重试仍失败
            }
        }
        pic.setUpdateTime(new Date());
        try {
            ardMediaPicMapper.updatePic(pic);
        } catch (Exception e) {
            log.error("更新图片状态失败 photoId={}", pic.getId(), e);
        }
    }