import { del, get, http, post, put, type JavaApiResponse, unwrapJavaResponse, } from "@/shared/api/http"; const JAVA_API_PREFIX = "/newApi/api"; function getCurrentUserId() { const raw = typeof window === "undefined" ? "" : window.localStorage.getItem("uid") || ""; const value = Number(raw); if (!Number.isFinite(value) || value <= 0) { throw new Error("未获取到用户ID"); } return value; } export interface UploadedFileRef { fileKey: string; originalFilename?: string; relativePath?: string; } export interface UploadFileVo { fileKey: string; originalFilename: string; localPath: string; size: number; relativePath?: string; } export interface DedupeResultItem { resultId?: number; sourceFilename: string; outputFilename?: string; success: boolean; error?: string; downloadUrl?: string; } export interface DedupeRunVo { total: number; successCount: number; failedCount: number; items: DedupeResultItem[]; } export interface DedupeHistoryVo { items: DedupeResultItem[]; } export interface DedupeRunRequest { files: UploadedFileRef[]; selectedColumns: string[]; keepIntegerIds: boolean; keepUnderscoreIds: boolean; keepIntegerMainIdsWhenNoSubIds: boolean; archiveName?: string; user_id: number; } export interface SplitArchiveEntry { filename: string; rowCount?: number; } export interface SplitResultItem { resultId?: number; sourceFilename: string; outputFilename?: string; success: boolean; error?: string; rowCount?: number; downloadUrl?: string; entryCount?: number; entries?: SplitArchiveEntry[]; } export interface SplitRunVo { total: number; successCount: number; failedCount: number; items: SplitResultItem[]; } export interface SplitHistoryVo { items: SplitResultItem[]; } export interface SplitRunRequest { files: UploadedFileRef[]; selectedColumns: string[]; splitMode: "rows_per_file" | "parts"; rowsPerFile?: number; parts?: number; archiveName?: string; user_id: number; } export interface ConvertResultItem { resultId?: number; sourceFilename: string; outputFilename?: string; success: boolean; error?: string; downloadUrl?: string; } export interface ConvertRunVo { total: number; successCount: number; failedCount: number; items: ConvertResultItem[]; } export interface ConvertHistoryVo { items: ConvertResultItem[]; } export interface ConvertRunRequest { files: UploadedFileRef[]; templateId: string; archiveName?: string; user_id: number; } 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; matched?: boolean; matchStatus?: DeleteBrandMatchStatus; matchMessage?: string; shopId?: string; platform?: string; openStoreUrl?: string; outputFilename?: string; downloadUrl?: string; 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 interface ConvertTemplateVo { id: string; templateCode: string; templateName: string; outputFilename: string; isDefault?: boolean; builtIn?: boolean; } export interface ConvertTemplateImportRequest { templateName: string; templateContent: string; } export interface ExcelInfoVo { headers: string[]; totalRows: number; } export function getExcelInfo(fileKey: string) { return unwrapJavaResponse( get>(`${JAVA_API_PREFIX}/files/excel-info`, { params: { fileKey }, }), ); } export function runDedupe( request: Omit | DedupeRunRequest, ) { return unwrapJavaResponse( post, DedupeRunRequest>( `${JAVA_API_PREFIX}/dedupe/run`, { ...request, user_id: getCurrentUserId(), }, ), ); } export function getDedupeHistory() { return unwrapJavaResponse( get>(`${JAVA_API_PREFIX}/dedupe/history`, { params: { user_id: getCurrentUserId() }, }), ); } export function deleteDedupeHistory(resultId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/dedupe/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function runSplit( request: Omit | SplitRunRequest, ) { return unwrapJavaResponse( post, SplitRunRequest>( `${JAVA_API_PREFIX}/split/run`, { ...request, user_id: getCurrentUserId(), }, ), ); } export function getSplitHistory() { return unwrapJavaResponse( get>(`${JAVA_API_PREFIX}/split/history`, { params: { user_id: getCurrentUserId() }, }), ); } export function deleteSplitHistory(resultId: number) { return unwrapJavaResponse( del>(`${JAVA_API_PREFIX}/split/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }), ); } export function getConvertTemplates() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/convert/templates`, ), ); } export function importConvertTemplate(request: ConvertTemplateImportRequest) { return unwrapJavaResponse( post, ConvertTemplateImportRequest>( `${JAVA_API_PREFIX}/convert/templates/import`, request, ), ); } export function setDefaultConvertTemplate(templateCode: string) { return unwrapJavaResponse( post>( `${JAVA_API_PREFIX}/convert/templates/${templateCode}/default`, ), ); } export function deleteConvertTemplate(templateCode: string) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/convert/templates/${templateCode}`, ), ); } export function runConvert( request: Omit | ConvertRunRequest, ) { return unwrapJavaResponse( post, ConvertRunRequest>( `${JAVA_API_PREFIX}/convert/run`, { ...request, user_id: getCurrentUserId(), }, ), ); } export function getConvertHistory() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/convert/history`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function deleteConvertHistory(resultId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/convert/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function runDeleteBrand( request: Omit | DeleteBrandRunRequest, ) { return unwrapJavaResponse( post, DeleteBrandRunRequest>( `${JAVA_API_PREFIX}/delete-brand/run`, { ...request, user_id: getCurrentUserId(), }, ), ); } export function getDeleteBrandHistory() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/delete-brand/history`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function deleteDeleteBrandHistory(resultId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/delete-brand/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function getDeleteBrandTaskDetail(taskId: number) { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}`, ), ); } export function getDeleteBrandTaskDetails(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/delete-brand/tasks/batch`, { taskIds }, ), ); } export function getDeleteBrandTaskDownloadUrl(taskId: number) { return getJavaDownloadUrl(`/delete-brand/tasks/${taskId}/download`); } export function submitDeleteBrandResult( taskId: number, request: DeleteBrandSubmitResultRequest, ) { return unwrapJavaResponse( post, DeleteBrandSubmitResultRequest>( `${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}/result`, request, ), ); } /** 商品风险处理:备选店铺与匹配相关数据结构。 */ export interface ProductRiskCandidateVo { id: number; shop_name: string; created_at?: string; } export interface ProductRiskShopQueueItem { shopName: string; matched: boolean; shopId?: string; platform?: string; companyName?: string; openStoreUrl?: string; matchedUserId?: number; matchStatus?: string; matchMessage?: string; } export interface ProductRiskMatchShopsVo { items: ProductRiskShopQueueItem[]; } export function listProductRiskCandidates() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/product-risk-resolve/candidates`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function addProductRiskCandidate(shopName: string) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; shop_name: string } >(`${JAVA_API_PREFIX}/product-risk-resolve/candidates`, { user_id: getCurrentUserId(), shop_name: shopName, }), ); } export function deleteProductRiskCandidate(id: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/product-risk-resolve/candidates/${id}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export interface ProductRiskCountryPreferenceVo { country_codes: string[]; } export function getProductRiskCountryPreference() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/product-risk-resolve/country-preference`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function putProductRiskCountryPreference(countryCodes: string[]) { return unwrapJavaResponse( put< JavaApiResponse, { user_id: number; country_codes: string[] } >(`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`, { user_id: getCurrentUserId(), country_codes: countryCodes, }), ); } export function matchProductRiskShops(shopNames: string[]) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; shop_names: string[] } >(`${JAVA_API_PREFIX}/product-risk-resolve/match-shops`, { user_id: getCurrentUserId(), shop_names: shopNames, }), ); } export interface ProductRiskDashboardVo { candidateCount: number; processedTaskCount: number; successTaskCount: number; failedTaskCount: number; } export interface ProductRiskHistoryItem { resultId?: number; taskId?: number; shopName?: string; shopId?: string; platform?: string; companyName?: string; matched?: boolean; matchStatus?: string; matchMessage?: string; taskStatus?: string; success?: boolean; error?: string; outputFilename?: string; downloadUrl?: string; scheduledAt?: string; } export interface ProductRiskHistoryVo { items: ProductRiskHistoryItem[]; } export interface ProductRiskTaskSummary { id?: number; taskNo?: string; status?: string; errorMessage?: string; createdAt?: string; updatedAt?: string; finishedAt?: string; scheduledAt?: string; countryCodes?: string[]; currentStageIndex?: number; activeStageIndex?: number; scheduleStages?: ShopMatchTaskStage[]; } export interface ProductRiskTaskDetailVo { task?: ProductRiskTaskSummary; items?: ProductRiskHistoryItem[]; } export interface ProductRiskTaskBatchVo { items: ProductRiskTaskDetailVo[]; missingTaskIds?: number[]; } export interface ProductRiskPendingDeleteVo { removed: boolean; } export interface ProductRiskCreateTaskVo { taskId: number; items: ProductRiskHistoryItem[]; } export type ShopMatchCandidateVo = ProductRiskCandidateVo; export type ShopMatchCountryPreferenceVo = ProductRiskCountryPreferenceVo; export type ShopMatchShopQueueItem = ProductRiskShopQueueItem; export type ShopMatchDashboardVo = ProductRiskDashboardVo; export type ShopMatchHistoryItem = ProductRiskHistoryItem; export type ShopMatchHistoryVo = ProductRiskHistoryVo; export type ShopMatchTaskDetailVo = ProductRiskTaskDetailVo; export type ShopMatchTaskBatchVo = ProductRiskTaskBatchVo; export type ShopMatchCreateTaskVo = ProductRiskCreateTaskVo; export interface ShopMatchTaskStage { stageIndex?: number; scheduledAt?: string; status?: string; } export function getProductRiskDashboard() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/product-risk-resolve/dashboard`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function getProductRiskHistory() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/product-risk-resolve/history`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function deleteProductRiskHistory(resultId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/product-risk-resolve/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function createProductRiskTask(items: ProductRiskShopQueueItem[]) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; items: ProductRiskShopQueueItem[] } >(`${JAVA_API_PREFIX}/product-risk-resolve/tasks`, { user_id: getCurrentUserId(), items, }), ); } export function deleteProductRiskTask(taskId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/product-risk-resolve/tasks/${taskId}`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function deletePendingProductRiskShopResult(shopName: string) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/product-risk-resolve/pending-shop-result`, { params: { user_id: getCurrentUserId(), shop_name: shopName }, }, ), ); } export function getProductRiskTasksBatch(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/product-risk-resolve/tasks/batch`, { taskIds }, ), ); } export function getProductRiskResultDownloadUrl(resultId: number) { return getJavaDownloadUrl( `/product-risk-resolve/results/${resultId}/download`, ); } export function listShopMatchCandidates() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/shop-match/candidates`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function addShopMatchCandidate(shopName: string) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; shop_name: string } >(`${JAVA_API_PREFIX}/shop-match/candidates`, { user_id: getCurrentUserId(), shop_name: shopName, }), ); } export function deleteShopMatchCandidate(id: number) { return unwrapJavaResponse( del>(`${JAVA_API_PREFIX}/shop-match/candidates/${id}`, { params: { user_id: getCurrentUserId() }, }), ); } export function getShopMatchCountryPreference() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/shop-match/country-preference`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function putShopMatchCountryPreference(countryCodes: string[]) { return unwrapJavaResponse( put< JavaApiResponse, { user_id: number; country_codes: string[] } >(`${JAVA_API_PREFIX}/shop-match/country-preference`, { user_id: getCurrentUserId(), country_codes: countryCodes, }), ); } export function matchShopMatchShops(shopNames: string[]) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; shop_names: string[] } >(`${JAVA_API_PREFIX}/shop-match/match-shops`, { user_id: getCurrentUserId(), shop_names: shopNames, }), ); } export function getShopMatchDashboard() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/shop-match/dashboard`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function getShopMatchHistory() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/shop-match/history`, { params: { user_id: getCurrentUserId() }, }, ), ); } export function deleteShopMatchHistory(resultId: number) { return unwrapJavaResponse( del>(`${JAVA_API_PREFIX}/shop-match/history/${resultId}`, { params: { user_id: getCurrentUserId() }, }), ); } export function createShopMatchTask( items: ShopMatchShopQueueItem[], countryCodes: string[], scheduleTimes?: string[], ) { return unwrapJavaResponse( post< JavaApiResponse, { user_id: number; items: ShopMatchShopQueueItem[]; country_codes: string[]; schedule_times?: string[] } >(`${JAVA_API_PREFIX}/shop-match/tasks`, { user_id: getCurrentUserId(), items, country_codes: countryCodes, schedule_times: scheduleTimes, }), ); } export function deleteShopMatchTask(taskId: number) { return unwrapJavaResponse( del>(`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}`, { params: { user_id: getCurrentUserId() }, }), ); } export function activateShopMatchTask(taskId: number, stageIndex: number) { return unwrapJavaResponse( post, undefined>( `${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}&stage_index=${encodeURIComponent(String(stageIndex))}`, undefined, ), ); } export function completeShopMatchTaskStage(taskId: number, stageIndex: number) { return unwrapJavaResponse( post, { stage_index: number }>( `${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/stage-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, { stage_index: stageIndex }, ), ); } export function getShopMatchTasksBatch(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/shop-match/tasks/batch`, { taskIds }, ), ); } export function getShopMatchResultDownloadUrl(resultId: number) { return getJavaDownloadUrl(`/shop-match/results/${resultId}/download`); } // ========== 跟价 ========== 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; } export interface PriceTrackMatchShopsVo { items: PriceTrackShopQueueItem[]; skipAsinsByCountry?: Record; asinRowsByCountry?: Record; } 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; error?: string; success?: boolean; } export interface PriceTrackHistoryVo { items: PriceTrackHistoryItem[]; } export interface PriceTrackAsinParsedRow { shopMallName?: string; asin?: string; price?: string; recommendedPrice?: string; minimumPrice?: string; firstPlace?: string; secondPlace?: string; cartShopName?: string; priceChangeStatus?: string; modifyCount?: string; status?: string; } export interface PriceTrackCreateTaskVo { taskId: number; items: PriceTrackHistoryItem[]; skipAsinsByCountry?: Record; asinRowsByCountry?: Record; } 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>( `${JAVA_API_PREFIX}/price-track/candidates?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function addPriceTrackCandidate(shopName: string) { return unwrapJavaResponse( post, { userId: number; shopName: string }>( `${JAVA_API_PREFIX}/price-track/candidates`, { userId: getCurrentUserId(), shopName }, ), ); } export function deletePriceTrackCandidate(id: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/price-track/candidates/${id}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function getPriceTrackCountryPreference() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/price-track/country-preference?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function putPriceTrackCountryPreference(countryCodes: string[]) { return unwrapJavaResponse( put, { 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, { 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 unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/shop-match/tasks/progress/batch`, { taskIds }, ), ); } export function getProductRiskTaskProgressBatch(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/product-risk-resolve/tasks/progress/batch`, { taskIds }, ), ); } export function getDeleteBrandTaskProgress(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/delete-brand/tasks/progress/batch`, { taskIds }, ), ); } export function getPriceTrackDashboard() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/price-track/dashboard?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function getPriceTrackHistory() { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/price-track/history?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function deletePriceTrackHistory(resultId: number) { return unwrapJavaResponse( del>( `${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, PriceTrackCreateTaskRequest>( `${JAVA_API_PREFIX}/price-track/tasks`, { ...request, userId: getCurrentUserId() }, ), ); } export function deletePriceTrackTask(taskId: number) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/price-track/tasks/${taskId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function getPriceTrackTasksBatch(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/price-track/tasks/batch`, { taskIds }, ), ); } export function createPriceTrackLoopRun( request: Omit | PriceTrackLoopRunCreateRequest, ) { return unwrapJavaResponse( post, PriceTrackLoopRunCreateRequest>( `${JAVA_API_PREFIX}/price-track/loop-runs`, { ...request, userId: getCurrentUserId() }, ), ); } export function getPriceTrackLoopRun(loopRunId: number) { return unwrapJavaResponse( get>( `${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, ), ); } export function dispatchNextPriceTrackLoopRun(loopRunId: number) { return unwrapJavaResponse( post, 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, { 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, undefined>( `${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/stop?user_id=${encodeURIComponent(String(getCurrentUserId()))}`, undefined, ), ); } export function getPriceTrackTaskProgressBatch(taskIds: number[]) { return unwrapJavaResponse( post, { taskIds: number[] }>( `${JAVA_API_PREFIX}/price-track/tasks/progress/batch`, { taskIds }, ), ); } export function getPriceTrackResultDownloadUrl(resultId: number) { return getJavaDownloadUrl(`/price-track/results/${resultId}/download`); } export function deletePendingPriceTrackShopResult(shopName: string) { return unwrapJavaResponse( del>( `${JAVA_API_PREFIX}/price-track/pending-shop-result?user_id=${encodeURIComponent(String(getCurrentUserId()))}&shop_name=${encodeURIComponent(shopName)}`, ), ); } export function getJavaDownloadUrl(path: string) { let raw = path.startsWith("http://") || path.startsWith("https://") ? path : `${JAVA_API_PREFIX}${path}`; // pywebview 的 save_file_from_url_new 需要完整且带 schema 的 URL if ( !raw.startsWith("http://") && !raw.startsWith("https://") && typeof window !== "undefined" ) { raw = `${window.location.origin}${raw}`; } const separator = raw.includes("?") ? "&" : "?"; return `${raw}${separator}user_id=${encodeURIComponent(String(getCurrentUserId()))}`; } export { JAVA_API_PREFIX, http };