数据库重构
This commit is contained in:
parent
80f43b37f6
commit
56fdd7db34
33
src/main/java/com/example/springdemo/entities/Dishes.java
Normal file
33
src/main/java/com/example/springdemo/entities/Dishes.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.example.springdemo.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "Dishes")
|
||||||
|
//菜单菜品类
|
||||||
|
public class Dishes {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;//主键,菜品ID
|
||||||
|
private String name;//菜品名称
|
||||||
|
private BigDecimal price;//菜品价格
|
||||||
|
private Integer discount;//菜品折扣
|
||||||
|
@Column(name = "finalPrice")
|
||||||
|
private BigDecimal finalPrice;//菜品最终价格
|
||||||
|
private String description;//菜品描述
|
||||||
|
|
||||||
|
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "merchantsID", referencedColumnName = "id")
|
||||||
|
@Column(name = "merchantsID")
|
||||||
|
private Merchants merchants;//商家
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
package com.example.springdemo.entities;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
//订单类
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "Indent")
|
|
||||||
public class Indent {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;//订单ID
|
|
||||||
private Float allPrice;//菜品总价
|
|
||||||
@CreatedDate
|
|
||||||
private Date createdDate;//订单创建时间
|
|
||||||
private String message;//下单备注
|
|
||||||
@OneToOne
|
|
||||||
private Users userID;//外键,下单用户ID
|
|
||||||
@OneToOne
|
|
||||||
private Merchants merchantsID;//外键,餐厅ID
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.example.springdemo.entities;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
//订单中的菜品
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
public class IndentItem {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;//主键,菜品ID
|
|
||||||
private String name;//菜品名字
|
|
||||||
@Column(name = "initialPrice")
|
|
||||||
private Float initialPrice;//菜品原价
|
|
||||||
private Float discount;//折扣
|
|
||||||
@Column(name = "finalPrice")
|
|
||||||
private Float finalPrice;//最终价格
|
|
||||||
private String description;//菜品描述
|
|
||||||
@OneToOne
|
|
||||||
private Indent indentID;//外键,订单ID
|
|
||||||
}
|
|
@ -3,6 +3,8 @@ package com.example.springdemo.entities;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@ -12,11 +14,15 @@ import lombok.*;
|
|||||||
public class Merchants {
|
public class Merchants {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;//主键,商家编号
|
private Integer id;//主键,商家编号
|
||||||
private String name;//店铺名字
|
private String name;//店铺名字
|
||||||
private String address;//店铺地址
|
private String address;//店铺地址
|
||||||
private String description;//店铺描述
|
|
||||||
@Column(name = "phoneNumber")
|
@Column(name = "phoneNumber")
|
||||||
private String phoneNumber;//商家联系方式
|
private String phoneNumber;//商家联系方式
|
||||||
|
private String description;//店铺描述
|
||||||
|
|
||||||
|
//商家和菜品是一对多的关系,有mappedBy的时候,表示Merchants的dishes 字段放弃维护权,而将维护权交给了Dishes的关联属性merchants
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "merchants")
|
||||||
|
@Column(name = "dishesID")
|
||||||
|
private List<Dishes> dishes;//菜品
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.example.springdemo.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
//订单中的菜品
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "OrderDishes")
|
||||||
|
public class OrderDishes {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;//主键ID
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "dishesID", referencedColumnName = "id")
|
||||||
|
@Column(name = "dishesID")
|
||||||
|
private Dishes dishes;//菜品ID
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "merchantsID", referencedColumnName = "id")
|
||||||
|
private Merchants merchants;//商家ID
|
||||||
|
|
||||||
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "ordersID", referencedColumnName = "id")
|
||||||
|
private Orders orders;//订单ID
|
||||||
|
}
|
43
src/main/java/com/example/springdemo/entities/Orders.java
Normal file
43
src/main/java/com/example/springdemo/entities/Orders.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package com.example.springdemo.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//订单类
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "Orders")
|
||||||
|
public class Orders {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;//订单ID
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "orders")
|
||||||
|
@Column(name = "orderDishesID")
|
||||||
|
private List<OrderDishes> orderDishes;//订单中的菜品
|
||||||
|
|
||||||
|
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "usersID", referencedColumnName = "id")
|
||||||
|
@Column(name = "usersID")
|
||||||
|
private Users user;//外键,下单用户
|
||||||
|
|
||||||
|
@Column(name = "allPrice")
|
||||||
|
private BigDecimal allPrice;//订单总价
|
||||||
|
|
||||||
|
private String message;//下单备注
|
||||||
|
|
||||||
|
@CreatedDate
|
||||||
|
@Column(name = "createDate")
|
||||||
|
private Date createdDate;//订单创建时间
|
||||||
|
}
|
@ -6,6 +6,8 @@ import lombok.Builder;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
//用户类
|
//用户类
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@ -16,10 +18,14 @@ import lombok.NoArgsConstructor;
|
|||||||
public class Users {
|
public class Users {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;//主键,用户ID
|
private Integer id;//主键,用户ID
|
||||||
private String name;//用户姓名
|
private String name;//用户姓名
|
||||||
|
private String sex;//用户性别
|
||||||
@Column(name = "phoneNumber")
|
@Column(name = "phoneNumber")
|
||||||
private String phoneNumber;//用户联系方式
|
private String phoneNumber;//用户联系方式
|
||||||
private String address;//家庭住址
|
private String address;//家庭住址
|
||||||
private String password;//用户密码
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
|
||||||
|
@Column(name = "ordersID")
|
||||||
|
private List<Orders> orders;//订单
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user