task-17: 拆分 delete-brand 模块 API 至 types/modules/delete-brand.ts,java-modules.ts re-export
- runDeleteBrand/getDeleteBrandHistory/deleteDeleteBrandHistory/getDeleteBrandTaskDetail/getDeleteBrandTaskDetails/getDeleteBrandTaskDownloadUrl/getDeleteBrandResultDownloadUrl/submitDeleteBrandResult/getDeleteBrandTaskProgress - delete-brand 全套类型(含 MatchStatus union)随模块迁移;progressBatch 内联缓存+超时实现 - 10 个测试:run URL/超时/history/delete/taskDetail/taskDetails/download×2/submitResult 请求体/progressBatch/export compat
This commit is contained in:
@@ -16,6 +16,7 @@ export * from "./types/modules/convert.ts";
|
||||
export * from "./types/modules/publish.ts";
|
||||
export * from "./types/modules/similar-asin.ts";
|
||||
export * from "./types/modules/appearance-patent.ts";
|
||||
export * from "./types/modules/delete-brand.ts";
|
||||
|
||||
const JAVA_API_PREFIX = "/newApi/api";
|
||||
|
||||
@@ -150,232 +151,6 @@ export async function uploadTempFileToJava(
|
||||
}
|
||||
|
||||
|
||||
export interface DeleteBrandPreviewRow {
|
||||
rowIndex: number;
|
||||
country: string;
|
||||
asin: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryAsinItem {
|
||||
rowIndex: number;
|
||||
asin: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryGroup {
|
||||
country: string;
|
||||
asinCount: number;
|
||||
items: DeleteBrandCountryAsinItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryResultItem {
|
||||
asin: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandProcessedCountry {
|
||||
country: string;
|
||||
items: DeleteBrandCountryResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandResultFile {
|
||||
fileKey?: string;
|
||||
sourceFilename: string;
|
||||
fileIndex?: number;
|
||||
fileTotal?: number;
|
||||
chunkIndex?: number;
|
||||
chunkTotal?: number;
|
||||
processedRows?: number;
|
||||
totalRows?: number;
|
||||
currentCountry?: string;
|
||||
currentAsin?: string;
|
||||
countries: DeleteBrandProcessedCountry[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandSubmitResultRequest {
|
||||
submissionId?: string;
|
||||
files: DeleteBrandResultFile[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandLineProgressInfo {
|
||||
file_index?: number;
|
||||
file_total?: number;
|
||||
file_name?: string;
|
||||
current_line?: number;
|
||||
total_lines?: number;
|
||||
current_country?: string;
|
||||
current_asin?: string;
|
||||
finished_files?: number;
|
||||
phase?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandLineProgress {
|
||||
has_progress: boolean;
|
||||
info?: DeleteBrandLineProgressInfo;
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskItem {
|
||||
id: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
sourceFileCount?: number;
|
||||
successFileCount?: number;
|
||||
failedFileCount?: number;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
downloadUrl?: string;
|
||||
downloadFilename?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskFileProgress {
|
||||
fileKey?: string;
|
||||
sourceFilename?: string;
|
||||
processedRows?: number;
|
||||
totalRows?: number;
|
||||
percent?: number;
|
||||
status?: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskDetailVo {
|
||||
task: DeleteBrandTaskItem;
|
||||
line_progress: DeleteBrandLineProgress;
|
||||
items?: DeleteBrandResultItem[];
|
||||
fileProgress?: DeleteBrandTaskFileProgress[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskBatchVo {
|
||||
items: DeleteBrandTaskDetailVo[];
|
||||
missingTaskIds: number[];
|
||||
}
|
||||
|
||||
export type DeleteBrandMatchStatus =
|
||||
| "MATCHED"
|
||||
| "PENDING"
|
||||
| "CONFLICT"
|
||||
| "INDEX_STALE";
|
||||
|
||||
export interface DeleteBrandResultItem {
|
||||
resultId?: number;
|
||||
fileKey?: string;
|
||||
sourceFilename: string;
|
||||
shopName?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: DeleteBrandMatchStatus;
|
||||
matchMessage?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
openStoreUrl?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
taskId?: number;
|
||||
countryCount?: number;
|
||||
countries?: DeleteBrandCountryGroup[];
|
||||
totalRows?: number;
|
||||
truncated?: boolean;
|
||||
previewRows?: DeleteBrandPreviewRow[];
|
||||
success: boolean;
|
||||
error?: string;
|
||||
taskStatus?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandRunVo {
|
||||
total: number;
|
||||
successCount: number;
|
||||
failedCount: number;
|
||||
items: DeleteBrandResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandHistoryVo {
|
||||
items: DeleteBrandResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandRunRequest {
|
||||
files: UploadedFileRef[];
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
export function runDeleteBrand(
|
||||
request: Omit<DeleteBrandRunRequest, "user_id"> | DeleteBrandRunRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<DeleteBrandRunVo>, DeleteBrandRunRequest>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/run`,
|
||||
{
|
||||
...request,
|
||||
user_id: getCurrentUserId(),
|
||||
},
|
||||
{ timeout: 180000 },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<DeleteBrandHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/history`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteDeleteBrandHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/history/${resultId}`,
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDetail(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<DeleteBrandTaskDetailVo>>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDetails(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<DeleteBrandTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDownloadUrl(taskId: number) {
|
||||
return getJavaDownloadUrl(`/delete-brand/tasks/${taskId}/download`);
|
||||
}
|
||||
|
||||
export function getDeleteBrandResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(`/delete-brand/results/${resultId}/download`);
|
||||
}
|
||||
|
||||
export function submitDeleteBrandResult(
|
||||
taskId: number,
|
||||
request: DeleteBrandSubmitResultRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, DeleteBrandSubmitResultRequest>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}/result`,
|
||||
request,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** 商品风险处理:备选店铺与匹配相关数据结构。 */
|
||||
export interface ProductRiskCandidateVo {
|
||||
id: number;
|
||||
@@ -1872,13 +1647,6 @@ export function getProductRiskTaskProgressBatch(taskIds: number[]) {
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskProgress(taskIds: number[]) {
|
||||
return postTaskProgressBatch<DeleteBrandTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackDashboardVo>>(
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
import { get, post, del, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { buildJavaUrl, JAVA_API_PREFIX } from '../../url.ts'
|
||||
import { getCurrentUserId } from '../../user.ts'
|
||||
import { getJavaDownloadUrl } from '../../download-url.ts'
|
||||
import { getTaskProgressCacheTtlMs, getTaskProgressTimeoutMs } from '../../../task-progress-config.ts'
|
||||
import { createTaskProgressRequestCache } from '../../../task-progress-request-cache.ts'
|
||||
import type { UploadedFileRef } from '../upload.ts'
|
||||
import { API_ENDPOINTS } from '../../endpoints.ts'
|
||||
|
||||
export interface DeleteBrandPreviewRow {
|
||||
rowIndex: number;
|
||||
country: string;
|
||||
asin: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryAsinItem {
|
||||
rowIndex: number;
|
||||
asin: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryGroup {
|
||||
country: string;
|
||||
asinCount: number;
|
||||
items: DeleteBrandCountryAsinItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandCountryResultItem {
|
||||
asin: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandProcessedCountry {
|
||||
country: string;
|
||||
items: DeleteBrandCountryResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandResultFile {
|
||||
fileKey?: string;
|
||||
sourceFilename: string;
|
||||
fileIndex?: number;
|
||||
fileTotal?: number;
|
||||
chunkIndex?: number;
|
||||
chunkTotal?: number;
|
||||
processedRows?: number;
|
||||
totalRows?: number;
|
||||
currentCountry?: string;
|
||||
currentAsin?: string;
|
||||
countries: DeleteBrandProcessedCountry[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandSubmitResultRequest {
|
||||
submissionId?: string;
|
||||
files: DeleteBrandResultFile[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandLineProgressInfo {
|
||||
file_index?: number;
|
||||
file_total?: number;
|
||||
file_name?: string;
|
||||
current_line?: number;
|
||||
total_lines?: number;
|
||||
current_country?: string;
|
||||
current_asin?: string;
|
||||
finished_files?: number;
|
||||
phase?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandLineProgress {
|
||||
has_progress: boolean;
|
||||
info?: DeleteBrandLineProgressInfo;
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskItem {
|
||||
id: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
sourceFileCount?: number;
|
||||
successFileCount?: number;
|
||||
failedFileCount?: number;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
downloadUrl?: string;
|
||||
downloadFilename?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskFileProgress {
|
||||
fileKey?: string;
|
||||
sourceFilename?: string;
|
||||
processedRows?: number;
|
||||
totalRows?: number;
|
||||
percent?: number;
|
||||
status?: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskDetailVo {
|
||||
task: DeleteBrandTaskItem;
|
||||
line_progress: DeleteBrandLineProgress;
|
||||
items?: DeleteBrandResultItem[];
|
||||
fileProgress?: DeleteBrandTaskFileProgress[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandTaskBatchVo {
|
||||
items: DeleteBrandTaskDetailVo[];
|
||||
missingTaskIds: number[];
|
||||
}
|
||||
|
||||
export type DeleteBrandMatchStatus =
|
||||
| "MATCHED"
|
||||
| "PENDING"
|
||||
| "CONFLICT"
|
||||
| "INDEX_STALE";
|
||||
|
||||
export interface DeleteBrandResultItem {
|
||||
resultId?: number;
|
||||
fileKey?: string;
|
||||
sourceFilename: string;
|
||||
shopName?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: DeleteBrandMatchStatus;
|
||||
matchMessage?: string;
|
||||
shopId?: string;
|
||||
platform?: string;
|
||||
openStoreUrl?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
taskId?: number;
|
||||
countryCount?: number;
|
||||
countries?: DeleteBrandCountryGroup[];
|
||||
totalRows?: number;
|
||||
truncated?: boolean;
|
||||
previewRows?: DeleteBrandPreviewRow[];
|
||||
success: boolean;
|
||||
error?: string;
|
||||
taskStatus?: string;
|
||||
}
|
||||
|
||||
export interface DeleteBrandRunVo {
|
||||
total: number;
|
||||
successCount: number;
|
||||
failedCount: number;
|
||||
items: DeleteBrandResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandHistoryVo {
|
||||
items: DeleteBrandResultItem[];
|
||||
}
|
||||
|
||||
export interface DeleteBrandRunRequest {
|
||||
files: UploadedFileRef[];
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
interface TaskProgressBatchOptions {
|
||||
force?: boolean;
|
||||
}
|
||||
|
||||
const taskProgressResponseCache = createTaskProgressRequestCache<unknown>({
|
||||
ttlMs: () => getTaskProgressCacheTtlMs(),
|
||||
maxEntries: 100,
|
||||
maxInflight: 16,
|
||||
});
|
||||
|
||||
function normalizeTaskIds(taskIds: number[]) {
|
||||
return Array.from(
|
||||
new Set(
|
||||
(taskIds || [])
|
||||
.map((taskId) => Number(taskId))
|
||||
.filter((taskId) => Number.isFinite(taskId) && taskId > 0),
|
||||
),
|
||||
).sort((left, right) => left - right);
|
||||
}
|
||||
|
||||
function buildTaskProgressRequestKey(path: string, taskIds: number[]) {
|
||||
return `${path}::${taskIds.join(",")}`;
|
||||
}
|
||||
|
||||
async function postTaskProgressBatch<T>(
|
||||
path: string,
|
||||
taskIds: number[],
|
||||
options: TaskProgressBatchOptions = {},
|
||||
) {
|
||||
const normalizedTaskIds = normalizeTaskIds(taskIds);
|
||||
if (!normalizedTaskIds.length) {
|
||||
return { items: [], missingTaskIds: [] } as T;
|
||||
}
|
||||
|
||||
const cacheKey = buildTaskProgressRequestKey(path, normalizedTaskIds);
|
||||
const cached = taskProgressResponseCache.get(cacheKey);
|
||||
if (!options.force && cached !== undefined) {
|
||||
return cached as T;
|
||||
}
|
||||
|
||||
const inflight = taskProgressResponseCache.getInflight(cacheKey);
|
||||
if (!options.force && inflight) {
|
||||
return (await inflight) as T;
|
||||
}
|
||||
|
||||
const requestPromise = unwrapJavaResponse(
|
||||
post<JavaApiResponse<T>, { taskIds: number[] }>(path, { taskIds: normalizedTaskIds }, {
|
||||
timeout: getTaskProgressTimeoutMs(),
|
||||
}),
|
||||
)
|
||||
.then((data) => {
|
||||
taskProgressResponseCache.set(cacheKey, data);
|
||||
return data;
|
||||
})
|
||||
.finally(() => {
|
||||
taskProgressResponseCache.endInflight(cacheKey);
|
||||
});
|
||||
|
||||
taskProgressResponseCache.startInflight(cacheKey, requestPromise);
|
||||
return requestPromise;
|
||||
}
|
||||
|
||||
export function runDeleteBrand(
|
||||
request: Omit<DeleteBrandRunRequest, "user_id"> | DeleteBrandRunRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<DeleteBrandRunVo>, DeleteBrandRunRequest>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.run),
|
||||
{
|
||||
...request,
|
||||
user_id: getCurrentUserId(),
|
||||
},
|
||||
{ timeout: 180000 },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<DeleteBrandHistoryVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.history),
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteDeleteBrandHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.historyDelete.replace('{resultId}', String(resultId))),
|
||||
{
|
||||
params: { user_id: getCurrentUserId() },
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDetail(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<DeleteBrandTaskDetailVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.taskDetail.replace('{taskId}', String(taskId))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDetails(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<DeleteBrandTaskBatchVo>, { taskIds: number[] }>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.taskDetails),
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskDownloadUrl(taskId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
API_ENDPOINTS.deleteBrand.taskDownload.replace('{taskId}', String(taskId)),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
API_ENDPOINTS.deleteBrand.resultDownload.replace('{resultId}', String(resultId)),
|
||||
);
|
||||
}
|
||||
|
||||
export function submitDeleteBrandResult(
|
||||
taskId: number,
|
||||
request: DeleteBrandSubmitResultRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, DeleteBrandSubmitResultRequest>(
|
||||
buildJavaUrl(API_ENDPOINTS.deleteBrand.resultSubmit.replace('{taskId}', String(taskId))),
|
||||
request,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeleteBrandTaskProgress(taskIds: number[]) {
|
||||
return postTaskProgressBatch<DeleteBrandTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/delete-brand/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user