package com.iamberry.wechat.handles.wechat.config;

import java.io.IOException;
import java.util.concurrent.Executors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.iamberry.wechat.face.wechat.ConfigService;
import com.iamberry.wechat.tools.NameUtils;
/**
 * description ： 分享的业务处理 
 * @author 何秀刚
 * create date：2016年2月25日
 */
@Controller
@RequestMapping("/config")
public class ConfigHandler {
	
	@Autowired
	private ConfigService configService;
	public void setConfigService(ConfigService configService) {
		this.configService = configService;
	}
	
	@RequestMapping(value="/get", method=RequestMethod.GET)
	public void getConfig(HttpServletRequest request, HttpServletResponse response) throws IOException{
		// 如果数据不为空,拼装数据
		String appid = NameUtils.getConfig("appId"), url = request.getParameter("url");
		if(appid ==null || url ==null){
			return;
		}

		// 拼装数据
		JSONObject json = configService.selectConfig(appid, url);
		if(json == null){
			return;
		}
		response.getWriter().write(json.toString());
		response.getWriter().close();
	}
}
