package com.cku.controller;

import java.io.IOException;

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.PageBeanResult;
import com.cku.core.RESTResponse;
import com.cku.model.CkuOrderInfo;
import com.cku.model.OrderDetilInfo;
import com.cku.service.OrderServiceImpl;
import com.cku.util.PageBean;
import com.cku.util.ServletUtils;
import com.sys.service.TokenService;

/**
 *user chaixueteng
 *2016年4月14日
 */
@Controller
@RequestMapping(value="sys-api/order")
public class MyOrderController {
	

	
	@Autowired
	public OrderServiceImpl  orderServiceImpl;
	/**
	 * 根据当前登录人,订单状态查询我的订单中所有的订单
	 */
	@RequestMapping(value="/getOrderList")
	public void getOrderList(HttpServletResponse response,HttpServletRequest request)throws IOException{
		RESTResponse result = null;
		try {
			Long userId = UserService.verifyUserId(request);
			String payconfirm = ServletUtils.getParameter(request, "payconfirm");
			PageBean pb=ServletUtils.getParameterBean(request);
			PageBeanResult<CkuOrderInfo> list=orderServiceImpl.getOrderListByCkuId(new Long(userId).intValue(), payconfirm,pb);
			result=new RESTResponse("items",list);
		
		} catch (Exception e) {
			result = new RESTResponse(e);
			e.printStackTrace();
		}
		ServletUtils.writeResponse(response, result);
	}
	
	/**
	 * 根据订单号,查询订单详细信息
	 */
	@RequestMapping(value="/getOrderMessage")
	public void getOrderMessage(HttpServletResponse response,HttpServletRequest request)throws IOException{
		RESTResponse result=null;
		try {
			String orderId = ServletUtils.getParameter(request, "orderId");
			Integer typeId = ServletUtils.getParameterInt(request, "typeId");
			OrderDetilInfo orderDetilInfo=orderServiceImpl.getOrderDetil(orderId,typeId);
			result=new RESTResponse("items",orderDetilInfo);
		} catch (Exception e) {
			result = new RESTResponse(e);
			e.printStackTrace();
		}
		ServletUtils.writeResponse(response, result);
	}
	
}
