feat(web): 优化级联查询中的逻辑删除
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
package com.eshore.gringotts.web.domain.authentication.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
@@ -25,6 +23,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
@@ -50,43 +49,14 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class Authentication extends SimpleEntity {
|
||||
public class Authentication extends CheckingNeededEntity {
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private DataResource target;
|
||||
private String description;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private Set<DataFile> evidences;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 无确权
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT,
|
||||
/**
|
||||
* 属主审查中
|
||||
*/
|
||||
OWNER_CHECKING,
|
||||
/**
|
||||
* 审查中
|
||||
*/
|
||||
CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* 驳回
|
||||
*/
|
||||
REJECT,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class CheckingNeededEntity extends LogicDeleteEntity {
|
||||
private String description;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 无确权
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT,
|
||||
/**
|
||||
* 审查中
|
||||
*/
|
||||
CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* 驳回
|
||||
*/
|
||||
REJECT,
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class DatetimeOnlyEntity extends IdOnlyEntity {
|
||||
@CreatedDate
|
||||
private LocalDateTime createdTime;
|
||||
@LastModifiedDate
|
||||
private LocalDateTime modifiedTime;
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
@@ -27,7 +25,6 @@ import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
@@ -55,40 +52,14 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
})
|
||||
@SQLDelete(sql = "update " + Constants.TABLE_PREFIX + "confirmation" + " set deleted = true where id = ?")
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
public class Confirmation extends LogicDeleteEntity {
|
||||
public class Confirmation extends CheckingNeededEntity {
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@WhereJoinTable(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private DataResource target;
|
||||
private String description;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private Set<DataFile> evidences;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 无确权
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT,
|
||||
/**
|
||||
* 审查中
|
||||
*/
|
||||
CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* 驳回
|
||||
*/
|
||||
REJECT,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,19 +59,24 @@ public class DataResource extends LogicDeleteEntity {
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private ResourceType type;
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private ResourceFormat format;
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private DataFile example;
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private Confirmation confirmation;
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
|
||||
@ToString.Exclude
|
||||
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
|
||||
private Set<Authentication> authentications;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user