package com.chinacreator.video.web;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chinacreator.video.util.URLUtil;
import com.chinacreator.video.annotation.Log;
import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.dto.DataOutPipe;
import com.chinacreator.video.dto.IncrDataOutPipe;
import com.chinacreator.video.mapper.DictionaryDao;
import com.chinacreator.video.service.HandleService;


@RestController
public class TestControl {
	
	 private static Logger logger = Logger.getLogger(TestControl.class);

	@Autowired
	private DictionaryDao dictionaryDao;
	
	@Log
	@RequestMapping("/testhandle")
	public DataOutPipe<?> hand(OrderInfo orderInfo) throws Exception {
		IncrDataOutPipe outpipe = new IncrDataOutPipe();
		String userid = orderInfo.getUserid();
		return outpipe;
	}
	
	/**
	 * 调VAC接口查询订购信息
	 * @param orderInfo
	 * @param spInfo
	 * @param cpInfo
	 * @return
	 * @throws Exception
	 */
	private String qryVac(OrderInfo orderInfo)throws Exception{
		String result = "-1";
		logger.info("***********进入订购关系判断*************");
		try {
			String url = dictionaryDao.getValue("vacQuery");
			//外网地址
			//url = "http://127.0.0.52:9999/vacquery/vacQuery.do";
			url = url+"?userId="+orderInfo.getUserid();
					
			String resultstr = URLUtil.get(url);
			//String resultstr = "{\"errorinfo\":\"\",\"orderItems\":[{\"coreId\":\"\",\"da\":\"18672686569\",\"daType\":0,\"effectiveTime\":\"20190312095737\",\"expireTime\":\"20501231235959\",\"fa\":\"\",\"faType\":0,\"id\":\"8000610900\",\"idType\":0,\"oa\":\"18672686569\",\"oaType\":0,\"resumeTime\":\"\",\"status\":0,\"subscribeTime\":\"20190312095747\",\"suspendTime\":\"\"},{\"coreId\":\"\",\"da\":\"18672686569\",\"daType\":0,\"effectiveTime\":\"20150701000000\",\"expireTime\":\"20501231235959\",\"fa\":\"\",\"faType\":0,\"id\":\"3100008300\",\"idType\":0,\"oa\":\"18672686569\",\"oaType\":0,\"resumeTime\":\"\",\"status\":0,\"subscribeTime\":\"20150701072816\",\"suspendTime\":\"\"},{\"coreId\":\"\",\"da\":\"18672686569\",\"daType\":0,\"effectiveTime\":\"20180601000000\",\"expireTime\":\"20501231000000\",\"fa\":\"\",\"faType\":0,\"id\":\"7000000200\",\"idType\":0,\"oa\":\"18672686569\",\"oaType\":0,\"resumeTime\":\"\",\"status\":0,\"subscribeTime\":\"20180527085644\",\"suspendTime\":\"\"},{\"coreId\":\"\",\"da\":\"18672686569\",\"daType\":0,\"effectiveTime\":\"20180601000000\",\"expireTime\":\"20501231000000\",\"fa\":\"\",\"faType\":0,\"id\":\"8200001100\",\"idType\":0,\"oa\":\"18672686569\",\"oaType\":0,\"resumeTime\":\"\",\"status\":0,\"subscribeTime\":\"20180527085644\",\"suspendTime\":\"\"}],\"resultCode\":0}";
			logger.info("查询返回信息=====>"+resultstr);
			JSONObject json = JSONObject.fromObject(resultstr);
			if (json.getString("resultCode").equals("0")) {
				JSONArray jsons = json.getJSONArray("orderItems");
				for (int i = 0; i < jsons.size(); i++){
					//logger.debug("++++++++++++++++++"+jsons.getJSONObject(i).get("id"));
					//if("8000610900".equals(jsons.getJSONObject(i).get("id"))){

						//orderInfo.setOrdertime(jsons.getJSONObject(i).get("effectiveTime").toString());
						//orderInfo.setEffecttime(jsons.getJSONObject(i).get("effectiveTime").toString());
		
					
				}
			}
			logger.info("***************"+(result.equals("1")?"vac无订购关系":"vac有订购关系"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
