package com.reptileclient.jlifeapp.schedule;

import com.reptileclient.jlifeapp.config.SendSms;
import com.reptileclient.jlifeapp.constant.HemaConstant;
import com.reptileclient.jlifeapp.constant.JlifeConstant;
import com.reptileclient.jlifeapp.dao.hm.HmTokenMapper;
import com.reptileclient.jlifeapp.entity.hm.HmToken;
import com.reptileclient.jlifeapp.service.HmSalesOrderService;
import com.reptileclient.jlifeapp.util.DateUtils;
import com.reptileclient.jlifeapp.util.HttpUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

/**
 *  token超时处理通知
 * @author lu
 *
 */
@Component
public class NoticeTokenTask {
	

	private static final Logger logger = LoggerFactory.getLogger(NoticeTokenTask.class);
	
	@Autowired
	HmSalesOrderService hmSalesOrderService;
	
	@Autowired
	HmTokenMapper hmtk;
	
	@Autowired
	SendSms sms;

	@Scheduled(cron = "0 0 8-22 * * ?") // 每天8到22点每小时执行一次
	public void runTask() {
		
		
		logger.info("开始  验证token.........................");
		try {
			HmToken hm = hmtk.selectAll();
//			String resultData = HttpUtil.requestGet(hm.getToken(), "{}", JlifeConstant.HM_STATION);
			
			String parmJson =HemaConstant.test_parm;
			Map<String, Object> request = HttpUtil.request(hm.getToken(), parmJson, HemaConstant.HEMADATA_LYSJYJXS_URL);
			
			logger.info("接口返回信息："+request);
			if (request.get("success").toString().equals("true")) {
				
			}else {
				//失败处理发短信
				sms.toSendMs();
			}
			
		} catch (Exception e) {
			sms.toSendMs();
			e.printStackTrace();
			
		}
		
		

	}

	 
	 

}
