You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
package com.mydreamjob.audit;
|
|
|
|
import jakarta.persistence.*;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Builder;
|
|
import lombok.Data;
|
|
import lombok.NoArgsConstructor;
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
/**
|
|
* 审计日志实体
|
|
*/
|
|
@Data
|
|
@Builder
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
@Entity
|
|
@Table(name = "audit_logs")
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
public class AuditLog {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(name = "user_id")
|
|
private Long userId;
|
|
|
|
@Column(name = "action", nullable = false, length = 50)
|
|
private String action;
|
|
|
|
@Column(name = "entity_type", length = 50)
|
|
private String entityType;
|
|
|
|
@Column(name = "entity_id")
|
|
private Long entityId;
|
|
|
|
@Column(name = "details", columnDefinition = "TEXT")
|
|
private String details;
|
|
|
|
@Column(name = "ip_address", length = 45)
|
|
private String ipAddress;
|
|
|
|
@Column(name = "user_agent", length = 500)
|
|
private String userAgent;
|
|
|
|
@Column(name = "request_id", length = 32)
|
|
private String requestId;
|
|
|
|
// S02:不再使用 @CreatedDate。
|
|
// Spring Data 审计会在持久化时用“当前时间”覆盖显式设置的值,而 S02 认证入口
|
|
// (登录/刷新/登出/重放处置/全局吊销)要求审计时间与入口单次捕获的 capturedNow 同源。
|
|
// 所有写入方(AuditService、SecurityAuditService)本就显式设置 createdAt,移除后行为不变。
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
|
private LocalDateTime createdAt;
|
|
}
|
|
|