feat(brandgating): 品牌Gating库并入店铺数据重复检查页
- 「店铺数据重复检查」新增「品牌Gating库」页签,承接原独立 Gating 网页后台的列表/筛选/统计、单条新增、批量导入、启停与删除。 - 复用既有 /api/admin/brand-gating 模块;接口权限键跟随宿主页 admin_shop_data_duplicate_check(V164 菜单已由 V166 删除)。 - 前端新增 brand-gating 模型/API 适配、BrandGatingPanel 与纯逻辑单测。
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
/** 品牌Gating库模型(任务:并入「店铺数据重复检查」页签):与 /api/admin/brand-gating 的 camel 契约对齐,纯逻辑。 */
|
||||
|
||||
export const GATING_COUNTRIES = ['全部', '英国', '德国', '法国', '西班牙', '意大利'] as const
|
||||
export const GATING_TYPES = ['品牌gating', '类目gating', '账户不符合'] as const
|
||||
export const GATING_SOURCES = ['AUTO', 'MANUAL'] as const
|
||||
|
||||
export type GatingStatusFilter = '' | '1' | '0'
|
||||
|
||||
export interface BrandGatingFilter {
|
||||
keyword: string
|
||||
country: string
|
||||
gatingType: string
|
||||
status: GatingStatusFilter
|
||||
source: string
|
||||
}
|
||||
|
||||
export interface BrandGatingForm {
|
||||
brand: string
|
||||
country: string
|
||||
gatingType: string
|
||||
asin: string
|
||||
remark: string
|
||||
}
|
||||
|
||||
export interface BrandGatingRow {
|
||||
id: number
|
||||
brand: string
|
||||
asin: string
|
||||
country: string
|
||||
gatingType: string
|
||||
/** 1=生效 0=已解除。 */
|
||||
status: number
|
||||
source: string
|
||||
shopName: string
|
||||
remark: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
disabledAt: string
|
||||
}
|
||||
|
||||
export interface BrandGatingNameCount {
|
||||
name: string
|
||||
count: number
|
||||
}
|
||||
|
||||
export interface BrandGatingStats {
|
||||
total: number
|
||||
active: number
|
||||
disabled: number
|
||||
brands: number
|
||||
byType: BrandGatingNameCount[]
|
||||
byCountry: BrandGatingNameCount[]
|
||||
bySource: BrandGatingNameCount[]
|
||||
}
|
||||
|
||||
export interface BrandGatingPage {
|
||||
total: number
|
||||
rows: BrandGatingRow[]
|
||||
}
|
||||
|
||||
export interface BrandGatingImportResult {
|
||||
added: number
|
||||
skipped: number
|
||||
}
|
||||
|
||||
export function createBrandGatingFilter(): BrandGatingFilter {
|
||||
return { keyword: '', country: '', gatingType: '', status: '', source: '' }
|
||||
}
|
||||
|
||||
export function createBrandGatingForm(): BrandGatingForm {
|
||||
return { brand: '', country: '全部', gatingType: '品牌gating', asin: '', remark: '' }
|
||||
}
|
||||
|
||||
/** 列表查询参数:空值与「全部」哨兵不下发,其余原样交给后端(与桌面版 list_gating 同口径)。 */
|
||||
export function toBrandGatingQuery(
|
||||
filter: BrandGatingFilter,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
): Record<string, string | number> {
|
||||
const query: Record<string, string | number> = {
|
||||
page: Math.max(1, Math.trunc(page) || 1),
|
||||
size: Math.max(1, Math.trunc(pageSize) || 10),
|
||||
}
|
||||
const keyword = filter.keyword.trim()
|
||||
if (keyword) query.keyword = keyword
|
||||
if (filter.country && filter.country !== '全部') query.country = filter.country
|
||||
if (filter.gatingType && filter.gatingType !== '全部') query.gatingType = filter.gatingType
|
||||
if (filter.status === '1' || filter.status === '0') query.status = filter.status
|
||||
if (filter.source && filter.source !== '全部') query.source = filter.source
|
||||
return query
|
||||
}
|
||||
|
||||
/** 单条新增前置校验:只拦空品牌,其余字段由后端落桌面版同款默认值。 */
|
||||
export function validateBrandGatingForm(form: BrandGatingForm): string {
|
||||
if (!form.brand.trim()) return '请填写品牌'
|
||||
return ''
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value && typeof value === 'object' ? (value as Record<string, unknown>) : null
|
||||
}
|
||||
|
||||
function textOf(value: unknown): string {
|
||||
return value == null ? '' : String(value).trim()
|
||||
}
|
||||
|
||||
function countOf(value: unknown): number {
|
||||
const count = Number(value)
|
||||
return Number.isFinite(count) ? Math.max(0, Math.trunc(count)) : 0
|
||||
}
|
||||
|
||||
function nameCountsOf(value: unknown): BrandGatingNameCount[] {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value
|
||||
.map((item) => {
|
||||
const record = asRecord(item)
|
||||
if (!record) return null
|
||||
const name = textOf(record.name)
|
||||
return name ? { name, count: countOf(record.count) } : null
|
||||
})
|
||||
.filter((item): item is BrandGatingNameCount => item !== null)
|
||||
}
|
||||
|
||||
export function parseBrandGatingRow(raw: unknown): BrandGatingRow | null {
|
||||
const record = asRecord(raw)
|
||||
if (!record) return null
|
||||
const id = Number(record.id)
|
||||
if (!Number.isFinite(id)) return null
|
||||
return {
|
||||
id,
|
||||
brand: textOf(record.brand),
|
||||
asin: textOf(record.asin),
|
||||
country: textOf(record.country),
|
||||
gatingType: textOf(record.gatingType),
|
||||
status: countOf(record.status) === 1 ? 1 : 0,
|
||||
source: textOf(record.source),
|
||||
shopName: textOf(record.shopName),
|
||||
remark: textOf(record.remark),
|
||||
createdAt: textOf(record.createdAt),
|
||||
updatedAt: textOf(record.updatedAt),
|
||||
disabledAt: textOf(record.disabledAt),
|
||||
}
|
||||
}
|
||||
|
||||
export function parseBrandGatingPage(raw: unknown): BrandGatingPage {
|
||||
const record = asRecord(raw)
|
||||
if (!record) return { total: 0, rows: [] }
|
||||
const rows = Array.isArray(record.rows)
|
||||
? record.rows
|
||||
.map(parseBrandGatingRow)
|
||||
.filter((row): row is BrandGatingRow => row !== null)
|
||||
: []
|
||||
return { total: countOf(record.total), rows }
|
||||
}
|
||||
|
||||
export function parseBrandGatingStats(raw: unknown): BrandGatingStats {
|
||||
const record = asRecord(raw)
|
||||
return {
|
||||
total: countOf(record?.total),
|
||||
active: countOf(record?.active),
|
||||
disabled: countOf(record?.disabled),
|
||||
brands: countOf(record?.brands),
|
||||
byType: nameCountsOf(record?.byType),
|
||||
byCountry: nameCountsOf(record?.byCountry),
|
||||
bySource: nameCountsOf(record?.bySource),
|
||||
}
|
||||
}
|
||||
|
||||
/** 单条新增回包:added=1 新增成功,0 表示撞唯一键(品牌+国家已存在)。 */
|
||||
export function parseBrandGatingAddResult(raw: unknown): boolean {
|
||||
return countOf(asRecord(raw)?.added) > 0
|
||||
}
|
||||
|
||||
export function parseBrandGatingImportResult(raw: unknown): BrandGatingImportResult {
|
||||
const record = asRecord(raw)
|
||||
return { added: countOf(record?.added), skipped: countOf(record?.skipped) }
|
||||
}
|
||||
Reference in New Issue
Block a user