package com.rongyichuang.region.entity; import jakarta.persistence.*; import java.time.LocalDateTime; @Entity @Table(name = "t_region") public class Region { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "pid") private Long pid; @Column(name = "name", nullable = false, length = 100) private String name; @Column(name = "code", length = 50) private String code; @Column(name = "level") private Integer level; @Column(name = "leaf_flag") private Boolean leafFlag; @Column(name = "full_path", length = 500) private String fullPath; @Column(name = "state") 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 Region() {} public Region(String name, Long pid, Integer level, Boolean leafFlag, Integer state) { this.name = name; this.pid = pid; this.level = level; this.leafFlag = leafFlag; 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 Long getPid() { return pid; } public void setPid(Long pid) { this.pid = pid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public Integer getLevel() { return level; } public void setLevel(Integer level) { this.level = level; } public Boolean getLeafFlag() { return leafFlag; } public void setLeafFlag(Boolean leafFlag) { this.leafFlag = leafFlag; } public String getFullPath() { return fullPath; } public void setFullPath(String fullPath) { this.fullPath = fullPath; } 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() { createTime = LocalDateTime.now(); updateTime = LocalDateTime.now(); if (version == null) { version = 0L; } } @PreUpdate protected void onUpdate() { updateTime = LocalDateTime.now(); } }