task-62(ASIN 数据中心): 实现去重汇总列表查询
新增 dedupe-total-model.ts 纯解析 DedupeTotalDataPageVo(camel items/total/page/pageSize, 条目 dataValue/country/groupId/groupName/uploader/username/createdAt,缺 id 过滤); dedupe-total-api.ts fetchDedupeTotalList 复用共享筛选归一后 GET /api/admin/dedupe-total-data。 8 用例全过,451 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/** 去重汇总列表查询适配(任务 62):GET /api/admin/dedupe-total-data + 共享筛选归一。 */
|
||||
import { http } from '@/api/http'
|
||||
import { normalizeAsinPageParams, toAsinPageQuery, type AsinListParams } from './asin-filter'
|
||||
import { parseDedupeTotalPage, type DedupeTotalPageResult } from './dedupe-total-model'
|
||||
|
||||
export const DEDUPE_TOTAL_ENDPOINT = '/api/admin/dedupe-total-data'
|
||||
|
||||
export async function fetchDedupeTotalList(params: Partial<AsinListParams> = {}): Promise<DedupeTotalPageResult> {
|
||||
const normalized = normalizeAsinPageParams(params)
|
||||
const { data } = await http.get<unknown>(DEDUPE_TOTAL_ENDPOINT, { params: toAsinPageQuery(normalized) })
|
||||
return parseDedupeTotalPage(data)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/** 去重汇总列表查询模型(任务 62):解析 DedupeTotalDataPageVo(camel),纯逻辑。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
import { ASIN_PAGE_DEFAULT_SIZE, type AsinListParams } from './asin-filter.ts'
|
||||
|
||||
export interface DedupeTotalItem {
|
||||
id: number
|
||||
dataValue: string
|
||||
country: string
|
||||
groupId: number | null
|
||||
groupName: string
|
||||
uploaderUserId: number | null
|
||||
username: string
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
export interface DedupeTotalPageResult {
|
||||
items: DedupeTotalItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export function emptyDedupeTotalPage(): DedupeTotalPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: ASIN_PAGE_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 解析单条去重总数据;缺 id 视为无效。 */
|
||||
export function toDedupeTotalItem(raw: unknown): DedupeTotalItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
const item: DedupeTotalItem = {
|
||||
id,
|
||||
dataValue: text(record.dataValue ?? record.data_value),
|
||||
country: text(record.country),
|
||||
groupId: numberOrNull(record.groupId ?? record.group_id),
|
||||
groupName: text(record.groupName ?? record.group_name),
|
||||
uploaderUserId: numberOrNull(record.uploaderUserId ?? record.uploader_user_id),
|
||||
username: text(record.username),
|
||||
}
|
||||
const createdAt = text(record.createdAt ?? record.created_at)
|
||||
if (createdAt) item.createdAt = createdAt
|
||||
return item
|
||||
}
|
||||
|
||||
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。 */
|
||||
export function parseDedupeTotalPage(payload: unknown): DedupeTotalPageResult {
|
||||
const out = emptyDedupeTotalPage()
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toDedupeTotalItem(raw))
|
||||
.filter((item): item is DedupeTotalItem => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
|
||||
/** 构造缺省分页查询参数(供初始加载使用)。 */
|
||||
export function emptyDedupePageParams(): Partial<AsinListParams> {
|
||||
return { page: 1, pageSize: ASIN_PAGE_DEFAULT_SIZE }
|
||||
}
|
||||
Reference in New Issue
Block a user