172 lines
7.1 KiB
TypeScript
172 lines
7.1 KiB
TypeScript
/** 外观专利无侵权数据列表查询模型(v1.3 AC-5):解析 AppearancePatentCleanItemPageVo(camel),纯逻辑。
|
|
* 行值是同步服务从 chunk payload 原样落的,读侧只搬运不加工(与后端 toVo 同一口径)。 */
|
|
import { unwrap } from '../../api/envelope.ts'
|
|
|
|
export interface AppearancePatentCleanItem {
|
|
id: number
|
|
resultId: number | null
|
|
taskId: number | null
|
|
userId: number | null
|
|
/** 所属主管(后端读侧现算列:主管/公司超管=自己,普通账户=创建人;读不到为空 → 界面展示 -)。 */
|
|
supervisorName: string
|
|
companyId: number | null
|
|
rowNo: number | null
|
|
asin: string
|
|
country: string
|
|
sku: string
|
|
brand: string
|
|
price: string
|
|
title: string
|
|
imageUrl: string
|
|
itemUrl: string
|
|
conclusion: string
|
|
titleReason: string
|
|
appearanceReason: string
|
|
patentReason: string
|
|
sourceFilename: string
|
|
syncedAt?: string
|
|
}
|
|
|
|
export interface AppearancePatentCleanPageResult {
|
|
items: AppearancePatentCleanItem[]
|
|
total: number
|
|
page: number
|
|
pageSize: number
|
|
}
|
|
|
|
/** 前端首屏默认容量:与后端 PageDefaults.CLEAN_ITEMS_PAGE_SIZE(蓝图 §3.2 默认 10)同值。 */
|
|
export const APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE = 10
|
|
|
|
/** 主管卡片(2026-11-11 客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):
|
|
* 一主管一卡,卡内是该主管名下的汇总——不再按明细铺卡(几千条明细=几千张卡,客户明确不要)。 */
|
|
export interface AppearancePatentSupervisorCard {
|
|
/** 主管用户 id;null=读不到主管的那一组(该卡不提供按主管下载)。 */
|
|
supervisorId: number | null
|
|
/** 主管名(读不到为空,界面展示 -)。 */
|
|
supervisorName: string
|
|
/** 无侵权明细条数。 */
|
|
itemCount: number
|
|
/** 涉及任务数。 */
|
|
taskCount: number
|
|
/** 最近涉及的任务号。 */
|
|
lastTaskId: number | null
|
|
/** 最近同步时间。 */
|
|
lastSyncedAt?: string
|
|
/** 涉及国家码集(前端用自己的国家字典翻中文)。 */
|
|
countryCodes: string[]
|
|
}
|
|
|
|
export interface AppearancePatentSupervisorPageResult {
|
|
items: AppearancePatentSupervisorCard[]
|
|
/** 主管数(不是明细条数)。 */
|
|
total: number
|
|
page: number
|
|
pageSize: number
|
|
}
|
|
|
|
export function emptyAppearancePatentCleanPage(): AppearancePatentCleanPageResult {
|
|
return { items: [], total: 0, page: 1, pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE }
|
|
}
|
|
|
|
/** 解析主管卡片;缺 supervisorId 的(未知主管组)依然保留(那一卡展示 -),不算无效行。 */
|
|
export function toAppearancePatentSupervisorCard(raw: unknown): AppearancePatentSupervisorCard | null {
|
|
if (!raw || typeof raw !== 'object') return null
|
|
const record = raw as Record<string, unknown>
|
|
const itemCount = numberOrNull(record.itemCount ?? record.item_count)
|
|
if (itemCount === null) return null
|
|
const rawCodes = record.countryCodes ?? record.country_codes
|
|
const countryCodes = Array.isArray(rawCodes)
|
|
? rawCodes.map((code) => text(code)).filter((code) => code.length > 0)
|
|
: []
|
|
return {
|
|
supervisorId: numberOrNull(record.supervisorId ?? record.supervisor_id),
|
|
supervisorName: text(record.supervisorName ?? record.supervisor_name),
|
|
itemCount,
|
|
taskCount: numberOrNull(record.taskCount ?? record.task_count) ?? 0,
|
|
lastTaskId: numberOrNull(record.lastTaskId ?? record.last_task_id),
|
|
lastSyncedAt: text(record.lastSyncedAt ?? record.last_synced_at) || undefined,
|
|
countryCodes,
|
|
}
|
|
}
|
|
|
|
/** 解析主管卡片分页信封({items,total,page,pageSize});total 是主管数。 */
|
|
export function parseAppearancePatentSupervisorPage(payload: unknown): AppearancePatentSupervisorPageResult {
|
|
const out: AppearancePatentSupervisorPageResult = {
|
|
items: [],
|
|
total: 0,
|
|
page: 1,
|
|
pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE,
|
|
}
|
|
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) => toAppearancePatentSupervisorCard(raw))
|
|
.filter((item): item is AppearancePatentSupervisorCard => 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
|
|
}
|
|
|
|
|
|
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 视为无效。camel 为正、snake 容错(与去重页模型同形)。 */
|
|
export function toAppearancePatentCleanItem(raw: unknown): AppearancePatentCleanItem | 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
|
|
return {
|
|
id,
|
|
resultId: numberOrNull(record.resultId ?? record.result_id),
|
|
taskId: numberOrNull(record.taskId ?? record.task_id),
|
|
userId: numberOrNull(record.userId ?? record.user_id),
|
|
supervisorName: text(record.supervisorName ?? record.supervisor_name),
|
|
companyId: numberOrNull(record.companyId ?? record.company_id),
|
|
rowNo: numberOrNull(record.rowNo ?? record.row_no),
|
|
asin: text(record.asin),
|
|
country: text(record.country),
|
|
sku: text(record.sku),
|
|
brand: text(record.brand),
|
|
price: text(record.price),
|
|
title: text(record.title),
|
|
imageUrl: text(record.imageUrl ?? record.image_url),
|
|
itemUrl: text(record.itemUrl ?? record.item_url),
|
|
conclusion: text(record.conclusion),
|
|
titleReason: text(record.titleReason ?? record.title_reason),
|
|
appearanceReason: text(record.appearanceReason ?? record.appearance_reason),
|
|
patentReason: text(record.patentReason ?? record.patent_reason),
|
|
sourceFilename: text(record.sourceFilename ?? record.source_filename),
|
|
syncedAt: text(record.syncedAt ?? record.synced_at) || undefined,
|
|
}
|
|
}
|
|
|
|
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。无 keyset 游标(蓝图 Out of Scope)。 */
|
|
export function parseAppearancePatentCleanPage(payload: unknown): AppearancePatentCleanPageResult {
|
|
const out = emptyAppearancePatentCleanPage()
|
|
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) => toAppearancePatentCleanItem(raw))
|
|
.filter((item): item is AppearancePatentCleanItem => 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
|
|
}
|