package com.cku.controller;

import java.io.IOException;

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

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

import com.cab.service.UserService;
import com.cku.core.RESTResponse;
import com.cku.model.CkuOrder;
import com.cku.service.CkuDogEnteredServiceImpl;
import com.cku.util.ServletUtils;

@Controller
@RequestMapping("dog/entered")
public class CkuDogEnteredController {
	
	@Autowired
	private CkuDogEnteredServiceImpl ckuDogEnteredService;
	
	/**
	 * 
	 * @Description：犬只赛事报名
	 * @author: zhuoHeng
	 * @version: 2016年4月19日 上午10:00:53
	 */
	@RequestMapping("/generateOrder")
	public void dogEventEntered(HttpServletRequest request,HttpServletResponse response) throws IOException{
		RESTResponse result = null;
		try
		{
			Long userId =UserService.verifyUserId(request);
			String showNums = ServletUtils.getParameter(request, "showNums");
			String pedigreeNum = ServletUtils.getParameter(request, "pedigreeNum");
			String detil = ServletUtils.getParameter(request, "detil");
			String ageGroup = ServletUtils.getParameter(request, "ageGroup",null);
			CkuOrder ckuOrderInfo = ckuDogEnteredService.dogEventEntered(userId,showNums,pedigreeNum,detil,ageGroup);
			result = new RESTResponse("item", ckuOrderInfo);
		}
		catch (Exception e)
		{
			result = new RESTResponse(e);
		}
		
		ServletUtils.writeResponse(response, result);
	}
	
	/**
	 * 
	 * @Description：余额支付赛事费用
	 * @author: zhuoHeng
	 * @version: 2016年4月20日 上午10:18:27
	 */
	@RequestMapping("/eventBalancePayment")
	public void eventBalancePayment(HttpServletRequest request,HttpServletResponse response) throws IOException{
		RESTResponse result = null;
		try
		{
			Long userId =UserService.verifyUserId(request);
			String orderID = ServletUtils.getParameter(request, "orderID");
			String pid = ServletUtils.getParameter(request, "pid");
			String payPsw = ServletUtils.getParameter(request,"payPsw");
			String dynamic = ServletUtils.getParameter(request,"dynamic");
			ckuDogEnteredService.eventBalancePayment(userId,orderID,pid,payPsw,dynamic);
			result = new RESTResponse();
		}
		catch (Exception e)
		{
			result = new RESTResponse(e);
		}
		
		ServletUtils.writeResponse(response, result);
	}
	
	/**
	 * 
	 * @Description：赛事报名取消订单
	 * @author: zhuoHeng
	 * @version: 2016年4月21日 上午11:56:34
	 */
	@RequestMapping("cancelTheOrder")
	public void  cancelTheOrder(HttpServletRequest request,HttpServletResponse response) throws IOException{
		RESTResponse result = null;
		try
		{
			Long userId =UserService.verifyUserId(request);
			String orderID = ServletUtils.getParameter(request, "orderId");
			ckuDogEnteredService.cancelTheOrder(userId,orderID);
			result = new RESTResponse();
		}
		catch (Exception e)
		{
			result = new RESTResponse(e);
		}
		
		ServletUtils.writeResponse(response, result);
	}

}
