Files
crawler-plugin/admin-frontend-vue/src/api/device-logs.ts
T
huangzd1997 c772a07fbe feat(公司tab): 日志管理列表按 uid 成员集筛,麦象行走 OR 不被筛掉
生产只读取证(2026-10-05 15:1x,主机 A 业务库只读):device_log_file COUNT(*)=1028,
GROUP BY source = client 831 / maixiang 197 ⇒ 客户端占多数 ⇒ 这页留在批次 1、照声明
companyScoped(若麦象占多数,公司 tab 只会筛掉小半边,就该把这页摘出清单)。

22 行 source='client' 且 uid IS NULL 的匿名客户端日志的处置:选了公司后接受它们从
每一个 tab 里消失(条件定成 (source='maixiang' OR uid IN (成员集)),不加 uid IS NULL
那条腿)。理由是那 197 行麦象能进每一个 tab,是因为它是平台自己的采集机(基础设施),
而这 22 行只是「没登录的桌面端」——一家没有归属的行在每一家各冒充一份,既错归属也让
「这家有多少日志」这个数失去意义;tab 只是超管的视图过滤器(这页 9 个端点全在
requireSuperAdmin 之后,无非超管调用方),全量仍可由不带 company_id 的请求拿到
(readScope(operator, null) ⇒ unfiltered ⇒ memberUids=null ⇒ 一条条件都不叠)。
代价与定案写进 DeviceLogServiceTest 的 @DisplayName
「定案:那 22 行 source=client 且 uid IS NULL 的匿名客户端日志——选了公司就接受它们消失」。

接线口径:controller 收 @RequestParam(name = "company_id", required = false) 并在 handler
体内算 dataReadScope.readScope(...).userIdsOr(null) 当实参交给 service(G2 断言 C 认的形状);
条件加在 wrapperBuilder 闭包内部,selectCount 与 selectList 共用同一把尺子;空成员集退化
成 eq(source,'maixiang') 而不是不叠条件;content/download/delete/devices 与三个写端点刻意
不收 company_id,由两支 SourceScan 用例钉住。
2026-10-05 17:20:57 +08:00

142 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { http } from './http'
import { unwrap } from './envelope'
/** 日志文件行(桌面客户端 / 麦象采集机上报)。 */
export interface DeviceLogFileRow {
id: number
source: string
deviceId: string
deviceName: string | null
username: string | null
uid: number | null
fileName: string
logDate: string
uploadedBytes: number
partCount: number
lastUploadAt: string | null
createdAt: string | null
}
export interface DeviceLogPage {
items: DeviceLogFileRow[]
total: number
page: number
pageSize: number
/** 云端日志保留天数(页面提示用)。 */
retentionDays: number
}
export interface DeviceLogContent {
fileId: number
fileName: string
content: string
totalBytes: number
shownBytes: number
truncated: boolean
}
export interface DeviceLogDevice {
source: string
deviceId: string
deviceName: string | null
lastUploadAt: string | null
}
export interface DeviceLogOverride {
id: number
source: string
deviceId: string
deviceName: string | null
mode: string
updatedAt: string | null
}
export interface DeviceLogConfigData {
globalMode: string
overrides: DeviceLogOverride[]
}
export interface DeviceLogQuery {
source?: string
/** 指定用户(users.id);不传=全部上报者,含 uid 为空的采集机与未登录客户端。 */
uid?: number
startDate?: string
endDate?: string
page: number
pageSize: number
/** 超管选中的公司 tab;null/undefined=不发这个参数,后端按「不筛」出全量(非超管恒不发)。 */
companyId?: number | null
}
/** 分页查询日志文件列表:GET /api/admin/device-logs/files */
export async function fetchDeviceLogFiles(params: DeviceLogQuery): Promise<DeviceLogPage> {
const query: Record<string, string | number> = { page: params.page, pageSize: params.pageSize }
if (params.source) query.source = params.source
if (params.uid) query.uid = params.uid
if (params.startDate) query.startDate = params.startDate
if (params.endDate) query.endDate = params.endDate
// 公司值由页面组件(companyTab.requestCompanyId)传进来,本模块不读 Pinia store。
// query 是这里逐字段点名的白名单构造 ⇒ 右半边只许取原始 params。
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get('/api/admin/device-logs/files', { params: query })
return unwrap<DeviceLogPage>(data)
}
/** 查看日志尾部内容:GET /api/admin/device-logs/content */
export async function fetchDeviceLogContent(fileId: number, maxBytes?: number): Promise<DeviceLogContent> {
const query: Record<string, number> = { fileId }
if (maxBytes) query.maxBytes = maxBytes
const { data } = await http.get('/api/admin/device-logs/content', { params: query })
return unwrap<DeviceLogContent>(data)
}
/** 完整日志下载地址(同域 cookie 鉴权,直接给 a[href] 或 window.open 用)。 */
export function deviceLogDownloadUrl(fileId: number): string {
return `/api/admin/device-logs/download?fileId=${fileId}`
}
/** 删除日志文件(片段与元数据,不可恢复):DELETE /api/admin/device-logs/{id} */
export async function deleteDeviceLogFile(id: number): Promise<void> {
const { data } = await http.delete(`/api/admin/device-logs/${id}`)
unwrap<unknown>(data)
}
/** 采集配置(全局默认 + 终端覆盖):GET /api/admin/device-logs/config */
export async function fetchDeviceLogConfig(keyword?: string): Promise<DeviceLogConfigData> {
const { data } = await http.get('/api/admin/device-logs/config', {
params: keyword ? { keyword } : undefined,
})
return unwrap<DeviceLogConfigData>(data)
}
/** 最近上报过的终端(覆盖选择用):GET /api/admin/device-logs/devices */
export async function fetchDeviceLogDevices(): Promise<DeviceLogDevice[]> {
const { data } = await http.get('/api/admin/device-logs/devices')
return unwrap<DeviceLogDevice[]>(data)
}
/** 设置全局采集模式:PUT /api/admin/device-logs/config/global */
export async function updateDeviceLogGlobalMode(mode: string): Promise<void> {
const { data } = await http.put('/api/admin/device-logs/config/global', undefined, { params: { mode } })
unwrap<unknown>(data)
}
/** 设置/更新终端覆盖:PUT /api/admin/device-logs/config/device */
export async function updateDeviceLogOverride(
source: string,
deviceId: string,
deviceName: string | null,
mode: string,
): Promise<void> {
const { data } = await http.put('/api/admin/device-logs/config/device', undefined, {
params: { source, deviceId, deviceName: deviceName || undefined, mode },
})
unwrap<unknown>(data)
}
/** 删除终端覆盖(回落到全局默认):DELETE /api/admin/device-logs/config/device/{id} */
export async function deleteDeviceLogOverride(id: number): Promise<void> {
const { data } = await http.delete(`/api/admin/device-logs/config/device/${id}`)
unwrap<unknown>(data)
}