package com.mosty.bkzx.sjjs.client;


import com.mosty.bkzx.sjjs.vo.AuthorizeTwoVo;
import com.mosty.common.base.exception.BusinessException;

public enum TokenClient {

    INSTANCE();

    private static String token;

    private static long createdTime;


    public String accessToken(){
        if(token == null){
            AuthorizeTwoVo authorizeTwoVo = HttpClient.authorizeAfter(HttpClient.authorizeBefore("zymytest","web"),"zymytest","system123");
            token = authorizeTwoVo.getToken();
            createdTime = System.currentTimeMillis();
        }
        if((System.currentTimeMillis() - createdTime) >= 90 *1000 ){
            HttpClient.keepAlive(token);
        }
        if((System.currentTimeMillis() - createdTime) >= 120 *1000){
            AuthorizeTwoVo authorizeTwoVo = HttpClient.authorizeAfter(HttpClient.authorizeBefore("zymytest","web"),"zymytest","system123");
            token = authorizeTwoVo.getToken();
            createdTime = System.currentTimeMillis();
        }
        return token;
    }

    /**
     * 大华根据不同的市区建库
     * @param account
     * @return
     */
    public  String accessToken(AccountUtils.Accounts account){
        if(null == account){throw  new BusinessException("token账号信息无效！");}
        AuthorizeTwoVo authorizeTwoVo = HttpClient.authorizeAfter(HttpClient.authorizeBefore(account.getAccount(),"web"),account.getAccount(),account.getPwd());
        token = authorizeTwoVo.getToken();
        return token;
    }
}
