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:
@@ -1,6 +1,10 @@
|
||||
package cn.novalon.manage.db.entity;
|
||||
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
|
||||
@@ -17,15 +21,19 @@ public abstract class BaseEntity implements Persistable<Long> {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@CreatedBy
|
||||
@Column("create_by")
|
||||
private String createBy;
|
||||
|
||||
@LastModifiedBy
|
||||
@Column("update_by")
|
||||
private String updateBy;
|
||||
|
||||
@CreatedDate
|
||||
@Column("created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column("updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
|
||||
+4
@@ -5,6 +5,8 @@ import cn.novalon.manage.sys.audit.repository.IAuditLogRepository;
|
||||
import cn.novalon.manage.db.converter.AuditLogConverter;
|
||||
import cn.novalon.manage.db.dao.AuditLogDao;
|
||||
import cn.novalon.manage.db.entity.AuditLogEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -20,6 +22,8 @@ import java.time.LocalDateTime;
|
||||
@Repository
|
||||
public class AuditLogRepository implements IAuditLogRepository {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuditLogRepository.class);
|
||||
|
||||
private final AuditLogDao auditLogDao;
|
||||
private final AuditLogConverter auditLogConverter;
|
||||
|
||||
|
||||
+7
-8
@@ -1,7 +1,6 @@
|
||||
-- Novalon管理系统审计日志表
|
||||
-- 版本: V7
|
||||
-- 描述: 创建审计日志表,记录数据变更前后的完整对比
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_log (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
entity_type VARCHAR(100) NOT NULL,
|
||||
@@ -11,20 +10,22 @@ CREATE TABLE IF NOT EXISTS audit_log (
|
||||
operation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
before_data JSONB,
|
||||
after_data JSONB,
|
||||
changed_fields TEXT[],
|
||||
changed_fields TEXT [],
|
||||
ip_address VARCHAR(50),
|
||||
user_agent TEXT,
|
||||
description TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
create_by VARCHAR(50),
|
||||
update_by VARCHAR(50),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_audit_log_entity_type ON audit_log(entity_type);
|
||||
CREATE INDEX idx_audit_log_entity_id ON audit_log(entity_id);
|
||||
CREATE INDEX idx_audit_log_operation_type ON audit_log(operation_type);
|
||||
CREATE INDEX idx_audit_log_operator ON audit_log(operator);
|
||||
CREATE INDEX idx_audit_log_operation_time ON audit_log(operation_time);
|
||||
CREATE INDEX idx_audit_log_entity ON audit_log(entity_type, entity_id);
|
||||
|
||||
COMMENT ON TABLE audit_log IS '审计日志表';
|
||||
COMMENT ON COLUMN audit_log.id IS '主键ID';
|
||||
COMMENT ON COLUMN audit_log.entity_type IS '实体类型(如User, Role等)';
|
||||
@@ -35,7 +36,5 @@ COMMENT ON COLUMN audit_log.operation_time IS '操作时间';
|
||||
COMMENT ON COLUMN audit_log.before_data IS '变更前数据(JSON格式)';
|
||||
COMMENT ON COLUMN audit_log.after_data IS '变更后数据(JSON格式)';
|
||||
COMMENT ON COLUMN audit_log.changed_fields IS '变更字段列表';
|
||||
COMMENT ON COLUMN audit_log.ip_address IS 'IP地址';
|
||||
COMMENT ON COLUMN audit_log.user_agent IS '用户代理';
|
||||
COMMENT ON COLUMN audit_log.description IS '操作描述';
|
||||
COMMENT ON COLUMN audit_log.ip_address IS 'IP地址';COMMENT ON COLUMN audit_log.description IS '操作描述';
|
||||
COMMENT ON COLUMN audit_log.created_at IS '记录创建时间';
|
||||
|
||||
Reference in New Issue
Block a user