Skip to content

Commit

Permalink
feat: 订单管理报错修改&新增索引
Browse files Browse the repository at this point in the history
  • Loading branch information
lichong-a committed Sep 22, 2024
1 parent 264d0be commit 4fd285b
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.funcode.portal.server.common.domain.ielts;


import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -33,7 +34,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_course")
@Table(name = "tb_course",
indexes = @Index(name = "index_tb_course_status", columnList = Course_.STATUS))
@Comment("课程管理表")
@Schema(description = "课程")
@DynamicUpdate
Expand All @@ -55,7 +57,7 @@ public class Course extends BaseEntity {
@Column(nullable = false)
@Comment("课程状态(0:已下架;1:已上架;2:下架并静止播放)")
@Schema(description = "课程状态(0:已下架;1:已上架;2:下架并静止播放)")
private int status;
private Integer status;

@Column
@Comment("课程价格")
Expand Down Expand Up @@ -89,33 +91,25 @@ public class Course extends BaseEntity {
private Set<Storage> courseAttachmentStorages;

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

@ManyToMany
@JoinTable(
name = "tb_order_course",
name = "tb_order_tb_course",
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "order_id"))
@JsonIgnore
@ToString.Exclude
@JsonBackReference
private Set<Order> orders;

@ManyToMany
@JoinTable(
name = "tb_redeem_code_course",
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "redeem_code_id"))
@ManyToMany(mappedBy = "courses")
@JsonIgnore
@ToString.Exclude
private Set<RedeemCode> redeemCodes;

@ManyToMany
@JoinTable(
name = "tb_user_course",
joinColumns = @JoinColumn(name = "course_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
@ManyToMany(mappedBy = "courses")
@JsonIgnore
@ToString.Exclude
private Set<User> users;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
package org.funcode.portal.server.common.domain.ielts;


import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -33,7 +35,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_course_column")
@Table(name = "tb_course_column",
indexes = @Index(name = "index_tb_course_column_status", columnList = CourseColumn_.STATUS))
@Comment("课程专栏管理表")
@Schema(description = "课程专栏")
@DynamicUpdate
Expand All @@ -55,7 +58,7 @@ public class CourseColumn extends BaseEntity {
@Column(nullable = false)
@Comment("专栏状态(0:已下架;1:已上架;2:下架并静止播放)")
@Schema(description = "专栏状态(0:已下架;1:已上架;2:下架并静止播放)")
private int status;
private Integer status;

@Column(nullable = false)
@Comment("课程专栏价格")
Expand All @@ -79,31 +82,25 @@ public class CourseColumn extends BaseEntity {
name = "tb_course_course_column",
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "course_id"))
@ToString.Exclude
@JsonManagedReference
private Set<Course> courses;

@ManyToMany
@JoinTable(
name = "tb_order_course_column",
name = "tb_order_tb_course_column",
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "order_id"))
@JsonIgnore
@ToString.Exclude
@JsonBackReference
private Set<Order> orders;

@ManyToMany
@JoinTable(
name = "tb_redeem_code_course_column",
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "redeem_code_id"))
@ManyToMany(mappedBy = "courseColumns")
@JsonIgnore
@ToString.Exclude
private Set<RedeemCode> redeemCodes;

