wangyunpeng 1 неделя назад
Родитель
Сommit
8f24f88606

+ 47 - 21
core/src/main/java/com/tzld/videoVector/service/impl/VideoSearchServiceImpl.java

@@ -83,6 +83,7 @@ public class VideoSearchServiceImpl implements VideoSearchService {
 
         // 检查是否存在重复的 channelContentId
         String channelContentId = param.getChannelContentId();
+        DeconstructContent failedContent = null;
         if (StringUtils.hasText(channelContentId)) {
             DeconstructContent existingContent = getDeconstructContentByChannelContentId(channelContentId);
             if (existingContent != null) {
@@ -94,9 +95,10 @@ public class VideoSearchServiceImpl implements VideoSearchService {
                             channelContentId, existingContent.getTaskId(), getStatusDesc(status));
                     return existingContent.getTaskId();
                 }
-                // 状态为 FAILED 时,允许重新提交
+                // 状态为 FAILED 时,记录该记录,重新提交后更新而非新增
                 log.info("解构任务已存在但失败,channelContentId={}, taskId={}, status={}, 允许重新提交",
                         channelContentId, existingContent.getTaskId(), getStatusDesc(status));
+                failedContent = existingContent;
             }
         }
 
@@ -126,27 +128,51 @@ public class VideoSearchServiceImpl implements VideoSearchService {
 
         // 保存任务到数据库
         try {
-            DeconstructContent content = new DeconstructContent();
-            content.setTaskId(taskId);
-            content.setBizType(bizType.byteValue());
-            content.setContentType(contentType.byteValue());
-            content.setChannelContentId(param.getChannelContentId());
-            content.setTitle(param.getTitle());
-            content.setBodyText(param.getBodyText());
-            content.setVideoUrl(param.getVideoUrl());
-            content.setChannelAccountId(param.getChannelAccountId());
-            content.setChannelAccountName(param.getChannelAccountName());
-            content.setStatus((byte) 0); // PENDING
-            content.setCreateTime(new Date());
-            content.setUpdateTime(new Date());
-
-            // 处理图片列表
-            if (param.getImageList() != null && !param.getImageList().isEmpty()) {
-                content.setImages(JSONObject.toJSONString(param.getImageList()));
+            if (failedContent != null) {
+                // 历史存在失败记录,更新该记录,不新增
+                failedContent.setTaskId(taskId);
+                failedContent.setBizType(bizType.byteValue());
+                failedContent.setContentType(contentType.byteValue());
+                failedContent.setTitle(param.getTitle());
+                failedContent.setBodyText(param.getBodyText());
+                failedContent.setVideoUrl(param.getVideoUrl());
+                failedContent.setChannelAccountId(param.getChannelAccountId());
+                failedContent.setChannelAccountName(param.getChannelAccountName());
+                failedContent.setStatus((byte) 0); // PENDING
+                // 清除历史失败信息(使用空字符串确保 selective update 生效)
+                failedContent.setResultJson("");
+                failedContent.setFailureReason("");
+                failedContent.setPointUrl("");
+                failedContent.setWeightUrl("");
+                failedContent.setPatternUrl("");
+                failedContent.setUpdateTime(new Date());
+                // 处理图片列表
+                if (param.getImageList() != null && !param.getImageList().isEmpty()) {
+                    failedContent.setImages(JSONObject.toJSONString(param.getImageList()));
+                }
+                deconstructContentMapper.updateByPrimaryKeySelective(failedContent);
+                log.info("解构失败记录已更新,contentId={}, taskId={}", failedContent.getId(), taskId);
+            } else {
+                DeconstructContent content = new DeconstructContent();
+                content.setTaskId(taskId);
+                content.setBizType(bizType.byteValue());
+                content.setContentType(contentType.byteValue());
+                content.setChannelContentId(param.getChannelContentId());
+                content.setTitle(param.getTitle());
+                content.setBodyText(param.getBodyText());
+                content.setVideoUrl(param.getVideoUrl());
+                content.setChannelAccountId(param.getChannelAccountId());
+                content.setChannelAccountName(param.getChannelAccountName());
+                content.setStatus((byte) 0); // PENDING
+                content.setCreateTime(new Date());
+                content.setUpdateTime(new Date());
+                // 处理图片列表
+                if (param.getImageList() != null && !param.getImageList().isEmpty()) {
+                    content.setImages(JSONObject.toJSONString(param.getImageList()));
+                }
+                deconstructContentMapper.insertSelective(content);
+                log.info("解构任务已保存到数据库,contentId={}, taskId={}", content.getId(), taskId);
             }
-
-            deconstructContentMapper.insertSelective(content);
-            log.info("解构任务已保存到数据库,contentId={}, taskId={}", content.getId(), taskId);
         } catch (Exception e) {
             log.error("保存解构任务失败,taskId={}, error={}", taskId, e.getMessage(), e);
         }