package com.rongyichuang.role.entity; import jakarta.persistence.*; import java.time.LocalDateTime; @Entity @Table(name = "t_role") public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "code", nullable = false, length = 64) private String code; @Column(name = "name", nullable = false, length = 128) private String name; @Column(name = "description", length = 255) private String description; @Column(name = "state", nullable = false) private Integer state; @Column(name = "create_time") private LocalDateTime createTime; @Column(name = "create_user_id") private Long createUserId; @Column(name = "update_time") private LocalDateTime updateTime; @Column(name = "update_user_id") private Long updateUserId; @Version @Column(name = "version") private Long version; // 构造函数 public Role() {} public Role(String code, String name, String description, Integer state) { this.code = code; this.name = name; this.description = description; this.state = state; this.createTime = LocalDateTime.now(); this.updateTime = LocalDateTime.now(); this.version = 0L; } // Getter和Setter方法 public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } 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 Long getCreateUserId() { return createUserId; } public void setCreateUserId(Long createUserId) { this.createUserId = createUserId; } public LocalDateTime getUpdateTime() { return updateTime; } public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; } public Long getUpdateUserId() { return updateUserId; } public void setUpdateUserId(Long updateUserId) { this.updateUserId = updateUserId; } public Long getVersion() { return version; } public void setVersion(Long version) { this.version = version; } @PrePersist protected void onCreate() { if (createTime == null) { createTime = LocalDateTime.now(); } if (updateTime == null) { updateTime = LocalDateTime.now(); } } @PreUpdate protected void onUpdate() { updateTime = LocalDateTime.now(); } }