package thyyxxk.webserver.entity.login;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import thyyxxk.webserver.config.ColumnName;
import thyyxxk.webserver.constants.RestrictedDrugLevels;
import thyyxxk.webserver.constants.Ysjb;
import thyyxxk.webserver.utils.StringUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author dj
 */
@Data
public class UserInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 编码
     */
    private String code;

    /**
     * 名字
     */
    @ColumnName
    private String name;
    @ColumnName
    private String ybName;
    @ColumnName
    private String referralCode;
    private String password;

    /**
     * 工号
     */
    private String codeRs;
    /**
     * 技术职称
     */
    @ColumnName
    private String empTitCode;
    private String empTitName;
    private String title;

    /**
     * 职务
     */
    @ColumnName
    private String empPoCode;
    private String position;

    private String avatar;
    private String token;
    private String sid;
    private String ip;

    /**
     * 医保编码
     */
    @ColumnName
    private String ybCode;

    @ColumnName
    private String deptCode;
    private String deptName;

    /**
     * 在院标志
     */
    @ColumnName
    private String mark;
    private String markName;

    /**
     * 干工标志
     */
    @ColumnName
    private String ifcadre;
    private String ifcadreName;

    /**
     * 拼音 五笔码
     */
    private String pyCode;
    private String dCode;
    /**
     * 医生处方权 1 普通处方权 2 毒麻药处方权
     */
    @ColumnName
    private String orderYn;
    /**
     * 病历级别
     * {@link Ysjb}
     */
    @ColumnName
    private String ysjb;

    /**
     * 挂号号别
     */
    @ColumnName
    private String ghChargeType;
    private String ghChargeTypeName;
    /**
     * 病区允许就诊 1 允许 2 不允许
     */
    @ColumnName
    private String loginFlag;
    /**
     * 限制药品级别
     * {@link RestrictedDrugLevels}
     */
    @ColumnName
    private String doctorXzYp;

    /**
     * 停用标志
     */
    @ColumnName
    private String delFlag;

    /**
     * 身份证
     */
    @ColumnName
    private String socialNo;

    /**
     * 手机号码
     */
    @ColumnName
    private String phoneNo;


    private List<Integer> roles;

    /**
     * 有权限的路由id
     */
    private List<Integer> menuId;

    /**
     * 医生用药等级
     */
    private Integer doctorLevel;

    /**
     * 药品编码
     */
    private String drugCode;

    /**
     * 医生兼职科室
     */
    private List<String> partTimeDept;
    private String partTimeDeptCode;
    private String partTimeDeptName;
    private Map<String, String> partTimeDeptMap;

    private String verificationCode;

    /**
     * 当前科室的人可以在会诊完成几天后，可以去到患者的医嘱录入界面
     */
    private Integer hzDay;

    private String userConfig;

    @ColumnName
    private Integer doctorZy;

    @ColumnName
    private Integer doctorYpZl;
    private String doctorYpZlName;

    @ColumnName
    private Integer dualchnlFlag;

    @ColumnName
    private String practiceCertificate;
    //自动日结 0 否 1 是
    @ColumnName
    private String autoDaily;

    public JSONObject getUserConfigJson() {
        return StringUtil.isBlank(userConfig) ? new JSONObject() : JSONObject.parseObject(userConfig);
    }

    public String getDoctorXzYpName() {
        return RestrictedDrugLevels.getName(doctorXzYp);
    }

    public String getYsjbName() {
        return Ysjb.getName(ysjb);
    }

    public String getOrderYnName() {
        if (StringUtil.notBlank(orderYn)) {
            if ("1".equals(orderYn)) {
                return "普通处方权";
            } else if ("2".equals(orderYn)) {
                return "毒麻药处方权";
            }
        }
        return "";
    }

    public List<Integer> getRoles() {
        return null == roles ? new ArrayList<Integer>() : roles;
    }
}
