package org.jeecg.common.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;

import java.lang.ref.ReferenceQueue;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;

/**
 * @author fenghaifu
 * @version V1.0
 * @Copyright: 上海萃颠信息科技有限公司. All rights reserved.
 * @Title:ProductAuthUtil
 * @projectName jeecg-boot
 * @Description:TODO
 * @date: 2020/7/5 20:35
 * @updatehistory: 2020/7/5 20:35 新增
 */
public class ProductAuthUtil {

	private static boolean isValid = false;
	private static Calendar validDate = DateUtils.getCalendar();
	private static int VALID_HOUR = 24;
	/**
	 * 验证设备
	 * @return
	 */
	public static boolean verify(){
		if (isValid && DateUtils.dateDiff('h', DateUtils.getCalendar(), validDate)<VALID_HOUR){
			return true;
		}
		JSONObject reqParam = new JSONObject();
		reqParam.put("productionCode", "FB896F1965907B9A9ED1BB2F0629A9C7");
		reqParam.put("computerInfo", JSON.toJSONString(HardwareUtil.get()));
		String respParam = HttpUtils.sendPost("http://renzheng.cuidiansoft.com:8011/cuidian/pa/device/verify", JSON.toJSONString(reqParam), true);
		JSONObject respObject = JSON.parseObject(respParam);
		boolean success =  respObject.getBoolean("success");
		if (success){
			isValid = true;
			validDate = DateUtils.getCalendar();
		}else{
			isValid = false;
		}

		return success;
//		isValid = true;
//		validDate = DateUtils.getCalendar();
//		return true;
	}
}
