package com.bocloud.ims.entity.common;

import com.bocloud.common.utils.DateDeserializer;
import com.bocloud.common.utils.DateSerializer;
import com.bocloud.entity.annotations.Column;
import com.bocloud.entity.annotations.IgnoreAll;
import com.bocloud.entity.annotations.PK;
import com.bocloud.entity.annotations.Table;
import com.bocloud.entity.bean.GenericEntity;
import com.bocloud.entity.meta.PKStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 自服务用户
 *
 * @author wangyu
 * @version 1.0
 * @since 2020年1月29日
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table("user")
public class User extends GenericEntity {

    @PK(value = PKStrategy.AUTO)
    private Long id; // ID
    @Column("account")
    private String account; // 账号
    @Column("password")
    private String password; // 密码
    @Column("email")
    private String email; // 邮件
    @Column("phone")
    private String phone; // 电话
    @Column("mobile")
    private String mobile; // 移动电话
    @Column("login_status")
    private Boolean loginStatus; // 登录状态
    @Column("company")
    private String company; // 公司
    @Column("session_id")
    private String sessionId; // sessionId
    @IgnoreAll
    private String tenantName;
    @IgnoreAll
    private String tenantAccount;//对应租户账号
    @IgnoreAll
    private BigDecimal discount;
    @Column("tenant_id")
    private Long tenantId; // 租户ID
    @IgnoreAll
    private List<String> roleNames;
    @Column("depart_id")
    private Long departId; // 组织机构ID
    @Column("depart_ids")
    private String departIds;
    @IgnoreAll
    private String departName;// 组织机构名称
    @IgnoreAll
    private Boolean checked;
    @Column("job_number")
    private String jobNumber;//工号
    @Column("sex")
    private Boolean sex;
    @IgnoreAll
    private Long projectId;// 当前登录的项目ID
    @IgnoreAll
    private List<Long> projectIds;
    @Column("tenant_ids")
    private String tenantIds;
    @Column("portrait")
    private String portrait;// 头像
    @Column("origin")
    private String origin;
    @Column("last_pwd_modify_date")
    @JsonSerialize(using = DateSerializer.class)
    @JsonDeserialize(using = DateDeserializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastPwdModifyDate;
    @Column("last_login_date")
    @JsonSerialize(using = DateSerializer.class)
    @JsonDeserialize(using = DateDeserializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastLoginDate;// 最后一次登录时间

    public User(String name, String account, String email, String company, String mobile, Long creatorId, Long tenantId) {
        this.setName(name);
        this.setCreatorId(creatorId);
        this.account = account;
        this.company = company;
        this.email = email;
        this.mobile = mobile;
        this.tenantId = tenantId;
    }
}
