package com.ff.weijinxiao.domain;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ff.weijinxiao.util.jsonfilter.DateSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 系统用户表
 */
@Data
@Entity
@Table(name = "tb_user")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    //名字
    @Column(name = "user_name", length = 20)
    private String name;

    //账号
    @Column(name = "account", length = 50)
    private String account;

    //密码
    @Column(name = "password_hash", length = 100)
    private String password;

    //电话
    @Column(name = "phone", length = 30)
    private String phone;

    //邮箱
    @Column(name = "email", length = 50)
    private String email;

    //用户状态（1=正常用户(默认) 0=异常用户)
    @Column(name = "user_status")
    private Integer status = 1;

    //角色
//    @ManyToMany(fetch=FetchType.EAGER)
//    @JoinTable(name = "tb_user_role_relation", joinColumns = {
//            @JoinColumn(name = "user_id", referencedColumnName = "id")}, inverseJoinColumns = {
//            @JoinColumn(name = "role_id", referencedColumnName = "id")})
//    private List<Role> roles;

    @Column(name = "user_deleted", columnDefinition = "int COMMENT '删除状态（0=未删除(默认) 1=已删除)'")
    @ApiModelProperty(value = "删除状态（0=未删除(默认) 1=已删除)")
    private Integer deleted = 0;

    //备注
    @Column(name = "description", length = 100)
    private String description;

    //创建时间
    @Column(updatable = false)
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date create_date;

    //更新时间
    @Column(name = "update_date")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date update_date;
}
