feat(task-retry): 重试按钮推广到相似ASIN与采集数据
同类问题一起修:这两个模块与外观专利共用同一条自动重试(原先也克隆重试)。
- 新增通用端点 POST /api/tasks/{taskId}/retry(模块无关,从任务行取 moduleType)
- 两页失败任务在「删除」前显示「重试」,调用后在原任务上复位续跑
- catch 棘轮 308→310,两处均 ElMessage 可见出口
This commit is contained in:
+47
@@ -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);
|
||||
}
|
||||
}
|
||||
+14
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户点「重试」的入口:校验归属与状态后原地复位。
|
||||
*
|
||||
|
||||
@@ -120,11 +120,15 @@
|
||||
history-empty-text="暂无历史记录"
|
||||
>
|
||||
<template #item-actions="{ item }">
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">重试</button>
|
||||
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
<template #history-item-actions="{ item }">
|
||||
<button v-if="canDownload(itemSource(item))" type="button" class="download"
|
||||
@click="downloadResult(itemSource(item))">下载</button>
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">重试</button>
|
||||
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
|
||||
@click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
@@ -139,6 +143,7 @@
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, shallowRef, triggerRef } from 'vue'
|
||||
import { userNotice } from '@/shared/utils/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { retryClientTask } from '@/shared/api/task-retry'
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
|
||||
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
|
||||
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
|
||||
@@ -491,6 +496,26 @@ async function pushToPythonQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
|
||||
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
|
||||
*/
|
||||
function canRetryTask(item: CollectDataHistoryItem | null | undefined): boolean {
|
||||
return Boolean(item?.taskId) && normalizeTaskStatus(item as CollectDataHistoryItem) === 'FAILED'
|
||||
}
|
||||
|
||||
async function retryTaskRecord(item: CollectDataHistoryItem | null | undefined) {
|
||||
const taskId = item?.taskId
|
||||
if (!taskId) return
|
||||
try {
|
||||
await retryClientTask(taskId)
|
||||
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
|
||||
await refreshBoard()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '重试失败')
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTaskStatus(item: CollectDataHistoryItem) {
|
||||
return (item.taskStatus || '').toUpperCase()
|
||||
}
|
||||
|
||||
@@ -109,11 +109,15 @@
|
||||
<div v-if="pendingResultHint(itemSource(item))" class="files result-hint">{{ pendingResultHint(itemSource(item)) }}</div>
|
||||
</template>
|
||||
<template #item-actions="{ item }">
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">重试</button>
|
||||
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
<template #history-item-actions="{ item }">
|
||||
<button v-if="canDownload(itemSource(item))" type="button" class="download"
|
||||
@click="downloadResult(itemSource(item))">下载</button>
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">重试</button>
|
||||
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
|
||||
@click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
@@ -129,6 +133,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { userNotice } from '@/shared/utils/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { retryClientTask } from '@/shared/api/task-retry'
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
|
||||
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
|
||||
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
|
||||
@@ -369,6 +374,26 @@ function isResultPreparing(item: SimilarAsinHistoryItem) {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
|
||||
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
|
||||
*/
|
||||
function canRetryTask(item: SimilarAsinHistoryItem | null | undefined): boolean {
|
||||
return Boolean(item?.taskId) && normalizeTaskStatus(item as SimilarAsinHistoryItem) === 'FAILED'
|
||||
}
|
||||
|
||||
async function retryTaskRecord(item: SimilarAsinHistoryItem | null | undefined) {
|
||||
const taskId = item?.taskId
|
||||
if (!taskId) return
|
||||
try {
|
||||
await retryClientTask(taskId)
|
||||
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
|
||||
await refreshBoard()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '重试失败')
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTaskStatus(item: SimilarAsinHistoryItem) {
|
||||
const taskStatus = (item.taskStatus || '').toUpperCase()
|
||||
if (taskStatus !== 'FAILED' && isResultFileComplete(item)) return 'SUCCESS'
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { post, type JavaApiResponse, unwrapJavaResponse } from './http.ts'
|
||||
import { JAVA_API_PREFIX } from './url.ts'
|
||||
import { getCurrentUserId } from './user.ts'
|
||||
|
||||
/**
|
||||
* 失败任务重试(模块无关,2026-11-01 用户拍板)。
|
||||
*
|
||||
* 口径:失败任务**不再自动克隆**(同一份输入会多出好几行结果),改由用户在「删除」旁点
|
||||
* 「重试」——服务端在原任务上复位(FAILED→PENDING),保留已收分片、解析载荷与已检测标记,
|
||||
* 也就是断点续传。外观专利/相似ASIN/采集数据三个模块共用这一条出口。
|
||||
*/
|
||||
export function retryClientTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/tasks/${taskId}/retry`, undefined, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -51,7 +51,10 @@ const BASELINE = {
|
||||
// 删除旁的重试按钮在原任务上续跑)。BrandAppearancePatentTab.vue 的 retryTaskRecord 包住
|
||||
// 重试请求:失败 ElMessage.error 当场报给用户、成功 ElMessage.success 并刷新看板——不是吞错,
|
||||
// silent 一格没涨,只进 blocks。
|
||||
blocks: 308,
|
||||
// 310 = 308 + 2(2026-11-01 失败任务重试按钮推广到同类模块):相似ASIN 与采集数据的
|
||||
// retryTaskRecord 各一支 try/catch,失败 ElMessage.error 当场报给用户、成功 ElMessage.success
|
||||
// 并刷新看板——与外观专利同口径,不是吞错;silent 一格没涨,只进 blocks。
|
||||
blocks: 310,
|
||||
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
|
||||
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
|
||||
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
|
||||
|
||||
Reference in New Issue
Block a user