task-18: 拆分 price-track 模块 API 至 types/modules/price-track.ts,java-modules.ts re-export
- candidates/preference/matchShops/createTask/tasksBatch/progressBatch/loopRun 系列/skipAsin 系列/dispatchFailed/pendingShopResult/dashboard/history/delete/download 共 23 函数 - price-track 全套类型(含 LoopRun/ExecutionMode/SkipPriceAsin 类型)随模块迁移 - 12 个测试:CRUD/preference/match/create/batch/loopRun/progressBatch/skipAsin 系列/dashboard/download/unwrap/export compat
This commit is contained in:
@@ -17,6 +17,7 @@ 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";
|
||||
export * from "./types/modules/price-track.ts";
|
||||
|
||||
const JAVA_API_PREFIX = "/newApi/api";
|
||||
|
||||
@@ -1444,195 +1445,6 @@ export function deleteWithdrawHistory(resultId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 跟价 ==========
|
||||
|
||||
export interface PriceTrackCandidateVo {
|
||||
id: number;
|
||||
shopName: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackShopQueueItem {
|
||||
shopName?: string;
|
||||
shopMallName?: string;
|
||||
shopId?: number | string | null;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
skipAsins?: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export interface PriceTrackMatchShopsVo {
|
||||
items: PriceTrackShopQueueItem[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
|
||||
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface PriceTrackCountryPreferenceVo {
|
||||
userId: number;
|
||||
countryCodes: string[];
|
||||
}
|
||||
|
||||
export interface PriceTrackDashboardVo {
|
||||
candidateCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface PriceTrackHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
shopName?: string;
|
||||
shopMallName?: string;
|
||||
shopId?: number | string | null;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
error?: string;
|
||||
success?: boolean;
|
||||
}
|
||||
|
||||
export interface PriceTrackHistoryVo {
|
||||
items: PriceTrackHistoryItem[];
|
||||
}
|
||||
|
||||
export interface PriceTrackAsinParsedRow {
|
||||
shopMallName?: string;
|
||||
asin?: string;
|
||||
price?: string;
|
||||
recommendedPrice?: string;
|
||||
shippingFee?: string;
|
||||
minimumPrice?: string;
|
||||
firstPlace?: string;
|
||||
firstShop?: string;
|
||||
secondPlace?: string;
|
||||
secondShop?: string;
|
||||
cartShopName?: string;
|
||||
priceChangeStatus?: string;
|
||||
modifyCount?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackCreateTaskVo {
|
||||
taskId: number;
|
||||
items: PriceTrackHistoryItem[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
|
||||
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskDetailVo {
|
||||
task?: PriceTrackTaskSummary;
|
||||
items?: PriceTrackHistoryItem[];
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskBatchVo {
|
||||
items: PriceTrackTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
export interface PriceTrackPendingDeleteVo {
|
||||
removed: boolean;
|
||||
}
|
||||
|
||||
export type PriceTrackCreateTaskPayload = Omit<
|
||||
PriceTrackCreateTaskRequest,
|
||||
"userId"
|
||||
>;
|
||||
|
||||
export function listPriceTrackCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addPriceTrackCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackCandidateVo>, { userId: number; shopName: string }>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates`,
|
||||
{ userId: getCurrentUserId(), shopName },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates/${id}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/country-preference?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putPriceTrackCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<JavaApiResponse<PriceTrackCountryPreferenceVo>, { userId: number; countryCodes: string[] }>(
|
||||
`${JAVA_API_PREFIX}/price-track/country-preference`,
|
||||
{ userId: getCurrentUserId(), countryCodes },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchPriceTrackShops(
|
||||
shopNames: string[],
|
||||
options?: {
|
||||
asinFiles?: string[];
|
||||
countryCodes?: string[];
|
||||
},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<PriceTrackMatchShopsVo>,
|
||||
{ userId: number; shopNames: string[]; asinFiles?: string[]; countryCodes?: string[] }
|
||||
>(
|
||||
`${JAVA_API_PREFIX}/price-track/match-shops`,
|
||||
{
|
||||
userId: getCurrentUserId(),
|
||||
shopNames,
|
||||
asinFiles: options?.asinFiles || [],
|
||||
countryCodes: options?.countryCodes || [],
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getShopMatchTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<ShopMatchTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/shop-match/tasks/progress/batch`,
|
||||
@@ -1647,231 +1459,6 @@ export function getProductRiskTaskProgressBatch(taskIds: number[]) {
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/dashboard?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/history?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/history/${resultId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export interface PriceTrackCreateTaskRequest {
|
||||
userId: number;
|
||||
statusMode: boolean;
|
||||
asinMode: boolean;
|
||||
items: PriceTrackShopQueueItem[];
|
||||
asinFiles: string[];
|
||||
countryCodes: string[];
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
shopIndex?: number;
|
||||
}
|
||||
|
||||
export type PriceTrackExecutionMode = "FINITE" | "INFINITE";
|
||||
|
||||
export interface PriceTrackLoopRunCreateRequest {
|
||||
userId: number;
|
||||
statusMode: boolean;
|
||||
asinMode: boolean;
|
||||
items: PriceTrackShopQueueItem[];
|
||||
asinFiles: string[];
|
||||
countryCodes: string[];
|
||||
executionMode: PriceTrackExecutionMode;
|
||||
targetRounds?: number;
|
||||
}
|
||||
|
||||
export interface PriceTrackLoopRunVo {
|
||||
id: number;
|
||||
status?: string;
|
||||
executionMode?: PriceTrackExecutionMode;
|
||||
targetRounds?: number;
|
||||
currentRound?: number;
|
||||
currentShopIndex?: number;
|
||||
totalShopCount?: number;
|
||||
activeTaskId?: number;
|
||||
activeTaskStatus?: string;
|
||||
stopRequested?: boolean;
|
||||
errorMessage?: string;
|
||||
statusMode?: boolean;
|
||||
asinMode?: boolean;
|
||||
asinFiles?: string[];
|
||||
countryCodes?: string[];
|
||||
}
|
||||
|
||||
export interface PriceTrackLoopRunDispatchVo {
|
||||
loopRun?: PriceTrackLoopRunVo;
|
||||
childTaskRequest?: PriceTrackCreateTaskRequest;
|
||||
}
|
||||
|
||||
export function createPriceTrackTask(
|
||||
request: PriceTrackCreateTaskPayload | PriceTrackCreateTaskRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackCreateTaskVo>, PriceTrackCreateTaskRequest>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks`,
|
||||
{ ...request, userId: getCurrentUserId() },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function createPriceTrackLoopRun(
|
||||
request: Omit<PriceTrackLoopRunCreateRequest, "userId"> | PriceTrackLoopRunCreateRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, PriceTrackLoopRunCreateRequest>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs`,
|
||||
{ ...request, userId: getCurrentUserId() },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackLoopRunVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function dispatchNextPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunDispatchVo>, undefined>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/dispatch-next?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function completePriceTrackLoopChild(loopRunId: number, childTaskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, { childTaskId: number }>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/child-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ childTaskId },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function stopPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, undefined>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/stop?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<PriceTrackTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(`/price-track/results/${resultId}/download`);
|
||||
}
|
||||
|
||||
export function getTaskSkipPriceAsinsPaginated(
|
||||
taskId: number,
|
||||
page: number = 1,
|
||||
pageSize: number = 1000,
|
||||
options: {
|
||||
shopName?: string | string[];
|
||||
countryCode?: string | string[];
|
||||
} = {},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<SkipPriceAsinPageVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asins/paginated`,
|
||||
{
|
||||
params: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
...(options.shopName ? { shop_name: options.shopName } : {}),
|
||||
...(options.countryCode ? { country_code: options.countryCode } : {}),
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function markPriceTrackDispatchFailed(taskId: number, errorMessage: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, { errorMessage: string }>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/dispatch-failed?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ errorMessage },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function checkTaskSkipPriceAsin(taskId: number, country: string, asin: string) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<SkipPriceAsinCheckVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asin/check`,
|
||||
{
|
||||
params: {
|
||||
country,
|
||||
asin,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export interface SkipPriceAsinCheckVo {
|
||||
country: string;
|
||||
asin: string;
|
||||
exists: boolean;
|
||||
minimumPrice?: string;
|
||||
}
|
||||
|
||||
export interface SkipPriceAsinPageVo {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
skipAsinsByCountry: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asins?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asin_rows_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
minimum_price_by_country_and_asin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface ShopMatchSkipAsinPageVo {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
@@ -1882,14 +1469,6 @@ export interface ShopMatchSkipAsinPageVo {
|
||||
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
}
|
||||
|
||||
export function deletePendingPriceTrackShopResult(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<PriceTrackPendingDeleteVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/pending-shop-result?user_id=${encodeURIComponent(String(getCurrentUserId()))}&shop_name=${encodeURIComponent(shopName)}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 视频复刻 / 图生视频 ==========
|
||||
|
||||
export interface ImageVideoDouyinCopyVo {
|
||||
|
||||
@@ -0,0 +1,486 @@
|
||||
import { get, post, put, 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 { API_ENDPOINTS } from '../../endpoints.ts'
|
||||
|
||||
export interface PriceTrackCandidateVo {
|
||||
id: number;
|
||||
shopName: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackShopQueueItem {
|
||||
shopName?: string;
|
||||
shopMallName?: string;
|
||||
shopId?: number | string | null;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
skipAsins?: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export interface PriceTrackMatchShopsVo {
|
||||
items: PriceTrackShopQueueItem[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
|
||||
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface PriceTrackCountryPreferenceVo {
|
||||
userId: number;
|
||||
countryCodes: string[];
|
||||
}
|
||||
|
||||
export interface PriceTrackDashboardVo {
|
||||
candidateCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface PriceTrackHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
shopName?: string;
|
||||
shopMallName?: string;
|
||||
shopId?: number | string | null;
|
||||
platform?: string;
|
||||
companyName?: string;
|
||||
matched?: boolean;
|
||||
matchStatus?: string;
|
||||
matchMessage?: string;
|
||||
taskStatus?: string;
|
||||
outputFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
error?: string;
|
||||
success?: boolean;
|
||||
}
|
||||
|
||||
export interface PriceTrackHistoryVo {
|
||||
items: PriceTrackHistoryItem[];
|
||||
}
|
||||
|
||||
export interface PriceTrackAsinParsedRow {
|
||||
shopMallName?: string;
|
||||
asin?: string;
|
||||
price?: string;
|
||||
recommendedPrice?: string;
|
||||
shippingFee?: string;
|
||||
minimumPrice?: string;
|
||||
firstPlace?: string;
|
||||
firstShop?: string;
|
||||
secondPlace?: string;
|
||||
secondShop?: string;
|
||||
cartShopName?: string;
|
||||
priceChangeStatus?: string;
|
||||
modifyCount?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackCreateTaskVo {
|
||||
taskId: number;
|
||||
items: PriceTrackHistoryItem[];
|
||||
skipAsinsByCountry?: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
|
||||
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskDetailVo {
|
||||
task?: PriceTrackTaskSummary;
|
||||
items?: PriceTrackHistoryItem[];
|
||||
}
|
||||
|
||||
export interface PriceTrackTaskBatchVo {
|
||||
items: PriceTrackTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
export interface PriceTrackPendingDeleteVo {
|
||||
removed: boolean;
|
||||
}
|
||||
|
||||
export type PriceTrackCreateTaskPayload = Omit<
|
||||
PriceTrackCreateTaskRequest,
|
||||
"userId"
|
||||
>;
|
||||
|
||||
export interface PriceTrackCreateTaskRequest {
|
||||
userId: number;
|
||||
statusMode: boolean;
|
||||
asinMode: boolean;
|
||||
items: PriceTrackShopQueueItem[];
|
||||
asinFiles: string[];
|
||||
countryCodes: string[];
|
||||
loopRunId?: number;
|
||||
roundIndex?: number;
|
||||
shopIndex?: number;
|
||||
}
|
||||
|
||||
export type PriceTrackExecutionMode = "FINITE" | "INFINITE";
|
||||
|
||||
export interface PriceTrackLoopRunCreateRequest {
|
||||
userId: number;
|
||||
statusMode: boolean;
|
||||
asinMode: boolean;
|
||||
items: PriceTrackShopQueueItem[];
|
||||
asinFiles: string[];
|
||||
countryCodes: string[];
|
||||
executionMode: PriceTrackExecutionMode;
|
||||
targetRounds?: number;
|
||||
}
|
||||
|
||||
export interface PriceTrackLoopRunVo {
|
||||
id: number;
|
||||
status?: string;
|
||||
executionMode?: PriceTrackExecutionMode;
|
||||
targetRounds?: number;
|
||||
currentRound?: number;
|
||||
currentShopIndex?: number;
|
||||
totalShopCount?: number;
|
||||
activeTaskId?: number;
|
||||
activeTaskStatus?: string;
|
||||
stopRequested?: boolean;
|
||||
errorMessage?: string;
|
||||
statusMode?: boolean;
|
||||
asinMode?: boolean;
|
||||
asinFiles?: string[];
|
||||
countryCodes?: string[];
|
||||
}
|
||||
|
||||
export interface PriceTrackLoopRunDispatchVo {
|
||||
loopRun?: PriceTrackLoopRunVo;
|
||||
childTaskRequest?: PriceTrackCreateTaskRequest;
|
||||
}
|
||||
|
||||
export interface SkipPriceAsinCheckVo {
|
||||
country: string;
|
||||
asin: string;
|
||||
exists: boolean;
|
||||
minimumPrice?: string;
|
||||
}
|
||||
|
||||
export interface SkipPriceAsinPageVo {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
skipAsinsByCountry: Record<string, string[]>;
|
||||
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
skip_asins?: Record<string, string[]>;
|
||||
skip_asins_by_country?: Record<string, string[]>;
|
||||
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
asin_rows_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
|
||||
minimum_price_by_country_and_asin?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
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[],
|
||||
) {
|
||||
const normalizedTaskIds = normalizeTaskIds(taskIds);
|
||||
if (!normalizedTaskIds.length) {
|
||||
return { items: [], missingTaskIds: [] } as T;
|
||||
}
|
||||
|
||||
const cacheKey = buildTaskProgressRequestKey(path, normalizedTaskIds);
|
||||
const cached = taskProgressResponseCache.get(cacheKey);
|
||||
if (cached !== undefined) {
|
||||
return cached as T;
|
||||
}
|
||||
|
||||
const inflight = taskProgressResponseCache.getInflight(cacheKey);
|
||||
if (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 listPriceTrackCandidates() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackCandidateVo[]>>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function addPriceTrackCandidate(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackCandidateVo>, { userId: number; shopName: string }>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates`,
|
||||
{ userId: getCurrentUserId(), shopName },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackCandidate(id: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/candidates/${id}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackCountryPreference() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackCountryPreferenceVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/country-preference?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function putPriceTrackCountryPreference(countryCodes: string[]) {
|
||||
return unwrapJavaResponse(
|
||||
put<JavaApiResponse<PriceTrackCountryPreferenceVo>, { userId: number; countryCodes: string[] }>(
|
||||
`${JAVA_API_PREFIX}/price-track/country-preference`,
|
||||
{ userId: getCurrentUserId(), countryCodes },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function matchPriceTrackShops(
|
||||
shopNames: string[],
|
||||
options?: {
|
||||
asinFiles?: string[];
|
||||
countryCodes?: string[];
|
||||
},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<PriceTrackMatchShopsVo>,
|
||||
{ userId: number; shopNames: string[]; asinFiles?: string[]; countryCodes?: string[] }
|
||||
>(
|
||||
`${JAVA_API_PREFIX}/price-track/match-shops`,
|
||||
{
|
||||
userId: getCurrentUserId(),
|
||||
shopNames,
|
||||
asinFiles: options?.asinFiles || [],
|
||||
countryCodes: options?.countryCodes || [],
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function createPriceTrackTask(
|
||||
request: PriceTrackCreateTaskPayload | PriceTrackCreateTaskRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackCreateTaskVo>, PriceTrackCreateTaskRequest>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks`,
|
||||
{ ...request, userId: getCurrentUserId() },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackTasksBatch(taskIds: number[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackTaskBatchVo>, { taskIds: number[] }>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/batch`,
|
||||
{ taskIds },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function createPriceTrackLoopRun(
|
||||
request: Omit<PriceTrackLoopRunCreateRequest, "userId"> | PriceTrackLoopRunCreateRequest,
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, PriceTrackLoopRunCreateRequest>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs`,
|
||||
{ ...request, userId: getCurrentUserId() },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackLoopRunVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function dispatchNextPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunDispatchVo>, undefined>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/dispatch-next?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function completePriceTrackLoopChild(loopRunId: number, childTaskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, { childTaskId: number }>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/child-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ childTaskId },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function stopPriceTrackLoopRun(loopRunId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<PriceTrackLoopRunVo>, undefined>(
|
||||
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/stop?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackTaskProgressBatch(taskIds: number[]) {
|
||||
return postTaskProgressBatch<PriceTrackTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/progress/batch`,
|
||||
taskIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
API_ENDPOINTS.priceTrack.resultDownload.replace('{resultId}', String(resultId)),
|
||||
);
|
||||
}
|
||||
|
||||
export function getTaskSkipPriceAsinsPaginated(
|
||||
taskId: number,
|
||||
page: number = 1,
|
||||
pageSize: number = 1000,
|
||||
options: {
|
||||
shopName?: string | string[];
|
||||
countryCode?: string | string[];
|
||||
} = {},
|
||||
) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<SkipPriceAsinPageVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asins/paginated`,
|
||||
{
|
||||
params: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
...(options.shopName ? { shop_name: options.shopName } : {}),
|
||||
...(options.countryCode ? { country_code: options.countryCode } : {}),
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function markPriceTrackDispatchFailed(taskId: number, errorMessage: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, { errorMessage: string }>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/dispatch-failed?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ errorMessage },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function checkTaskSkipPriceAsin(taskId: number, country: string, asin: string) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<SkipPriceAsinCheckVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asin/check`,
|
||||
{
|
||||
params: {
|
||||
country,
|
||||
asin,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePendingPriceTrackShopResult(shopName: string) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<PriceTrackPendingDeleteVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/pending-shop-result?user_id=${encodeURIComponent(String(getCurrentUserId()))}&shop_name=${encodeURIComponent(shopName)}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/dashboard?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPriceTrackHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<PriceTrackHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/price-track/history?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePriceTrackHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/price-track/history/${resultId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user