task-113(任务与重复分析中心): 实现店铺数据任务批量下载

新增 shop-data-download.ts(打包请求体 result_ids + 下载 job 状态),
shop-data-api.ts 增加 requestShopDataZipDownload(POST /download-zip, blob)。

TDD: task-113.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
2026-09-05 17:20:39 +08:00
parent 40463772c5
commit 69f6965c93
3 changed files with 125 additions and 1 deletions
@@ -0,0 +1,48 @@
/** 店铺数据结果批量下载任务(任务 113):打包请求体与下载 job 状态;纯逻辑。 */
export type ShopDataDownloadStatus = 'idle' | 'running' | 'done' | 'failed'
export interface ShopDataDownloadJob {
status: ShopDataDownloadStatus
message?: string
fileCount?: number
errorCount?: number
}
function finitePositive(value: unknown): number | null {
const number = typeof value === 'number' && Number.isFinite(value)
? value
: typeof value === 'string' && /^\d+$/.test(value.trim())
? Number(value.trim())
: null
return number === null || number < 1 ? null : Math.floor(number)
}
/** result_id → POST /download-zip 请求体(过滤非法 id,按序去重)。 */
export function toShopDataZipRequest(resultIds: readonly (number | string)[]): { result_ids: number[] } {
const ids: number[] = []
const seen = new Set<number>()
for (const id of resultIds) {
const parsed = finitePositive(id)
if (parsed === null || seen.has(parsed)) continue
seen.add(parsed)
ids.push(parsed)
}
return { result_ids: ids }
}
export function createShopDataDownloadJob(): ShopDataDownloadJob {
return { status: 'idle' }
}
export function startShopDataDownload(): ShopDataDownloadJob {
return { status: 'running' }
}
export function succeedShopDataDownload(_job: ShopDataDownloadJob, fileCount: number, errorCount: number): ShopDataDownloadJob {
return { status: 'done', fileCount, errorCount }
}
export function failShopDataDownload(_job: ShopDataDownloadJob, message: string): ShopDataDownloadJob {
return { status: 'failed', message }
}