package com.mvc.interceptor;

import com.mvc.constant.QueryUserType;
import com.mvc.model.AppUserModel;
import com.mvc.model.CustomUserModel;
import com.mvc.model.FacUserModel;
import com.mvc.model.TAffiliatedunitModel;

import java.util.HashMap;

/**
 * Jwt中存储的用户信息
 */
public class JwtInfoMap extends HashMap<String, Object> {
    public JwtInfoMap(Object userModel) {
        super();

        String loginId = "";//预留
        String pwd = "";//预留
        QueryUserType queryUserType = QueryUserType.CUSTOMER;
        if (userModel.getClass() == FacUserModel.class) {
            FacUserModel user = (FacUserModel) userModel;
            loginId = user.getLoginId();
            pwd = user.getLoginPwd();
            queryUserType = QueryUserType.INTERNAL;
        } else if (userModel.getClass() == CustomUserModel.class) {
            CustomUserModel user = (CustomUserModel) userModel;
            loginId = user.getLoginId();
            pwd = user.getLoginPwd();

            TAffiliatedunitModel affiliatedunitModel = user.getAffiliatedunitModel();
            if (affiliatedunitModel != null) {
                //除运维单位外,都视为客户
                queryUserType = affiliatedunitModel.getUnitType().equals("3") ? QueryUserType.OPRATIONER : QueryUserType.CUSTOMER;
            } else {
                queryUserType = QueryUserType.CUSTOMER;
            }
        } else if (userModel.getClass() == AppUserModel.class) {
            AppUserModel user = (AppUserModel) userModel;
            loginId = user.getLoginId();
            pwd = user.getLoginPwd();
            queryUserType = user.getUserType().equals("0") ? QueryUserType.INTERNAL : QueryUserType.OPRATIONER;
        }

        this.put("loginId", loginId);
        this.put("pwd", pwd);
        this.put("queryUserType", queryUserType.getFlag());
    }
}