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