package cn.hmsoft.hmplatform.helper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hmsoft.application.AppHelper;
import cn.hmsoft.frame.constants.FrameStatus;
import cn.hmsoft.frame.data.model.FrameParam;
import cn.hmsoft.frame.util.FrameParamUtil;
import cn.hmsoft.helper.BeanHelper;
import cn.hmsoft.helper.CollectionHelper;
import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.hmplatform.constants.ArtParamType;
import cn.hmsoft.weixin.data.model.WxDefine;
import cn.hmsoft.weixin.util.WeiXinUtil;

public class ParamHelper extends FrameParamUtil {

	public final static String SessionName_EnrolWeixinCode = "EnrolWeixinCode";
	public final static String SessionName_EnrolWeixinUser = "EnrolWeixinUser";
	public final static String SessionName_EnrolStdReg = "EnrolStdReg";
	public static String AppEncryptKey = "gKrSAKfxQywOTi";
	/*******************
	 * 当前年份
	 */
	private static String ArtShortYear = "";
	/******************
	 * 加载参数密钥
	 */
	public static String ReloadParamPassword = "2020";
	/*******************
	 * 参数加载时长
	 */
	public static int ReloadParamInterval = 10;
	/*******************
	 * 当前年份
	 */
	public static String ArtYear = "2020";

	/*******************
	 * 当前状态
	 */
	public static String ArtStatus = "Config";

	/*****************
	 * 业务名称
	 */
	public static String BusinessName = "本科校考";

	/*****************
	 * 学校所在省份
	 */
	public static String SchoolProvince = "";

	/*****************
	 * 学校微信地址
	 */
	public static String SchoolWeixinUrl = "";

	/*****************
	 * 学校的公众号信息，必须有
	 */
	public static String SchoolWeixinAppId = "";
	/*****************
	 * 学校的商户编号
	 */
	public static String SchoolMerchantId = "";
	/*****************
	 * 是否启用二级学院
	 */
	public static String TwoLevelCollege = "InActive";

	/******************
	 * 特权ip
	 */
	public static String PrivilegeAddress = "";
	/******************
	 * 报名系统开放时间
	 */
	public static String EnrolOpenTime = "";
	/******************
	 * 报名系统关闭时间
	 */
	public static String EnrolCloseTime = "";
	/******************
	 * 大陆地区行政区划代码最大值
	 */
	public static Integer MainlandMaxProvinceId = 69;

	/*****************
	 * 默认公众号
	 */
	private static WxDefine SchoolWxDefine = null;

	/******************
	 * 报名app 考生材料本地路径
	 */
	public static String EnrolMaterialLocalPath = "";
	/******************
	 * 报名app 考生材料web路径
	 */
	public static String EnrolMaterialWebPath = "";
	/******************
	 * 视频路径
	 */
	public static String EnrolMaterialVideoPath = "";
	/******************
	 * 本省考点过期后是否允许省外考点
	 */
	public static String EnrolAllowOutsideProvince = "Active";
	/******************
	 * 考生最大专业数量
	 */
	public static int EnrolStdAspectLimit = 5;
	/******************
	 * 考生最大大类数量
	 */
	public static int EnrolStdCategoryLimit = 5;
	/******************
	 * 划线是否只针对大陆地区
	 */
	public static String PlanMainlandOnly = FrameStatus.Active.toString();
	
	/******************
	 * 录制视频最大可以断掉的秒数
	 */
	public static Integer VideoInterview = 30;

	/***************
	 * 获取短年份
	 */
	public static String getShortYear() {
		if (StringHelper.isEmpty(ArtShortYear)) {
			synchronized (ParamHelper.class) {
				if (StringHelper.isEmpty(ArtShortYear)) {
					ArtShortYear = ArtYear.substring(0, 2);
				}
			}
		}
		return ArtShortYear;
	}

	/****************
	 * 获取公众号
	 */
	public static WxDefine getSchoolWeixin() {
		if (SchoolWxDefine == null) {
			synchronized (ParamHelper.class) {
				if (SchoolWxDefine == null) {
					SchoolWxDefine = WeiXinUtil.getWxDefine(SchoolWeixinAppId);
				}
			}
		}
		return SchoolWxDefine;
	}

	private static Map<String, List<FrameParam>> paramMap = null;

	/**********************
	 * 初始化参数信息
	 */
	public static void instanceParams(boolean refresh) {
		if (paramMap == null || refresh) {
			synchronized (ParamHelper.class) {
				paramMap = new HashMap<String, List<FrameParam>>();
				// 全局的
				paramMap.put(ArtParamType.Gobal, new ArrayList<FrameParam>());
				for (FrameParam p : AppHelper.FrameParamArray) {
					paramMap.get(ArtParamType.Gobal).add(p);
				}
				BeanHelper.setStaticFields(ParamHelper.class, AppHelper.GobalParamMap);
			}
		}

	}

	/**********************
	 * 获取某一类型的所有参数
	 * 
	 * @param param_type
	 *            参数类型
	 * @return
	 */
	public static List<FrameParam> listParams(String param_type) {
		instanceParams(false);
		if (paramMap.containsKey(param_type))
			return paramMap.get(param_type);
		return new ArrayList<FrameParam>();
	}

	public static <T> T getParamValue(String param_name, T default_value) {
		return CollectionHelper.getParamValue(ParamHelper.GobalParamMap, param_name, default_value);
	}
}
