ソースを参照

Merge branch 'dev-volcengine' into develop

cmy 4 週間 前
コミット
17491329f6

+ 53 - 42
src/main/java/com/backendsys/modules/ai/volcengine/service/impl/VolcengineVideoTaskServiceImpl.java

@@ -33,6 +33,7 @@ import javax.annotation.PostConstruct;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -74,28 +75,29 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
 
         // 图生视频功能 构建请求参数
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(volcengineVideoTask.getText())) {
-            StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
-            if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
-                text.append(" --rs ").append(volcengineVideoTask.getResolution());
-            }
-            if(volcengineVideoTask.getDuration() != null) {
-                text.append(" --dur ").append(volcengineVideoTask.getDuration());
-            }
-            if(volcengineVideoTask.getCamerafixed() != null) {
-                if (volcengineVideoTask.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
+        if (StringUtils.isBlank(volcengineVideoTask.getText())) {
+            volcengineVideoTask.setText("");
+        }
+        StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
+        if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
+            text.append(" --rs ").append(volcengineVideoTask.getResolution());
+        }
+        if(volcengineVideoTask.getDuration() != null) {
+            text.append(" --dur ").append(volcengineVideoTask.getDuration());
+        }
+        if(volcengineVideoTask.getCamerafixed() != null) {
+            if (volcengineVideoTask.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
             }
-
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
         }
 
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()
                 .type("image_url")
@@ -252,28 +254,30 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
 
         // 图生视频功能 构建请求参数
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(volcengineVideoTask.getText())) {
-            StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
-            if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
-                text.append(" --rs ").append(volcengineVideoTask.getResolution());
-            }
-            if(volcengineVideoTask.getDuration() != null) {
-                text.append(" --dur ").append(volcengineVideoTask.getDuration());
-            }
-            if(volcengineVideoTask.getCamerafixed() != null) {
-                if (volcengineVideoTask.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
+        if (StringUtils.isBlank(volcengineVideoTask.getText())) {
+            volcengineVideoTask.setText("");
+        }
+        StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
+        if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
+            text.append(" --rs ").append(volcengineVideoTask.getResolution());
+        }
+        if(volcengineVideoTask.getDuration() != null) {
+            text.append(" --dur ").append(volcengineVideoTask.getDuration());
+        }
+        if(volcengineVideoTask.getCamerafixed() != null) {
+            if (volcengineVideoTask.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
             }
-
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
         }
 
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
+
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()
                 .type("image_url")
@@ -281,12 +285,14 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
                         .url(volcengineVideoTask.getImg_url())
                         .build())
                 .build());
+
+        String notifyUrl = domain+ "/api/ai/volcengine/video/notify";
         // 创建视频生成任务
         CreateContentGenerationTaskRequest createRequest = CreateContentGenerationTaskRequest.builder()
                 .model(volcengineVideoTask.getModel())
                 .content(contents)
-                // todo callback_url 回调地址
-//                .callbackUrl()
+                // 回调地址
+                .callbackUrl(notifyUrl)
                 .build();
 
         dataBean.setUser_id(volcengineVideoTaskDetail.getUser_id());
@@ -308,8 +314,13 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
         VolcengineVideoTaskDetail dataBean = volcengineVideoTaskDetailService.getOne(Wrappers.<VolcengineVideoTaskDetail>lambdaQuery()
                 .eq(VolcengineVideoTaskDetail::getVolcengine_task_id, notify.getId()));
         if (dataBean == null) {
-            log.error("图生视频通知异常,找不到任务明细,通知内容:" + notify);
-            throw new CustException("图生视频通知异常,找不到任务明细");
+            // 任务状态排队/运行中,可能速度快于平台数据库保存,可忽略,其他状态视为异常
+            if(!Arrays.asList("queued","running").contains(notify.getStatus())){
+                log.error("图生视频通知异常,找不到任务明细,通知内容:" + notify);
+                throw new CustException("图生视频通知异常,找不到任务明细");
+            } else {
+                return;
+            }
         }
 
         if("succeeded".equals(dataBean.getStatus()) || "failed".equals(dataBean.getStatus())) {

+ 22 - 19
src/main/java/com/backendsys/modules/sdk/volcengine/service/impl/VolcengineImage2VideoServiceImpl.java

@@ -35,27 +35,30 @@ public class VolcengineImage2VideoServiceImpl implements VolcengineImage2VideoSe
 
         // 图生视频功能
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(params.getText())) {
-            StringBuilder text = new StringBuilder(params.getText());
-            if(StringUtils.isNotBlank(params.getResolution())) {
-                text.append(" --rs ").append(params.getResolution());
-            }
-            if(params.getDuration() != null) {
-                text.append(" --dur ").append(params.getDuration());
-            }
-            if(params.getCamerafixed() != null) {
-                if (params.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
-            }
+        if (StringUtils.isBlank(params.getText())) {
+            params.setText("");
+        }
 
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
+        StringBuilder text = new StringBuilder(params.getText());
+        if(StringUtils.isNotBlank(params.getResolution())) {
+            text.append(" --rs ").append(params.getResolution());
+        }
+        if(params.getDuration() != null) {
+            text.append(" --dur ").append(params.getDuration());
         }
+        if(params.getCamerafixed() != null) {
+            if (params.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
+            }
+        }
+
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
 
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()

+ 4 - 3
src/main/resources/mapper/ai/volcengine/VolcengineVideoTaskDao.xml

@@ -73,7 +73,7 @@
     <!-- 收藏任务映射 -->
     <resultMap id="resultMapTaskCollect" type="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTask" extends="baseTaskMap">
         <collection select="queryDetailCollectById" property="detail_list" javaType="java.util.List"
-                    ofType="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTaskDetail" column="{id=id, user_id=user_id}">
+                    ofType="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTaskDetail" column="{id=id, param_user_id=param_user_id}">
             <id property="id" column="id" />
             <result property="user_id" column="user_id" />
             <result property="task_id" column="task_id" />
@@ -137,7 +137,8 @@
             resultMap="resultMapTaskCollect">
         SELECT
                <include refid="includeVolcengineVideoTask" />
-               , 1 AS is_collect
+               , 1 AS is_collect,
+                #{dto.user_id} as param_user_id
         FROM ai_volcengine_video_task avvt
         INNER JOIN (
             SELECT
@@ -168,7 +169,7 @@
         INNER JOIN ai_volcengine_video_collect avc
             ON avc.task_id = avvtd.task_id
             AND avc.task_detail_id = avvtd.id
-            AND avc.user_id = #{user_id}
+            AND avc.user_id = #{param_user_id}
         WHERE avvtd.task_id = #{id}
         ORDER BY update_time DESC
     </select>