109 lines
4.4 KiB
TypeScript
109 lines
4.4 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
|
|
|
|
export function emptyAppearancePatentCleanPage(): AppearancePatentCleanPageResult {
|
|
return { items: [], total: 0, page: 1, pageSize: APPEARANCE_PATENT_CLEAN_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 视为无效。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
|
|
}
|
|
|
|
/** 结论单元格的悬停全文:三因齐给,空因不下发(读侧不加工的展示面出口)。 */
|
|
export function cleanItemReasonTooltip(item: AppearancePatentCleanItem): string {
|
|
const parts: string[] = []
|
|
if (item.titleReason) parts.push(`标题:${item.titleReason}`)
|
|
if (item.appearanceReason) parts.push(`外观:${item.appearanceReason}`)
|
|
if (item.patentReason) parts.push(`专利:${item.patentReason}`)
|
|
return parts.join('\n')
|
|
}
|