package com.cnd3b.common.parameter;

import com.cnd3b.common.data.Row;
import p2.p2server.P2Server;
import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;

import java.util.Date;
import java.util.HashMap;

/**
 * 参数及全局数据表
 *
 * @author SHENJW
 */
public class parameter {
    //token:userid
    public static HashMap<String, Long> tokenlist = new HashMap<String, Long>(16);
    //token:time
    public static HashMap<String, Date> requesttime = new HashMap<String, Date>(16);
    //userid:usermsg
    public static HashMap<Long, Row> userIdList = new HashMap<>(16);

    /**
     * 登录-手机号、验证码
     */
    public static HashMap<String, String> phonenumber_password = new HashMap<>(16);
    /**
     * 登录-验证码、有效期
     */
    public static HashMap<String, Date> phonenumber_date = new HashMap<>(16);

    /**
     * 修改手机号-手机号、验证码
     */
    public static HashMap<String, String> changephonenumber_passwordmap = new HashMap<>(16);
    /**
     * 修改手机号-验证码、有效期
     */
    public static HashMap<String, Date> changephonenumber_date = new HashMap<>(16);

    /**
     * 忘记密码-账号、验证码
     */
    public static HashMap<String, String> forgetpassword_passwordmap = new HashMap<>(16);
    /**
     * 忘记密码-验证码、有效期
     */
    public static HashMap<String, Date> forgetpassword_date = new HashMap<>(16);


    /**
     * 方法请求次数
     */
    public static HashMap<String, Long> callmethodTimes = new HashMap<String, Long>(16);

    /**
     * 方法请求从缓存获取次数
     */
    public static HashMap<String, Long> callmethod_fromcacheTimes = new HashMap<String, Long>(16);

    /**
     * 方法请求查询平均时间
     */
    public static HashMap<String, Long> callmethodTimeLong = new HashMap<String, Long>(16);

    /**
     * 方法请求查询最新时间
     */
    public static HashMap<String, Long> callmethodLastTimeLong = new HashMap<String, Long>(16);

    /**
     * 方法请求最近时间
     */
    public static HashMap<String, Date> lastcallmethodtime = new HashMap<String, Date>(16);


    public static boolean isdebug() {
        parameter_init();
        return isdebug;
    }

    public static long OBS_expireSeconds() {
        parameter_init();
        return OBS_expireSeconds;
    }

    public static String SQLiteFilePath() {
        parameter_init();
        return SQLiteFilePath;
    }

    public static String UpLoadExcelErrFilePath() {
        parameter_init();
        return UpLoadExcelErrFilePath;
    }

    public static String Bucket_endPoint() {
        parameter_init();
        return Bucket_endPoint;
    }

    public static String Bucket_location() {
        parameter_init();
        return Bucket_location;
    }

    public static String Bucket_ak() {
        parameter_init();
        return Bucket_ak;
    }

    public static String Bucket_sk() {
        parameter_init();
        return Bucket_sk;
    }

    public static void parameter_init() {
        if (isparameterinit) {
            return;
        }
        PaoSetRemote tparameter = null;
        try {
            tparameter = P2Server.getP2Server().getPaoSet("tparameter", P2Server.getP2Server().getSystemUserInfo());
            if (!tparameter.isEmpty()) {
                PaoRemote pao = tparameter.getPao(0);
                isdebug = pao.getBoolean("isdebug");

                Bucket_ak = pao.getString("bucket_ak");
                Bucket_sk = pao.getString("bucket_sk");
                Bucket_endPoint = pao.getString("bucket_endpoint");
                Bucket_location = pao.getString("bucket_location");
                OBS_expireSeconds = pao.getLong("obs_expireseconds");
                SQLiteFilePath = pao.getString("sqlitefilepath");
                UpLoadExcelErrFilePath = pao.getString("uploadexcelerrfilepath");
                isparameterinit = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                tparameter.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 参数是否初始化
     */
    public static boolean isparameterinit = false;

    /**
     * 云存储参数
     */
    private static String Bucket_endPoint;
    private static String Bucket_location;
    private static String Bucket_ak;
    private static String Bucket_sk;
    /**
     * 是否调试模式
     */
    private static boolean isdebug;

    /**
     * obs分享链接实效
     */
    private static long OBS_expireSeconds;

    /**
     * SQLlite数据库文件路径
     */
    private static String SQLiteFilePath;

    /**
     * 上传数据错误文件存放路径
     */
    private static String UpLoadExcelErrFilePath;
}