@ManyToMany
@JoinTable(
name = "tb_user_course_column",
joinColumns = @JoinColumn(name = "course_column_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
@ManyToMany(mappedBy = "courseColumns")
@JsonIgnore
@ToString.Exclude
private Set<User> users;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
Expand Down Expand Up @@ -38,7 +39,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_order")
@Table(name = "tb_order",
indexes = @Index(name = "index_tb_order_user", columnList = "order_user_id"))
@Comment("订单管理表")
@Schema(description = "订单")
@DynamicUpdate
Expand All @@ -55,7 +57,7 @@ public class Order extends BaseEntity {
@Column(nullable = false)
@Comment("交易方式(0:兑换码;1:微信支付)")
@Schema(description = "交易方式(0:兑换码;1:微信支付)")
private int tradeType;
private Integer tradeType;

@Column
@Temporal(TemporalType.TIMESTAMP)
Expand All @@ -75,12 +77,23 @@ public class Order extends BaseEntity {
@JoinColumn(name = "order_user_id", referencedColumnName = "id")
@Comment("人员")
@Schema(description = "人员")
@JsonManagedReference
private User user;

@ManyToMany(mappedBy = "orders", fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_order_tb_course",
joinColumns = @JoinColumn(name = "order_id"),
inverseJoinColumns = @JoinColumn(name = "course_id"))
@JsonManagedReference
private Set<Course> courses;

@ManyToMany(mappedBy = "orders", fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_order_tb_course_column",
joinColumns = @JoinColumn(name = "order_id"),
inverseJoinColumns = @JoinColumn(name = "course_column_id"))
@JsonManagedReference
private Set<CourseColumn> courseColumns;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_redeem_code")
@Table(name = "tb_redeem_code",
indexes = @Index(name = "index_tb_redeem_code_code", columnList = RedeemCode_.CODE))
@Comment("兑换码管理表")
@Schema(description = "兑换码")
@DynamicUpdate
Expand Down Expand Up @@ -79,10 +80,18 @@ public class RedeemCode extends BaseEntity {
@Schema(description = "兑换时间")
private LocalDateTime redeemTime;

@ManyToMany(fetch = FetchType.EAGER, mappedBy = "redeemCodes")
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_redeem_code_course",
joinColumns = @JoinColumn(name = "redeem_code_id"),
inverseJoinColumns = @JoinColumn(name = "course_id"))
private Set<Course> courses;

@ManyToMany(fetch = FetchType.EAGER, mappedBy = "redeemCodes")
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_redeem_code_course_column",
joinColumns = @JoinColumn(name = "redeem_code_id"),
inverseJoinColumns = @JoinColumn(name = "course_column_id"))
private Set<CourseColumn> courseColumns;

@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_basic_authority")
@Table(name = "tb_basic_authority",
indexes = @Index(name = "index_tb_basic_authority_authority_key", columnList = BasicAuthority_.AUTHORITY_KEY))
@Comment("权限表")
@Schema(description = "权限")
@DynamicUpdate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
@Builder
@Entity
@ToString(callSuper = true)
@Table(name = "tb_role")
@Table(name = "tb_role",
indexes = @Index(name = "index_tb_role_role_key", columnList = Role_.ROLE_KEY))
@Comment("角色表")
@Schema(description = "角色")
@DynamicUpdate
Expand Down Expand Up @@ -65,7 +66,7 @@ public class Role extends BaseEntity implements GrantedAuthority {
name = "tb_role_basic_authority",
joinColumns = @JoinColumn(name = "role_id"),
inverseJoinColumns = @JoinColumn(name = "basic_authority_id"))
@JsonIgnore
@ToString.Exclude
private Set<BasicAuthority> basicAuthorities;

@ManyToMany(mappedBy = "roles")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.funcode.portal.server.common.domain.security;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -17,15 +18,13 @@
import org.funcode.portal.server.common.domain.ielts.RedeemCode;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.*;

/**
* @author 李冲
Expand All @@ -38,7 +37,6 @@
@NoArgsConstructor
@Builder
@Entity
@EqualsAndHashCode(callSuper = false, of = {"id"})
@ToString(callSuper = true)
@Table(name = "tb_user")
@Comment("人员表")
Expand Down Expand Up @@ -115,26 +113,37 @@ public class User extends BaseEntity implements UserDetails {
@Comment("是否启用")
@Schema(description = "是否启用")
private boolean enabled = true;
@ManyToMany(targetEntity = Role.class, fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "tb_user_role",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
@ToString.Exclude
private Set<Role> roles;

@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.EAGER)
@ToString.Exclude
@JsonBackReference
private Set<Order> orders;

@OneToMany(mappedBy = "user")
@JsonIgnore
@ToString.Exclude
private Set<RedeemCode> redeemCodes;

@ManyToMany(mappedBy = "users", fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_user_course_column",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "course_column_id"))
@ToString.Exclude
private Set<CourseColumn> courseColumns;

@ManyToMany(mappedBy = "users")
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "tb_user_course",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "course_id"))
@ToString.Exclude
private Set<Course> courses;

Expand All @@ -149,4 +158,19 @@ public Collection<? extends GrantedAuthority> getAuthorities() {
return result;
}

@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;
User user = (User) o;
return getId() != null && Objects.equals(getId(), user.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 @@ -73,9 +73,13 @@ public RedeemCode redeem(String code) {
currentUser.setCourseColumns(courseColumns);
userRepository.save(currentUser);
// 保存订单
Set<Course> orderCourses = new HashSet<>(courses.size());
orderCourses.addAll(courses);
Set<CourseColumn> orderCourseColumns = new HashSet<>(courseColumns.size());
orderCourseColumns.addAll(courseColumns);
Order order = Order.builder()
.courses(courses)
.courseColumns(courseColumns)
.courses(orderCourses)
.courseColumns(orderCourseColumns)
.paymentTime(now)
.price(BigDecimal.valueOf(0))
.tradeType(0)
Expand Down

0 comments on commit 4fd285b

Please sign in to comment.