Files
crawler-plugin/admin-frontend-vue/src/pages/asin/dedupe-total-model.ts
T
huangzd1997 892d88ed1e feat(后台管理): 实体管理列表统一展示创建时间/更新时间
用户管理、菜单管理、不符合ASIN、数据去重总数据、查询ASIN、最低价ASIN、
商品类目、密钥管理共 8 个实体管理列表补齐两列。分组管理/店铺密钥/店铺管理
此前已带创建+修改时间,任务列表与统计报表(撞款监控、密钥用量、日志、
记录与版本)不含实体更新语义,均未改动。

关键点——时间列必须由数据库维护,否则新列是假的:
这些表的更新走 selectById → 改字段 → updateById,实体带着读出的旧
updated_at 一起写回。MySQL 规则是「UPDATE 显式给某列赋值时不触发该列的
ON UPDATE 自动更新」,不禁写就会把旧值写回去,更新时间永远冻结在首次写入
时刻。按 V125(biz_file_result)既有样板,给 7 个实体标注
@TableField(insertStrategy=NEVER, updateStrategy=NEVER)。

- V131:users / columns 补 updated_at(幂等 ADD COLUMN,仿 V125 写法)。
  存量行被回填为迁移执行时刻,非真实历史变更时间(历史上无记录,无法还原)
- 实体/VO:AdminUserEntity、PermissionMenuEntity、InvalidAsinDataEntity、
  DedupeTotalDataEntity、ProductCategoryEntity、QueryAsinEntity、
  SkipPriceAsinEntity 加/改写 updatedAt;AdminUserItemVo、PermissionMenuItemVo、
  InvalidAsinDataItemVo、DedupeTotalDataItemVo 补 updatedAt;
  AdminUserSecretRowVo 补 createdAt(行级首次配置时间 = 三模块最早)
- 查询ASIN/最低价ASIN 后端 VO 与前端 model 本就有两字段,仅补渲染
- 前端 8 页表格加列,同步修正空态/加载行的 colspan(手写表格,不同步会错位)
- 测试:align-query-asin / align-skip-price 原断言「不允许有更新时间列」
  (像素复刻旧版),按新需求改为断言两列存在;新增 e2e list-time-columns
  覆盖 8 页表头与真实时间值渲染
2026-09-19 15:53:01 +08:00

141 lines
5.5 KiB
TypeScript

/** 去重汇总列表查询模型(任务 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
updatedAt?: string
}
export interface DedupeTotalPageResult {
items: DedupeTotalItem[]
total: number
page: number
pageSize: number
/** 顺序翻页游标:本页最后一行 id;下一页回传它即可走 keyset。 */
nextLastId?: 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
const updatedAt = text(record.updatedAt ?? record.updated_at)
if (updatedAt) item.updatedAt = updatedAt
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 rawNextLastId = record.nextLastId ?? record.next_last_id
if (typeof rawNextLastId === 'number' && rawNextLastId > 0) out.nextLastId = Math.floor(rawNextLastId)
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 }
}
/** 数据权限分组选项(GET /api/admin/shop-manages/groups items)。 */
export interface DedupeGroupOption {
id: number
name: string
leaderUserId?: number | null
}
/** 归一化分组选项负载(信封 items 或裸数组),缺 id 行丢弃;解析组长 id 供汇总卡判定组长/组员。 */
export function parseDedupeGroupOptionList(payload: unknown): DedupeGroupOption[] {
const core = unwrap<unknown>(payload)
const rawList = Array.isArray(core)
? core
: core && typeof core === 'object'
? (core as Record<string, unknown>).items
: []
if (!Array.isArray(rawList)) return []
const options: DedupeGroupOption[] = []
for (const raw of rawList) {
if (!raw || typeof raw !== 'object') continue
const record = raw as Record<string, unknown>
const id = typeof record.id === 'number' ? Math.floor(record.id) : Number(record.group_id)
if (!Number.isFinite(id) || id <= 0) continue
const nameRaw = record.groupName ?? record.group_name ?? record.name
const name = typeof nameRaw === 'string' ? nameRaw.trim() : ''
const option: DedupeGroupOption = { id, name: name || `分组${id}` }
const leaderRaw = record.leader_user_id ?? record.leaderUserId
const leaderUserId = typeof leaderRaw === 'number' ? Math.floor(leaderRaw) : Number(leaderRaw)
if (Number.isFinite(leaderUserId) && leaderUserId > 0) option.leaderUserId = leaderUserId
options.push(option)
}
return options
}
/** 页顶数据权限分组汇总(对齐 admin.js renderDedupeGroupSummary)。 */
export type DedupeGroupSummary =
| { kind: 'all'; count: number }
| { kind: 'none' }
| { kind: 'chips'; chips: Array<{ name: string; relation: string }>; extra: number }
export function dedupeGroupSummaryOf(
groups: DedupeGroupOption[],
currentUserId: number | null,
operatorRole: string,
): DedupeGroupSummary {
if ((operatorRole || '').toLowerCase() === 'super_admin') {
return { kind: 'all', count: groups.length }
}
if (!groups.length) return { kind: 'none' }
const visible = groups.slice(0, 4)
const currentKey = currentUserId != null ? String(currentUserId) : ''
const chips = visible.map((group) => ({
name: group.name,
relation: String(group.leaderUserId ?? '') === currentKey ? '组长' : '组员',
}))
return { kind: 'chips', chips, extra: Math.max(groups.length - visible.length, 0) }
}