审计导出功能--初版

This commit is contained in:
Cheng Zhou
2025-12-17 21:55:38 +08:00
parent 4202ed7922
commit 4aa968f27c
9 changed files with 228 additions and 24 deletions
@@ -0,0 +1,55 @@
import { getDictLabel, statusDict } from "../../dictionaries";
import type { AuditEvent } from "..";
import { auditExportColumns } from "./auditExportColumns";
export interface AuditExportRow {
[key: string]: string;
}
const extractStatusLabel = (obj?: Record<string, any>) => {
if (!obj) return "";
if (obj.status) return getDictLabel(statusDict, obj.status) || obj.status;
return "";
};
export const formatAuditRow = (event: AuditEvent): AuditExportRow => {
const beforeStatus = extractStatusLabel(event.before);
const afterStatus = extractStatusLabel(event.after);
const descriptionParts: string[] = [];
descriptionParts.push(`${event.actorName} ${event.actionText}`);
if (event.targetTypeLabel || event.targetName || event.targetId) {
descriptionParts.push(
`对象:${event.targetTypeLabel || ""}${event.targetName ? `${event.targetName}` : `${event.targetId}`})`
);
}
if (event.diffText?.length) {
descriptionParts.push(`变更:${event.diffText.join("")}`);
}
return {
timestamp: event.timestamp || "",
actorName: event.actorName || "",
actorId: event.actorId || "",
actorRoleLabel: event.actorRoleLabel || "",
eventLabel: event.eventLabel || "",
targetTypeLabel: event.targetTypeLabel || "",
targetIdentifier: event.targetName || event.targetId || "",
description: descriptionParts.join(""),
beforeStatus,
afterStatus,
resultLabel: event.resultLabel || "",
reason: event.reason || "",
ip: "",
remark: event.diffText?.join("") || "",
};
};
export const formatAuditRows = (events: AuditEvent[]): AuditExportRow[] => {
return events.map((ev) => formatAuditRow(ev)).map((row) => {
const ordered: AuditExportRow = {};
auditExportColumns.forEach((col) => {
ordered[col.key] = row[col.key] ?? "";
});
return ordered;
});
};