后台完成修复,初始化项目
This commit is contained in:
89
src/main/java/com/org/flashsalesystem/entity/FlashSale.java
Normal file
89
src/main/java/com/org/flashsalesystem/entity/FlashSale.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.org.flashsalesystem.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 秒杀活动实体类
|
||||
* 对应数据库flash_sales表
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "flash_sales")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FlashSale {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "商品ID不能为空")
|
||||
@Column(name = "product_id", nullable = false)
|
||||
private Long productId;
|
||||
|
||||
@NotNull(message = "秒杀价格不能为空")
|
||||
@DecimalMin(value = "0.01", message = "秒杀价格必须大于0")
|
||||
@Column(name = "flash_price", nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal flashPrice;
|
||||
|
||||
@Min(value = 1, message = "秒杀库存必须大于0")
|
||||
@Column(name = "flash_stock", nullable = false)
|
||||
private Integer flashStock;
|
||||
|
||||
@NotNull(message = "开始时间不能为空")
|
||||
@Column(name = "start_time", nullable = false)
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@NotNull(message = "结束时间不能为空")
|
||||
@Column(name = "end_time", nullable = false)
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 活动状态:1-未开始,2-进行中,3-已结束
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private Integer status = 1;
|
||||
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "product_id", insertable = false, updatable = false)
|
||||
private Product product;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查活动是否已开始
|
||||
*/
|
||||
public boolean isStarted() {
|
||||
return LocalDateTime.now().isAfter(startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查活动是否已结束
|
||||
*/
|
||||
public boolean isEnded() {
|
||||
return LocalDateTime.now().isAfter(endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查活动是否正在进行中
|
||||
*/
|
||||
public boolean isActive() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return now.isAfter(startTime) && now.isBefore(endTime) && status == 2;
|
||||
}
|
||||
}
|
||||
133
src/main/java/com/org/flashsalesystem/entity/Order.java
Normal file
133
src/main/java/com/org/flashsalesystem/entity/Order.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package com.org.flashsalesystem.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单实体类
|
||||
* 对应数据库orders表
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "orders")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Order {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@NotNull(message = "商品ID不能为空")
|
||||
@Column(name = "product_id", nullable = false)
|
||||
private Long productId;
|
||||
|
||||
@Min(value = 1, message = "商品数量必须大于0")
|
||||
@Column(nullable = false)
|
||||
private Integer quantity;
|
||||
|
||||
@NotNull(message = "订单总价不能为空")
|
||||
@DecimalMin(value = "0.01", message = "订单总价必须大于0")
|
||||
@Column(name = "total_price", nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
/**
|
||||
* 订单状态:1-待支付,2-已支付,3-已发货,4-已完成,5-已取消
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private Integer status = 1;
|
||||
|
||||
/**
|
||||
* 订单类型:1-普通订单,2-秒杀订单
|
||||
*/
|
||||
@Column(name = "order_type", nullable = false)
|
||||
private Integer orderType = 1;
|
||||
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", insertable = false, updatable = false)
|
||||
private User user;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "product_id", insertable = false, updatable = false)
|
||||
private Product product;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单状态枚举
|
||||
*/
|
||||
public enum OrderStatus {
|
||||
PENDING_PAYMENT(1, "待支付"),
|
||||
PAID(2, "已支付"),
|
||||
SHIPPED(3, "已发货"),
|
||||
COMPLETED(4, "已完成"),
|
||||
CANCELLED(5, "已取消");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
OrderStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单类型枚举
|
||||
*/
|
||||
public enum OrderType {
|
||||
NORMAL(1, "普通订单"),
|
||||
FLASH_SALE(2, "秒杀订单");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
OrderType(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/main/java/com/org/flashsalesystem/entity/Product.java
Normal file
71
src/main/java/com/org/flashsalesystem/entity/Product.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.org.flashsalesystem.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商品实体类
|
||||
* 对应数据库products表
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "products")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
@Column(nullable = false, length = 200)
|
||||
private String name;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String description;
|
||||
|
||||
@NotNull(message = "商品价格不能为空")
|
||||
@DecimalMin(value = "0.01", message = "商品价格必须大于0")
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal price;
|
||||
|
||||
@Min(value = 0, message = "库存不能为负数")
|
||||
@Column(nullable = false)
|
||||
private Integer stock = 0;
|
||||
|
||||
@Column(name = "image_url", length = 500)
|
||||
private String imageUrl;
|
||||
|
||||
/**
|
||||
* 商品状态:1-上架,0-下架
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private Integer status = 1;
|
||||
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
68
src/main/java/com/org/flashsalesystem/entity/User.java
Normal file
68
src/main/java/com/org/flashsalesystem/entity/User.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.org.flashsalesystem.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户实体类
|
||||
* 对应数据库users表
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@Size(min = 3, max = 50, message = "用户名长度必须在3-50个字符之间")
|
||||
@Column(unique = true, nullable = false, length = 50)
|
||||
private String username;
|
||||
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Size(min = 6, max = 100, message = "密码长度必须在6-100个字符之间")
|
||||
@Column(nullable = false, length = 100)
|
||||
private String password;
|
||||
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Column(length = 100)
|
||||
private String email;
|
||||
|
||||
@Size(max = 20, message = "手机号长度不能超过20个字符")
|
||||
@Column(length = 20)
|
||||
private String phone;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private Integer status = 1; // 1-正常, 0-禁用
|
||||
|
||||
@Column(name = "last_login")
|
||||
private LocalDateTime lastLogin;
|
||||
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user