package com.rongyichuang.common.entity; import jakarta.persistence.*; import org.hibernate.annotations.Where; import java.time.LocalDateTime; /** * 基础实体类 */ @MappedSuperclass @Where(clause = "state = 1") public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; /** * 状态:1-正常,0-删除 */ @Column(name = "state", nullable = false) private Integer state = 1; /** * 创建时间 */ @Column(name = "create_time", nullable = false, updatable = false) private LocalDateTime createTime; /** * 更新时间 */ @Column(name = "update_time") private LocalDateTime updateTime; @PrePersist protected void onCreate() { createTime = LocalDateTime.now(); updateTime = LocalDateTime.now(); if (state == null) { state = 1; } } @PreUpdate protected void onUpdate() { updateTime = LocalDateTime.now(); } // Getters and Setters public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Integer getState() { return state; } public void setState(Integer state) { this.state = state; } public LocalDateTime getCreateTime() { return createTime; } public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; } public LocalDateTime getUpdateTime() { return updateTime; } public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; } }