forked from baskbuddy/zhangshun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
83 lines
2.1 KiB
package com.mydreamjob.auth;
|
|
|
|
import jakarta.persistence.*;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Builder;
|
|
import lombok.Data;
|
|
import lombok.NoArgsConstructor;
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
import org.springframework.data.annotation.LastModifiedDate;
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* 用户实体
|
|
*/
|
|
@Data
|
|
@Builder
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
@Entity
|
|
@Table(name = "users")
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
public class User {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(name = "phone", nullable = false, unique = true, length = 20)
|
|
private String phone;
|
|
|
|
@Column(name = "email", length = 100)
|
|
private String email;
|
|
|
|
@Column(name = "nickname", length = 50)
|
|
private String nickname;
|
|
|
|
@Column(name = "avatar_url", length = 500)
|
|
private String avatarUrl;
|
|
|
|
@Column(name = "password_hash", length = 255)
|
|
private String passwordHash;
|
|
|
|
@Column(name = "password_changed_at")
|
|
private LocalDateTime passwordChangedAt;
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
@Column(name = "role", nullable = false, length = 30)
|
|
@Builder.Default
|
|
private Role role = Role.STUDENT;
|
|
|
|
@ElementCollection(targetClass = Role.class)
|
|
@CollectionTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"))
|
|
@Column(name = "role")
|
|
@Enumerated(EnumType.STRING)
|
|
@Builder.Default
|
|
private Set<Role> roles = Set.of(Role.STUDENT);
|
|
|
|
@Column(name = "is_active", nullable = false)
|
|
@Builder.Default
|
|
private Boolean active = true;
|
|
|
|
@Column(name = "is_verified", nullable = false)
|
|
@Builder.Default
|
|
private Boolean verified = false;
|
|
|
|
@CreatedDate
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
|
private LocalDateTime createdAt;
|
|
|
|
@LastModifiedDate
|
|
@Column(name = "updated_at", nullable = false)
|
|
private LocalDateTime updatedAt;
|
|
|
|
public enum Role {
|
|
UNASSIGNED,
|
|
STUDENT,
|
|
COMPANY,
|
|
ADMIN
|
|
}
|
|
}
|
|
|