package com.bcxin.backend.domain.system.entities;

import lombok.Data;

import javax.persistence.*;
import java.util.Collection;
import java.util.Date;

@Data
@Entity
@Table(name = "t_user")
public class UserDTO {
    @Id
    private String id;
    private String name;
    private String loginno;
    @Column(name = "NAME_LETTER")
    private String nameLetter;
    private String loginpwd;
    private String telephone;
    private String email;
    private String field1;
    private String field2;
    private String field3;
    private String field4;
    private String field5;
    private String field6;
    private String field7;
    private String field8;
    private String field9;
    private String field10;
    private String field11;
    private String field12;
    private String field13;
    private String field14;
    private String field15;
    private String field16;
    private String field17;
    private String field18;
    private String field19;
    private String field20;
    private String field21;
    private String field22;
    private String field23;
    private String field24;
    private String field25;
    private String field26;
    private String field27;
    private String field28;
    private String field29;
    private String field30;
    @Column(name = "DEFAULTDEPARTMENT")
    protected String defaultDepartment;
    protected String domainid;
    @Column(name = "LEVELS")
    protected int level;
    @Column(name = "LASTMODIFYTIME")
    protected Date lastModifyTime;
    @Column(name = "LIAISON_OFFICER")
    protected boolean liaisonOfficer;
    @Column(name = "ISDOMAINUSER")
    protected String domainUser;
    protected int dimission;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "t_user_department_role_set",
            joinColumns =
            @JoinColumn(name = "USERID", referencedColumnName = "ID"),
            inverseJoinColumns =
            @JoinColumn(name = "DEPARTMENTID", referencedColumnName = "ID")
    )
    private Collection<DepartmentDTO> departments;

    public void doneForDataExchange() {
        this.setField27("完成分发");
        this.setField28(String.valueOf(new Date()));
    }

    public void markDispatchError(String msg) {
        this.setField28(String.format("%s: 分发异常: %s", new Date(), msg));
    }
}
