mirror of https://github.com/halo-dev/halo
Refactor entities
parent
fc2349314d
commit
5548d18875
|
@ -1,12 +1,13 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Attachment entity
|
||||
|
@ -19,10 +20,12 @@ import java.util.Date;
|
|||
@Table(name = "attachments")
|
||||
@SQLDelete(sql = "update attachments set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class Attachment {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Attachment extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -74,35 +77,10 @@ public class Attachment {
|
|||
@Column(name = "type", columnDefinition = "int default 0")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Base entity.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/20/19
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class BaseEntity {
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted = false;
|
||||
|
||||
@PrePersist
|
||||
protected void prePersist() {
|
||||
deleted = false;
|
||||
Date now = DateUtils.now();
|
||||
createTime = now;
|
||||
updateTime = now;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void preUpdate() {
|
||||
updateTime = new Date();
|
||||
}
|
||||
|
||||
@PreRemove
|
||||
protected void preRemove() {
|
||||
updateTime = new Date();
|
||||
}
|
||||
|
||||
}
|
|
@ -21,11 +21,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Category {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Category extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
|
@ -52,35 +52,10 @@ public class Category {
|
|||
@Column(name = "parent_id", columnDefinition = "int default 0")
|
||||
private Integer parentId;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Comment {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Comment extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class Comment {
|
|||
/**
|
||||
* 评论者网址
|
||||
*/
|
||||
@Column(name = "author_url",columnDefinition = "varchar(512) default ''")
|
||||
@Column(name = "author_url", columnDefinition = "varchar(512) default ''")
|
||||
private String authorUrl;
|
||||
|
||||
/**
|
||||
|
@ -95,35 +95,10 @@ public class Comment {
|
|||
@Column(name = "parent_id", columnDefinition = "bigint default 0")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.model.entity;
|
|||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
|
@ -19,10 +21,12 @@ import java.util.Date;
|
|||
@Table(name = "galleries")
|
||||
@SQLDelete(sql = "update galleries set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class Gallery {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Gallery extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -63,35 +67,9 @@ public class Gallery {
|
|||
@Column(name = "url", columnDefinition = "varchar(1023) not null")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.model.entity;
|
|||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
|
@ -19,10 +21,12 @@ import java.util.Date;
|
|||
@Table(name = "links")
|
||||
@SQLDelete(sql = "update links set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class Link {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Link extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -56,35 +60,10 @@ public class Link {
|
|||
@Column(name = "group", columnDefinition = "varchar(255) default ''")
|
||||
private String group;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Log {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Log extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
@ -54,35 +54,10 @@ public class Log {
|
|||
@Column(name = "ip_address", columnDefinition = "varchar(127) default ''")
|
||||
private String ipAddress;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.model.entity;
|
|||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
|
@ -19,10 +21,12 @@ import java.util.Date;
|
|||
@Table(name = "menus")
|
||||
@SQLDelete(sql = "update menus set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class Menu {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Menu extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -56,35 +60,10 @@ public class Menu {
|
|||
@Column(name = "icon", columnDefinition = "varchar(50) default ''")
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Option {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Option extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
|
@ -40,35 +40,9 @@ public class Option {
|
|||
@Column(name = "option_value", columnDefinition = "varchar(1023) not null")
|
||||
private String optionValue;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cc.ryanc.halo.model.entity;
|
|||
import cc.ryanc.halo.model.enums.PostCreateFrom;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -24,11 +23,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Post {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Post extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
|
@ -131,35 +130,10 @@ public class Post {
|
|||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date editTime;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ import java.util.Date;
|
|||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class PostCategory {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PostCategory extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
|
@ -40,35 +40,10 @@ public class PostCategory {
|
|||
@Column(name = "post_id")
|
||||
private Integer postId;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.model.entity;
|
|||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
|
@ -17,10 +19,12 @@ import java.util.Date;
|
|||
@Table(name = "post_tags")
|
||||
@SQLDelete(sql = "update post_tags set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class PostTag {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PostTag extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -36,35 +40,9 @@ public class PostTag {
|
|||
@Column(name = "tag_id", columnDefinition = "int not null")
|
||||
private Integer tagId;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
@ -16,13 +19,15 @@ import java.util.Date;
|
|||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "menus")
|
||||
@SQLDelete(sql = "update menus set deleted = true where id = ?")
|
||||
@Table(name = "tags")
|
||||
@SQLDelete(sql = "update tags set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class Tag {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Tag extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -38,35 +43,9 @@ public class Tag {
|
|||
@Column(name = "slug_name", columnDefinition = "varchar(255) not null")
|
||||
private String slugName;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
@Override
|
||||
protected void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.utils.DateUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
|
@ -19,10 +20,12 @@ import java.util.Date;
|
|||
@Table(name = "users")
|
||||
@SQLDelete(sql = "update users set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
public class User {
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class User extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
|
@ -69,35 +72,10 @@ public class User {
|
|||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间戳
|
||||
*/
|
||||
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||
private Boolean deleted;
|
||||
|
||||
@PrePersist
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
public void preUpdate() {
|
||||
if (updateTime == null) {
|
||||
updateTime = DateUtils.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue