package com.chinacreator.video.restful.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.restful.bean.ShopInObject;
import com.chinacreator.video.restful.bean.ShopOutObject;
import com.chinacreator.video.restful.service.PointShopService;
import com.chinacreator.video.restful.util.JsonUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.n3.ecs.open.util.HMACUtil;
import com.n3.ecs.open.util.SignUtil;

@RestController
@RequestMapping(value = "/point")
public class PointShopController {
	
	private static Logger logger = Logger.getLogger(PointShopController.class);
	
	private static Logger log = Logger.getLogger("pointshop");
	
	@Autowired
	private PointShopService service;
	
	/**
	 * POST方式办理业务
	 * @param inputObj
	 * @param request
	 * @return
	 * @throws Exception 
	 */
    @RequestMapping(value = "/busi", method = RequestMethod.POST, produces = "application/json")
    public String order(@RequestBody ShopInObject inputObj, HttpServletRequest request) throws Exception {
    	ShopOutObject outputObj = new ShopOutObject();
    	String inputParams = "";
    	String outputParams = "";
    	try {
        	inputParams = JSON.toJSONString(inputObj); //输入参数
        	outputObj = service.busiOper(inputObj);
        	outputParams = JSON.toJSONString(outputObj);
            return JSON.toJSONString(outputObj);
		} catch (Exception e) {
			e.printStackTrace();
			if(e instanceof BussinessException) {
				throw e;
			}else {
				throw new BussinessException("8003", "出现异常，"+e.getMessage());
			}
		} finally {
			//发送短信
			log.info(outputObj.getRequestId()+", inputObj=>"+inputParams);
			log.info(outputObj.getRequestId()+", outputObj=>"+outputParams);
		}

    }
    
    /**
     * GET方式办理业务
     * @param param
     * @param request
     * @return
     */
/*    @RequestMapping(value = "/qryOrder/{param}", method = RequestMethod.GET, produces = "application/json")
    public String qryOrder(@PathVariable String param, HttpServletRequest request) {
        System.out.println("开始新增..."+param);
        String paramLocal = param;
        try {
        	paramLocal = URLDecoder.decode(paramLocal, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("",e);
        }
        
        ShopInObject inputObj = JsonUtil.convertJson2Object(paramLocal, ShopInObject.class);
        System.out.println(inputObj.getServiceCode());
        System.out.println("paramLocal=>"+paramLocal);
        Enumeration enumeration = request.getParameterNames();
        while(enumeration.hasMoreElements()){
        	Object obj = enumeration.nextElement();
        	System.out.println(obj);
        }
        return JSON.toJSONString(inputObj);
    }*/
}
