package com.vctgo.system.api.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.vctgo.common.core.annotation.Excel;
import com.vctgo.common.core.annotation.Excel.ColumnType;
import com.vctgo.common.core.annotation.Excel.Type;
import com.vctgo.common.core.annotation.Excels;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author vctgo
 */
@Data
@NoArgsConstructor
@TableName("sys_platform_user")
public class SysPlatformUser extends SysUserTempalte {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    @TableId
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    /**
     * 帐号状态（0启用 1禁用）
     */
    @Excel(name = "帐号状态", readConverterExp = "0=启用  1=禁用  2未启用")
    private String status;

    @TableField(exist = false)
    /** 部门对象 */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    private SysPlatformDept dept;

    @TableField(exist = false)
    /** 角色对象 */
    private List<SysPlatformRole> roles;

    public SysPlatformUser(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    private Long createById;

    private Long updateById;

    @TableField(exist = false)
    private String postName;

    @TableField(exist = false)
    private Long postId;

    @TableField(exist = false)
    private String deptName;

    @TableField(exist = false)
    private String leader;

}
