refactor(审计日志): 优化审计日志架构和 E2E 测试质量

架构改进:
- 引入审计日志服务层,实现业务逻辑与数据访问分离
- 添加 Spring Data 审计注解,自动填充创建人、创建时间等字段
- 修复切面范围,避免 Repository 和 Dao 层重复记录

代码优化:
- 移除构造函数中的冗余 info 日志,降低生产环境日志量
- 恢复 SQL 文件格式,提高可读性
- 优化 E2E 测试等待策略,移除硬编码等待时间,提高测试稳定性

影响范围:
- 后端:审计日志模块(Service、Repository、Aspect、Entity)
- 前端:E2E 测试文件(4 个 workflow 测试)
- 数据库:审计日志表结构
This commit was merged in pull request #2.
This commit is contained in:
张翔
2026-04-08 19:49:55 +08:00
parent 7e534f3049
commit 7e54d7fb46
16 changed files with 766 additions and 252 deletions
@@ -3,24 +3,24 @@ import { Page, Locator, expect } from '@playwright/test';
export class DictionaryManagementPage {
readonly page: Page;
readonly table: Locator;
readonly createDictTypeButton: Locator;
readonly createDictDataButton: Locator;
readonly searchInput: Locator;
readonly searchButton: Locator;
readonly successMessage: Locator;
readonly dictTypeTable: Locator;
readonly dictDataTable: Locator;
readonly createDictButton: Locator;
readonly saveButton: Locator;
readonly dialog: Locator;
readonly dictNameInput: Locator;
readonly dictTypeInput: Locator;
readonly statusSelect: Locator;
readonly remarkInput: Locator;
constructor(page: Page) {
this.page = page;
this.table = page.locator('.el-table').or(page.locator('.dict-table'));
this.createDictTypeButton = page.getByRole('button', { name: '新增字典类型' }).or(page.locator('button:has-text("新增字典类型")'));
this.createDictDataButton = page.getByRole('button', { name: '新增字典数据' }).or(page.locator('button:has-text("新增字典数据")'));
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
this.dictTypeTable = page.locator('.dict-type-table').or(page.locator('.el-table').first());
this.dictDataTable = page.locator('.dict-data-table').or(page.locator('.el-table').nth(1));
this.table = page.locator('.el-table');
this.createDictButton = page.getByRole('button', { name: '新增字典' });
this.saveButton = page.getByRole('button', { name: '确定' });
this.dialog = page.locator('.el-dialog');
this.dictNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典名称' });
this.dictTypeInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典类型' });
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
this.remarkInput = page.locator('.el-dialog').getByRole('textbox', { name: '备注' });
}
async goto() {
@@ -40,156 +40,57 @@ export class DictionaryManagementPage {
}
}
async clickCreateDictType() {
await this.createDictTypeButton.click();
async createDict(dictName: string, dictType: string, status: string = '0', remark?: string) {
await this.createDictButton.click();
await this.page.waitForTimeout(500);
await this.dictNameInput.fill(dictName);
await this.dictTypeInput.fill(dictType);
if (status) {
await this.statusSelect.click();
await this.page.waitForTimeout(300);
await this.page.getByRole('option', { name: status === '0' ? '正常' : '停用' }).click();
}
if (remark) {
await this.remarkInput.fill(remark);
}
await this.saveButton.click();
await this.page.waitForLoadState('networkidle');
}
async clickCreateDictData() {
await this.createDictDataButton.click();
async editDict(dictName: string, newDictName: string) {
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
const editBtn = row.getByRole('button', { name: '编辑' });
await editBtn.click();
await this.page.waitForTimeout(500);
await this.dictNameInput.clear();
await this.dictNameInput.fill(newDictName);
await this.saveButton.click();
await this.page.waitForLoadState('networkidle');
}
async fillDictTypeForm(dictTypeData: {
dictName: string;
dictType: string;
status?: string;
remark?: string;
}) {
const dialog = this.page.locator('.el-dialog');
async deleteDict(dictName: string) {
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
const deleteBtn = row.getByRole('button', { name: '删除' });
await deleteBtn.click();
await this.page.waitForTimeout(500);
await dialog.locator('input').first().fill(dictTypeData.dictName);
await dialog.locator('input').nth(1).fill(dictTypeData.dictType);
if (dictTypeData.status) {
const statusRadio = dialog.locator(`input[value="${dictTypeData.status}"]`);
if (await statusRadio.count() > 0) {
await statusRadio.check();
}
}
if (dictTypeData.remark) {
const remarkInput = dialog.locator('textarea');
if (await remarkInput.count() > 0) {
await remarkInput.fill(dictTypeData.remark);
}
}
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
await confirmBtn.click();
await this.page.waitForLoadState('networkidle');
}
async fillDictDataForm(dictData: {
dictLabel: string;
dictValue: string;
dictType?: string;
cssClass?: string;
listClass?: string;
isDefault?: string;
status?: string;
sort?: number;
}) {
const dialog = this.page.locator('.el-dialog');
await dialog.locator('input').first().fill(dictData.dictLabel);
await dialog.locator('input').nth(1).fill(dictData.dictValue);
if (dictData.dictType) {
const dictTypeSelect = dialog.locator('.el-select');
if (await dictTypeSelect.count() > 0) {
await dictTypeSelect.click();
await this.page.waitForTimeout(300);
await this.page.getByRole('option', { name: dictData.dictType }).click();
}
}
if (dictData.cssClass) {
const cssClassInput = dialog.locator('input[placeholder*="CSS"]');
if (await cssClassInput.count() > 0) {
await cssClassInput.fill(dictData.cssClass);
}
}
if (dictData.listClass) {
const listClassInput = dialog.locator('input[placeholder*="列表"]');
if (await listClassInput.count() > 0) {
await listClassInput.fill(dictData.listClass);
}
}
if (dictData.isDefault) {
const defaultRadio = dialog.locator(`input[value="${dictData.isDefault}"]`);
if (await defaultRadio.count() > 0) {
await defaultRadio.check();
}
}
if (dictData.status) {
const statusRadio = dialog.locator(`input[value="${dictData.status}"]`);
if (await statusRadio.count() > 0) {
await statusRadio.check();
}
}
if (dictData.sort !== undefined) {
const sortInput = dialog.locator('input[type="number"]');
if (await sortInput.count() > 0) {
await sortInput.fill(String(dictData.sort));
}
}
}
async submitForm() {
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('button:has-text("确定")')).click();
}
async editDictType(dictName: string) {
const dictTypeRow = this.dictTypeTable.locator('tbody tr').filter({ hasText: dictName });
await dictTypeRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
}
async editDictData(dictLabel: string) {
const dictDataRow = this.dictDataTable.locator('tbody tr').filter({ hasText: dictLabel });
await dictDataRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
}
async deleteDictType(dictName: string) {
const dictTypeRow = this.dictTypeTable.locator('tbody tr').filter({ hasText: dictName });
await dictTypeRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
}
async deleteDictData(dictLabel: string) {
const dictDataRow = this.dictDataTable.locator('tbody tr').filter({ hasText: dictLabel });
await dictDataRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
}
async confirmDelete() {
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
async getDictCount() {
const rows = await this.table.locator('.el-table__row').count();
return rows;
}
async containsText(text: string): Promise<boolean> {
return await this.table.getByText(text).count() > 0;
}
async isSuccessMessageVisible(): Promise<boolean> {
try {
return await this.successMessage.isVisible({ timeout: 3000 });
} catch {
return false;
}
}
async getDictTypeCount(): Promise<number> {
return await this.dictTypeTable.locator('tbody tr').count();
}
async getDictDataCount(): Promise<number> {
return await this.dictDataTable.locator('tbody tr').count();
}
async reload() {
await this.page.reload();
}
}