lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
    }
}