Files
crawler-plugin/admin-frontend-vue/src/pages/records/history-dto.ts
T
huangzd1997 83a444def6 feat(公司tab): 接线 生成记录——company_id 走 DataReadScope,空成员集一律空页
「tab 画出来了、请求真带了 company_id、后端读都不读」是撒谎窗口,比不接更坏:
页面标题写某公司、数据仍是全量。所以后半页必须同时落地读侧与前端。

- controller 收显式 company_id,菜单闸门仍在算范围之前;范围只在 DataReadScope
  一处出口(不再有第二个 if)。DELETE /history 与 clearAllHistory 一字未动:
  写操作不吃 company_id。
- service 的总数与行集共用同一个 filterOf,"同范围"由结构保证;空成员集在
  分页归一之后早退,绝不把 [] 交给 in()(渲染成 IN () 就是 500)。
- 前端从原始 params 读 companyId——normalizeHistoryParams 是白名单构造,从
  normalized 读会静默拿到 undefined,编译绿、请求里没有参数。

验证:ImageHistoryServiceTest 7/0,后端全量 3663 例 0 红;G1 缺口清单 7 页 →
6 页(admin_history 消失);前端 1726/1725/1(那条红是刻意留的接线缺口尺子)、
vue-tsc rc=0。变异 M-A(删 filter.in)与 M-B(早退改永假)各杀 2 支。
2026-10-05 08:32:40 +08:00

93 lines
2.9 KiB
TypeScript

/** 历史生成记录 DTO(任务 121):列表筛选/分页归一与类型边界;与 Java ImageHistoryController
* snake 契约对齐;历史页与后台版本/公开版本接口分离。纯逻辑。 */
export const HISTORY_DEFAULT_PAGE_SIZE = 10
export const HISTORY_MIN_PAGE = 1
export const HISTORY_MAX_PAGE_SIZE = 200
/** 历史记录面板类型(保留字符串,由后端 panel_type 决定)。 */
export type HistoryRecordType = string
export interface HistoryRecordItem {
id: number
userId: number | null
username: string
createdAt: string
panelType: HistoryRecordType
originalUrls: string[]
resultUrls: string[]
longImageUrl: string
params?: Record<string, unknown>
}
export interface HistoryPageResult {
items: HistoryRecordItem[]
total: number
page: number
pageSize: number
}
export interface HistoryListParams {
page: number
pageSize: number
userId?: number | null
timeStart?: string
timeEnd?: string
/** 公司 tab 的当前值;页面传入,不参与 normalizeHistoryParams 的归一(它是白名单构造)。 */
companyId?: number | null
}
export interface HistoryListQuery {
page: number
page_size: number
user_id?: number
time_start?: string
time_end?: string
company_id?: number
}
function finiteInt(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
}
function positiveIdOrNull(value: unknown): number | null {
const id = finiteInt(value)
return id === null || id < 1 ? null : id
}
function textOrUndefined(value: unknown): string | undefined {
const text = typeof value === 'string' ? value.trim() : ''
return text || undefined
}
/** 归一历史筛选/分页:页码下限 1、页大小 1..上限。 */
export function normalizeHistoryParams(raw: Partial<HistoryListParams>): HistoryListParams {
const page = Math.max(finiteInt(raw.page) ?? HISTORY_MIN_PAGE, HISTORY_MIN_PAGE)
const rawSize = finiteInt(raw.pageSize)
const pageSize =
rawSize === null || rawSize < HISTORY_MIN_PAGE
? HISTORY_DEFAULT_PAGE_SIZE
: Math.min(rawSize, HISTORY_MAX_PAGE_SIZE)
return {
page,
pageSize,
userId: positiveIdOrNull(raw.userId),
timeStart: textOrUndefined(raw.timeStart),
timeEnd: textOrUndefined(raw.timeEnd),
}
}
/** 前端状态 → Java 查询参数(snake,仅下发非空)。 */
export function toHistoryListQuery(params: HistoryListParams): HistoryListQuery {
const query: HistoryListQuery = { page: params.page, page_size: params.pageSize }
if (params.userId != null) query.user_id = params.userId
if (params.timeStart) query.time_start = params.timeStart
if (params.timeEnd) query.time_end = params.timeEnd
return query
}
/** 无数据历史分页缺省值。 */
export function emptyHistoryPage(): HistoryPageResult {
return { items: [], total: 0, page: HISTORY_MIN_PAGE, pageSize: HISTORY_DEFAULT_PAGE_SIZE }
}