feat(task-retry): 重试按钮推广到相似ASIN与采集数据

同类问题一起修:这两个模块与外观专利共用同一条自动重试(原先也克隆重试)。
- 新增通用端点 POST /api/tasks/{taskId}/retry(模块无关,从任务行取 moduleType)
- 两页失败任务在「删除」前显示「重试」,调用后在原任务上复位续跑
- catch 棘轮 308→310,两处均 ElMessage 可见出口
This commit is contained in:
2026-11-01 00:46:08 +08:00
parent 0a467793ac
commit 96b090dfd5
6 changed files with 133 additions and 1 deletions
@@ -0,0 +1,47 @@
package com.nanri.aiimage.modules.task.controller;
import com.nanri.aiimage.common.api.ApiResponse;
import com.nanri.aiimage.common.security.AdminAuthSupport;
import com.nanri.aiimage.modules.task.service.TaskInPlaceRetryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 失败任务重试(模块无关,2026-11-01 用户拍板)。
*
* <p>口径:失败任务不再自动克隆新任务(同一份输入会多出好几行结果),改由用户在
* 「删除」旁点「重试」——在原任务上复位续跑,保留已收分片、解析载荷与已检测标记。
* 外观专利另有模块专属端点 {@code /api/appearance-patent/tasks/{id}/retry},行为一致。
*/
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/tasks")
@Tag(name = "任务重试", description = "失败任务在原任务上复位重试(外观专利/相似ASIN/采集数据共用)。")
public class TaskRetryController {
private final TaskInPlaceRetryService taskRetryService;
private final AdminAuthSupport adminAuthSupport;
@PostMapping("/{taskId}/retry")
@Operation(summary = "重试失败任务",
description = "在原任务上复位(FAILED→PENDING),保留分片/解析载荷/已检测标记,不创建新任务。")
public ApiResponse<Void> retry(
@Parameter(description = "任务 ID。", required = true) @PathVariable Long taskId,
@Parameter(description = "当前用户 ID,必须与任务归属一致。", required = true)
@RequestParam("user_id") Long userId,
HttpServletRequest httpRequest) {
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
taskRetryService.retryFailedTask(taskId, userId);
return ApiResponse.success(null);
}
}
@@ -71,6 +71,20 @@ public class TaskInPlaceRetryService {
return true;
}
/**
* 通用入口(模块无关):从任务行自身取 moduleType。
*
* <p>外观专利/相似ASIN/采集数据三个模块的失败任务走同一条路——它们原先都会被
* {@code TaskResumeService} 克隆重试,同一份输入在界面上多出好几行。
*/
public void retryFailedTask(Long taskId, Long userId) {
FileTaskEntity task = fileTaskMapper.selectById(taskId);
if (task == null || !java.util.Objects.equals(userId, task.getUserId())) {
throw new com.nanri.aiimage.common.exception.BusinessException("任务不存在");
}
retryFailedTask(taskId, userId, task.getModuleType());
}
/**
* 用户点「重试」的入口:校验归属与状态后原地复位。
*