package com.winsun.shiro;


import org.apache.commons.lang3.StringUtils;

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

/**
 * 自定义Authentication对象，使得Subject除了携带用户的登录名外还可以携带更多信息
 *
 * @author fengshuonan
 * @date 2016年12月5日 上午10:26:43
 */
public class ShiroUser implements Serializable {

    private static final long serialVersionUID = 1L;

    public Integer id;          // 主键ID
    public String account;      // 账号
    public String name;         // 姓名
    public String phone;         // 姓名
    public Integer deptId;      // 部门id
    public String email;      // 邮箱
    public List<Integer> roleList; // 角色集
    public String deptName;        // 部门名称
    public List<String> roleNames; // 角色名称集
    public String roleId;           //用户角色
    public Integer level;        //角色等级
    public List<Integer> pids;  //用户父部门集合
    public String parentDeptName; //父部门名称
    public String channelType;  //渠道大类
    public String salestaffId;  //揽装工号
    public String substName;    //县分名称
    public String branchName;   //营服名称
    public List<String> subTypeList; //渠道名称
    public List<String> subTypeListDl; //大类渠道名称
    private List<String> areaList;    //所属片区
    private List<String> gridNameList;    //所属网格名称
    private List<String> gridCodeList;    //所属网格编码
    private List<String> channelNameList; //所拥有网点名称
    private String xfyfJson; //所属县分营服
    private String yfpqJson; //所属营服片区
    private List<String> operatorsList; //所属合作商
    private String sqDeptId;//社区工单机构id
    private String crmNum;//社区工单机构id

	public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getDeptId() {
        return deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    public List<Integer> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Integer> roleList) {
        this.roleList = roleList;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public List<String> getRoleNames() {
        return roleNames;
    }

    public void setRoleNames(List<String> roleNames) {
        this.roleNames = roleNames;
    }

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public List<Integer> getPids() {
        return pids;
    }

    public void setPids(List<Integer> pids) {
        this.pids = pids;
    }

    public String getParentDeptName() {
        return parentDeptName;
    }

    public void setParentDeptName(String parentDeptName) {
        this.parentDeptName = parentDeptName;
    }

    public String getChannelType() {
        return channelType;
    }

    public void setChannelType(String channelType) {
        this.channelType = channelType;
    }

    public String getSalestaffId() {
        return salestaffId;
    }

    public void setSalestaffId(String salestaffId) {
        this.salestaffId = salestaffId;
    }

    public String getSubstName() {
        return substName;
    }

    public void setSubstName(String substName) {
        this.substName = substName;
    }

    public String getBranchName() {
        return branchName;
    }

    public void setBranchName(String branchName) {
        this.branchName = branchName;
    }
    
    public List<String> getSubTypeList() {
		return subTypeList;
	}

	public void setSubTypeList(List<String> subTypeList) {
		this.subTypeList = subTypeList;
	}

    public List<String> getAreaList() {
        return areaList;
    }

    public void setAreaList(List<String> areaList) {
        this.areaList = areaList;
    }

    public List<String> getGridNameList() {
        return gridNameList;
    }

    public void setGridNameList(List<String> gridNameList) {
        this.gridNameList = gridNameList;
    }

    public List<String> getGridCodeList() {
        return gridCodeList;
    }

    public void setGridCodeList(List<String> gridCodeList) {
        this.gridCodeList = gridCodeList;
    }

    public String getXfyfJson() {
        return xfyfJson;
    }

    public void setXfyfJson(String xfyfJson) {
        this.xfyfJson = xfyfJson;
    }

    public String getYfpqJson() {
        return yfpqJson;
    }

    public void setYfpqJson(String yfpqJson) {
        this.yfpqJson = yfpqJson;
    }

    public List<String> getOperatorsList() {
        return operatorsList;
    }

    public void setOperatorsList(List<String> operatorsList) {
        this.operatorsList = operatorsList;
    }


    public List<String> getChannelNameList() {
        return channelNameList;
    }

    public void setChannelNameList(List<String> channelNameList) {
        this.channelNameList = channelNameList;
    }

    public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the sqDeptId
	 */
	public String getSqDeptId() {
		return sqDeptId;
	}

	/**
	 * @param sqDeptId the sqDeptId to set
	 */
	public void setSqDeptId(String sqDeptId) {
		this.sqDeptId = sqDeptId;
	}

    public String getCrmNum() {
        return crmNum;
    }

    public void setCrmNum(String crmNum) {
        this.crmNum = crmNum;
    }


    public List<String> getSubTypeListDl() {
        return subTypeListDl;
    }

    public void setSubTypeListDl(List<String> subTypeListDl) {
        this.subTypeListDl = subTypeListDl;
    }

    //实体渠道用户角色权限
    public void getUserRoleScope(Map<String, Object> map) {
        Integer level = getLevel();
        //超级管理员,市公司管理岗,渠道主健团队 等级1 2 3
        if (level > 0 && level <= 3) {
            if (map.get("subst_name") == null)
                map.put("subst_name", "");
            if (map.get("branch_name") == null)
                map.put("branch_name", "");
            map.put("account", "");
        }
        //县分管理岗,县分主战团队 等级4 5
        else if (level > 3 && level <= 5) {
            map.put("subst_name", getSubstName());
            if (map.get("branch_name") == null)
                map.put("branch_name", "");
            map.put("account", "");
        }
        //营服管理岗 6
        else if (level == 6) {
            map.put("subst_name", getSubstName());
            map.put("branch_name", getBranchName());
            map.put("account", "");
        }
        //机构管理员 -1
        else if (level == -1) {
            //县分岗
        	//"".equals(getBranchName())
            if (!"全市".equals(getSubstName()) && StringUtils.isBlank(getBranchName())) {
                map.put("subst_name", getSubstName());
            }
            //营服岗
            else if (!"全市".equals(getSubstName()) && !StringUtils.isBlank(getBranchName())){
                map.put("subst_name", getSubstName());
                map.put("branch_name", getBranchName());
            }
            map.put("account", "");
        }else {
            map.put("subst_name", getSubstName());
            map.put("branch_name", getBranchName());
            map.put("account", getAccount());
            List<String> subTypeList = getSubTypeList();
            if (subTypeList.size() == 1 && StringUtils.isBlank(subTypeList.get(0))) {
                map.put("subTypeList", new ArrayList());
            } else {
                map.put("subTypeList", getSubTypeList());
            }
        }
    }
    
}
