Class AuditableDataEntity<ID extends Serializable>

Type Parameters:
ID - the type of the entity identifier
All Implemented Interfaces:
Serializable

public abstract class AuditableDataEntity<ID extends Serializable> extends BaseDataEntity<ID>
Data entity with audit fields for tracking creation and modification. Automatically manages audit timestamps and user information.

带有审计字段的数据实体,用于跟踪创建和修改。 自动管理审计时间戳和用户信息。

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • createdAt

      private LocalDateTime createdAt
    • updatedAt

      private LocalDateTime updatedAt
    • createdBy

      private UUID createdBy
    • updatedBy

      private UUID updatedBy
    • CURRENT_USER

      private static final ThreadLocal<UUID> CURRENT_USER
      Sets the current user context for audit purposes. Thread-local storage for the current operation's user.
  • Constructor Details

    • AuditableDataEntity

      public AuditableDataEntity()
  • Method Details

    • setCurrentUser

      public static void setCurrentUser(UUID userId)
      Sets the current user for audit tracking. Call this before performing data operations.

      设置用于审计跟踪的当前用户。 在执行数据操作之前调用此方法。

      Parameters:
      userId - the current user's UUID
    • clearCurrentUser

      public static void clearCurrentUser()
      Clears the current user context. Call this after completing data operations.

      清除当前用户上下文。 在完成数据操作后调用此方法。

    • getCurrentUser

      protected static UUID getCurrentUser()
      Gets the current user from the thread-local context. 从线程本地上下文获取当前用户。
      Returns:
      the current user's UUID, or null if not set
    • onCreate

      public void onCreate()
      Description copied from class: BaseDataEntity
      Called before the entity is persisted for the first time. Override to add custom pre-insert logic.

      在实体首次持久化之前调用。 重写以添加自定义预插入逻辑。

      Overrides:
      onCreate in class BaseDataEntity<ID extends Serializable>
    • onUpdate

      public void onUpdate()
      Description copied from class: BaseDataEntity
      Called before the entity is updated. Override to add custom pre-update logic.

      在实体更新之前调用。 重写以添加自定义预更新逻辑。

      Overrides:
      onUpdate in class BaseDataEntity<ID extends Serializable>
    • getAge

      public Duration getAge()
      Gets the age of this entity since creation. 获取此实体自创建以来的年龄。
      Returns:
      the duration since creation, or null if not persisted
    • getTimeSinceUpdate

      public Duration getTimeSinceUpdate()
      Gets the time since the last modification. 获取自上次修改以来的时间。
      Returns:
      the duration since last update, or null if not persisted
    • wasModified

      public boolean wasModified()
      Checks if this entity was modified after creation. 检查此实体是否在创建后被修改。
      Returns:
      true if modified after creation