- 完善 User/Product/Order 实体字段和关联关系 - 更新 DTO 适配新增字段 - 增强 Service 层业务逻辑和 Repository 查询方法 - 优化控制器接口,完善管理后台 API - 新增请求监控过滤器和指标服务
78 lines
2.0 KiB
Java
78 lines
2.0 KiB
Java
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(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;
|
|
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
|
private LocalDateTime createdAt;
|
|
|
|
@Column(name = "updated_at")
|
|
private LocalDateTime updatedAt;
|
|
|
|
@PrePersist
|
|
protected void onCreate() {
|
|
if (role == null || role.trim().isEmpty()) {
|
|
role = "USER";
|
|
}
|
|
createdAt = LocalDateTime.now();
|
|
updatedAt = LocalDateTime.now();
|
|
}
|
|
|
|
@PreUpdate
|
|
protected void onUpdate() {
|
|
updatedAt = LocalDateTime.now();
|
|
}
|
|
}
|