package com.chinacreator.process.util;

import com.chinacreator.common.support.util.SpringContextUtil;
import com.chinacreator.common.util.URLUtil;
import com.chinacreator.process.bean.VacOrder;
import com.chinacreator.process.dao.DictionaryDao;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * <p>Description: 调用vac工具类</p>
 * <p>Copyright: Copyright (c) 2013</p>
 * <p>Company: Chinacreator（长沙科创集成）</p>
 * <p>creationTime: 2013-4-12</p>
 * @author  
 * @version 1.0
 */
public class VacUtil {





	
	/**
	 * 调用vac接口，vac接口调用地址，由字典表配置
	 * @param userId 手机号码
	 * @param spCode sp编码
	 * @param productId 产品标识
	 * @param type 1表示包月订购，2表示退订，0：单次订购
	 * @return
	 */
	public static String vac(String userId,String spCode, String productId,String type) throws Exception{
		DictionaryDao dictionaryDao = SpringUtils.getBean(DictionaryDao.class);
		String vacUrl = dictionaryDao.getValue("vacUrl");
		if(vacUrl.indexOf("?") == -1) {
			vacUrl += "?";
		} else {
			vacUrl += "&";
		}
		vacUrl += "usermob=" + userId;
		vacUrl += "&productid=" + productId;
		vacUrl += "&vacid=" + productId;
		vacUrl += "&spcode=" + spCode;
		vacUrl += "&ordertype=" + type;
		vacUrl += "&servicetype=80";
		return  URLUtil.get(vacUrl);
	}
	
	public static VacOrder query(String userid) throws Exception {
		DictionaryDao dictionaryDao = SpringContextUtil.getBean(DictionaryDao.class);
		String url = dictionaryDao.getValue("vacQuery");
		if(url.indexOf("?") == -1) {
			url += "?";
		} else {
			url += "&";
		}
		url += "userId=" + userid;
		String result = URLUtil.get(url);
		Gson gson = new GsonBuilder().serializeNulls().create();
		VacOrder vacOrder = gson.fromJson(result, VacOrder.class);
		return vacOrder;
	}
}
