refactor: 后端核心模块功能增强与代码优化
- 完善 User/Product/Order 实体字段和关联关系 - 更新 DTO 适配新增字段 - 增强 Service 层业务逻辑和 Repository 查询方法 - 优化控制器接口,完善管理后台 API - 新增请求监控过滤器和指标服务
This commit is contained in:
@@ -26,6 +26,12 @@ public class Order {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "order_no", nullable = false, unique = true, length = 64)
|
||||
private String orderNo;
|
||||
|
||||
@Column(name = "group_no", length = 64)
|
||||
private String groupNo;
|
||||
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
@@ -58,6 +64,30 @@ public class Order {
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "receiver_name", length = 100)
|
||||
private String receiverName;
|
||||
|
||||
@Column(name = "receiver_phone", length = 20)
|
||||
private String receiverPhone;
|
||||
|
||||
@Column(name = "receiver_address", length = 255)
|
||||
private String receiverAddress;
|
||||
|
||||
@Column(name = "remark", length = 255)
|
||||
private String remark;
|
||||
|
||||
@Column(name = "payment_method", length = 50)
|
||||
private String paymentMethod;
|
||||
|
||||
@Column(name = "paid_at")
|
||||
private LocalDateTime paidAt;
|
||||
|
||||
@Column(name = "shipped_at")
|
||||
private LocalDateTime shippedAt;
|
||||
|
||||
@Column(name = "completed_at")
|
||||
private LocalDateTime completedAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@@ -73,6 +103,9 @@ public class Order {
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
if (orderNo == null || orderNo.trim().isEmpty()) {
|
||||
orderNo = "FS" + System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
|
||||
@@ -39,6 +39,9 @@ public class Product {
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal price;
|
||||
|
||||
@Column(length = 100)
|
||||
private String category;
|
||||
|
||||
@Min(value = 0, message = "库存不能为负数")
|
||||
@Column(nullable = false)
|
||||
private Integer stock = 0;
|
||||
@@ -60,6 +63,9 @@ public class Product {
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
if (category == null || category.trim().isEmpty()) {
|
||||
category = "默认分类";
|
||||
}
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@@ -43,9 +43,15 @@ public class User {
|
||||
@Column(length = 20)
|
||||
private String phone;
|
||||
|
||||
@Column(length = 500)
|
||||
private String avatar;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private Integer status = 1; // 1-正常, 0-禁用
|
||||
|
||||
@Column(name = "role", nullable = false, length = 20)
|
||||
private String role = "USER";
|
||||
|
||||
@Column(name = "last_login")
|
||||
private LocalDateTime lastLogin;
|
||||
|
||||
@@ -57,6 +63,9 @@ public class User {
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
if (role == null || role.trim().isEmpty()) {
|
||||
role = "USER";
|
||||
}
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user