refactor(审计日志): 重构审计日志模块,修复SQL插入错误
问题分析:AuditLog领域对象直接继承R2dbcRepository导致SQL插入时缺少entity_id字段 解决方案:参考OperationLog实现模式,新增Entity/Dao/Converter/Repository分层 测试验证:后端启动成功,调试测试通过
This commit is contained in:
+2
-40
@@ -1,9 +1,7 @@
|
||||
package cn.novalon.manage.sys.audit.domain;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.BaseDomain;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -13,75 +11,47 @@ import java.time.LocalDateTime;
|
||||
* @author 张翔
|
||||
* @date 2026-04-01
|
||||
*/
|
||||
@Table("audit_log")
|
||||
@Schema(description = "审计日志实体")
|
||||
public class AuditLog {
|
||||
public class AuditLog extends BaseDomain {
|
||||
|
||||
@Id
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
@Column("entity_type")
|
||||
@Schema(description = "实体类型(如User, Role等)", example = "User")
|
||||
private String entityType;
|
||||
|
||||
@Column("entity_id")
|
||||
@Schema(description = "实体ID", example = "1")
|
||||
private Long entityId;
|
||||
|
||||
@Column("operation_type")
|
||||
@Schema(description = "操作类型(CREATE, UPDATE, DELETE)", example = "UPDATE")
|
||||
private String operationType;
|
||||
|
||||
@Column("operator")
|
||||
@Schema(description = "操作人", example = "admin")
|
||||
private String operator;
|
||||
|
||||
@Column("operation_time")
|
||||
@Schema(description = "操作时间")
|
||||
private LocalDateTime operationTime;
|
||||
|
||||
@Column("before_data")
|
||||
@Schema(description = "变更前数据(JSON格式)")
|
||||
private String beforeData;
|
||||
|
||||
@Column("after_data")
|
||||
@Schema(description = "变更后数据(JSON格式)")
|
||||
private String afterData;
|
||||
|
||||
@Column("changed_fields")
|
||||
@Schema(description = "变更字段列表")
|
||||
private String[] changedFields;
|
||||
|
||||
@Column("ip_address")
|
||||
@Schema(description = "IP地址", example = "192.168.1.100")
|
||||
private String ipAddress;
|
||||
|
||||
@Column("user_agent")
|
||||
@Schema(description = "用户代理")
|
||||
private String userAgent;
|
||||
|
||||
@Column("description")
|
||||
@Schema(description = "操作描述", example = "更新用户信息")
|
||||
private String description;
|
||||
|
||||
@Column("created_at")
|
||||
@Schema(description = "记录创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public AuditLog() {
|
||||
this.operationTime = LocalDateTime.now();
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
@@ -169,12 +139,4 @@ public class AuditLog {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -1,8 +1,6 @@
|
||||
package cn.novalon.manage.sys.audit.repository;
|
||||
|
||||
import cn.novalon.manage.sys.audit.domain.AuditLog;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -14,8 +12,15 @@ import java.time.LocalDateTime;
|
||||
* @author 张翔
|
||||
* @date 2026-04-01
|
||||
*/
|
||||
@Repository
|
||||
public interface IAuditLogRepository extends R2dbcRepository<AuditLog, Long> {
|
||||
public interface IAuditLogRepository {
|
||||
|
||||
Mono<AuditLog> findById(Long id);
|
||||
|
||||
Mono<AuditLog> save(AuditLog auditLog);
|
||||
|
||||
Mono<Void> deleteById(Long id);
|
||||
|
||||
Flux<AuditLog> findAll();
|
||||
|
||||
Flux<AuditLog> findByEntityType(String entityType);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user