数据库重构

This commit is contained in:
myh 2023-11-05 23:16:30 +08:00
parent 80f43b37f6
commit 56fdd7db34
7 changed files with 125 additions and 63 deletions

View 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;//商家
}

View File

@ -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
}

View File

@ -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
}

View File

@ -3,6 +3,8 @@ package com.example.springdemo.entities;
import jakarta.persistence.*;
import lombok.*;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@ -12,11 +14,15 @@ import lombok.*;
public class Merchants {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;//主键,商家编号
private Integer id;//主键,商家编号
private String name;//店铺名字
private String address;//店铺地址
private String description;//店铺描述
@Column(name = "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;//菜品
}

View 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;
//订单中的菜品
@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
}

View 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;//订单创建时间
}

View File

@ -6,6 +6,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
//用户类
@Data
@Builder
@ -16,10 +18,14 @@ import lombok.NoArgsConstructor;
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;//主键用户ID
private Integer id;//主键用户ID
private String name;//用户姓名
private String sex;//用户性别
@Column(name = "phoneNumber")
private String phoneNumber;//用户联系方式
private String address;//家庭住址
private String password;//用户密码
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
@Column(name = "ordersID")
private List<Orders> orders;//订单
}