package com.uas.platform.b2b.history.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uas.platform.b2b.history.model.PurchaseInquiry;
import com.uas.platform.b2b.history.model.PurchaseInquiryItem;
import com.uas.platform.b2b.history.service.PurchaseInquiryService;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.PageInfo;
import com.uas.platform.core.model.PageParams;
import com.uas.platform.core.model.Status;
import com.uas.platform.core.web.bind.RequestState;

/**
 * 卖家对询价单的操作（历史数据）
 * 
 * @author yingp
 * 
 */
@Controller("history.SaleInquiryController")
@RequestMapping("/sale/inquiry/history")
public class SaleInquiryController {

	@Autowired
	private PurchaseInquiryService purchaseInquiryService;

	/**
	 * 作为卖家，收到的采购询价（全部）
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public Page<PurchaseInquiryItem> getReceivedPurchaseInquiries(PageParams params) {
		PageInfo info = new PageInfo(params);
		// 我作为卖家，把我的企业ID作为供应商ID传入
		info.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
		return purchaseInquiryService.findAllByPageInfo(info);
	}

	/**
	 * 作为卖家，收到的采购询价（待回复）
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping(params = RequestState.TODO, method = RequestMethod.GET)
	@ResponseBody
	public Page<PurchaseInquiryItem> getTodoInquiries(PageParams params) {
		PageInfo info = new PageInfo(params);
		// 询价单状态为未回复
		info.filter("status", Status.NOT_REPLY.value());
		// 我作为卖家，把我的企业ID作为供应商ID传入
		info.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
		return purchaseInquiryService.findAllByPageInfo(info);
	}

	/**
	 * 作为卖家，收到的采购询价明细
	 * 
	 */
	@RequestMapping(value = "/items/{inquiryItemId}", method = RequestMethod.GET)
	@ResponseBody
	public PurchaseInquiryItem getInquiryItemById(@PathVariable("inquiryItemId") Long inquiryItemId) {
		return purchaseInquiryService.findItemByItemId(inquiryItemId);
	}

	/**
	 * 作为卖家，根据询价单ID查找询价单(含明细)
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	@ResponseBody
	public PurchaseInquiry getReceivedPurchaseOrderItemById(@PathVariable("id") Long id) {
		return purchaseInquiryService.findById(id);
	}

}
