Skip to content

Commit

Permalink
feat: 表关系修改
Browse files Browse the repository at this point in the history
  • Loading branch information
lichong-a committed Sep 16, 2024
1 parent 43efab5 commit 19f2bd5
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
Expand All @@ -27,7 +30,6 @@
*/
@Getter
@Setter
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@MappedSuperclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.funcode.portal.server.common.domain.base.BaseEntity;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;

import java.util.Objects;

/**
* @author 李冲
Expand All @@ -25,7 +28,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id", "title"})
@ToString(callSuper = true)
@Table(name = "tb_carousel")
@Comment("轮播管理表")
Expand All @@ -52,10 +54,26 @@ public class Carousel extends BaseEntity {
@Schema(description = "标题")
private String title;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "storage_id", referencedColumnName = "id")
@Comment("图片文件")
@Schema(description = "图片文件")
private Storage storage;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
Course course = (Course) o;
return getId() != null && Objects.equals(getId(), course.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.funcode.portal.server.common.domain.security.User;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -30,7 +32,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id", "title", "status", "price"})
@ToString(callSuper = true)
@Table(name = "tb_course")
@Comment("课程管理表")
Expand Down Expand Up @@ -61,29 +62,35 @@ public class Course extends BaseEntity {
@Schema(description = "课程价格")
private BigDecimal price;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "course_description_storage_id", referencedColumnName = "id")
@Comment("课程简介文件")
@Schema(description = "课程简介文件")
private Storage courseDescriptionStorage;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "course_media_storage_id", referencedColumnName = "id")
@Comment("课程音视频文件")
@Schema(description = "课程音视频文件")
private Storage courseMediaStorage;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "course_cover_storage_id", referencedColumnName = "id")
@Comment("课程封面文件")
@Schema(description = "课程封面文件")
private Storage courseCoverStorage;

@OneToMany(mappedBy = "attachmentCourse")
@ManyToMany
@JoinTable(
name = "tb_course_course_attachment_storages",
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "storage_id"))
@ToString.Exclude
private Set<Storage> courseAttachmentStorages;

@ManyToMany(mappedBy = "courses")
@JsonIgnore
@ToString.Exclude
private Set<CourseColumn> courseColumns;

@ManyToMany
Expand All @@ -92,6 +99,7 @@ public class Course extends BaseEntity {
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "order_id"))
@JsonIgnore
@ToString.Exclude
private Set<Order> orders;

@ManyToMany
Expand All @@ -100,6 +108,7 @@ public class Course extends BaseEntity {
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "redeem_code_id"))
@JsonIgnore
@ToString.Exclude
private Set<RedeemCode> redeemCodes;

@ManyToMany
Expand All @@ -108,6 +117,22 @@ public class Course extends BaseEntity {
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
@JsonIgnore
@ToString.Exclude
private Set<User> users;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
Course course = (Course) o;
return getId() != null && Objects.equals(getId(), course.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.funcode.portal.server.common.domain.security.User;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -30,7 +32,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id", "title", "status", "price"})
@ToString(callSuper = true)
@Table(name = "tb_course_column")
@Comment("课程专栏管理表")
Expand Down Expand Up @@ -61,19 +62,19 @@ public class CourseColumn extends BaseEntity {
@Schema(description = "课程专栏价格")
private BigDecimal price;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "course_column_description_storage_id", referencedColumnName = "id")
@Comment("课程专栏简介文件")
@Schema(description = "课程专栏简介文件")
private Storage courseColumnDescriptionStorage;

@OneToOne
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "course_column_cover_storage_id", referencedColumnName = "id")
@Comment("课程专栏封面文件")
@Schema(description = "课程专栏封面文件")
private Storage courseColumnCoverStorage;

@ManyToMany
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_course_course_column",
joinColumns = @JoinColumn(name = "course_column_id"),
Expand All @@ -86,6 +87,7 @@ public class CourseColumn extends BaseEntity {
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "order_id"))
@JsonIgnore
@ToString.Exclude
private Set<Order> orders;

@ManyToMany
Expand All @@ -94,6 +96,7 @@ public class CourseColumn extends BaseEntity {
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "redeem_code_id"))
@JsonIgnore
@ToString.Exclude
private Set<RedeemCode> redeemCodes;

@ManyToMany
Expand All @@ -102,6 +105,22 @@ public class CourseColumn extends BaseEntity {
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
@JsonIgnore
@ToString.Exclude
private Set<User> users;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
CourseColumn that = (CourseColumn) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.funcode.portal.server.common.domain.security.User;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -35,7 +37,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id", "tradeType", "paymentTime", "price"})
@ToString(callSuper = true)
@Table(name = "tb_order")
@Comment("订单管理表")
Expand Down Expand Up @@ -76,10 +77,25 @@ public class Order extends BaseEntity {
@Schema(description = "人员")
private User user;

@ManyToMany(mappedBy = "orders")
@ManyToMany(mappedBy = "orders", fetch = FetchType.EAGER)
private Set<Course> courses;

@ManyToMany(mappedBy = "orders")
@ManyToMany(mappedBy = "orders", fetch = FetchType.EAGER)
private Set<CourseColumn> courseColumns;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
Order order = (Order) o;
return getId() != null && Objects.equals(getId(), order.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.funcode.portal.server.common.domain.security.User;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;

import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -34,7 +36,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id", "code"})
@ToString(callSuper = true)
@Table(name = "tb_redeem_code")
@Comment("兑换码管理表")
Expand Down Expand Up @@ -78,10 +79,10 @@ public class RedeemCode extends BaseEntity {
@Schema(description = "兑换时间")
private LocalDateTime redeemTime;

@ManyToMany(mappedBy = "redeemCodes")
@ManyToMany(mappedBy = "redeemCodes", fetch = FetchType.EAGER)
private Set<Course> courses;

@ManyToMany(mappedBy = "redeemCodes")
@ManyToMany(mappedBy = "redeemCodes", fetch = FetchType.EAGER)
private Set<CourseColumn> courseColumns;

@ManyToOne
Expand All @@ -90,4 +91,19 @@ public class RedeemCode extends BaseEntity {
@Schema(description = "兑换人")
private User user;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
RedeemCode that = (RedeemCode) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Loading

0 comments on commit 19f2bd5

Please sign in to comment.