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

import java.util.List;

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.PurchaseNotice;
import com.uas.platform.b2b.history.model.SaleSendItem;
import com.uas.platform.b2b.history.service.PurchaseNoticeService;
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.SaleNoticeController")
@RequestMapping("/sale/notice/history")
public class SaleNoticeController {

	@Autowired
	private PurchaseNoticeService purchaseNoticeService;

	/**
	 * 作为卖家，收到的送货提醒
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public Page<PurchaseNotice> getReceivedPurchaseNotices(PageParams params) {
		PageInfo info = new PageInfo(params);
		// 我作为卖家，把我的企业ID作为供应商ID传入
		info.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
		return purchaseNoticeService.findAllByPageInfo(info);
	}

	/**
	 * 作为卖家，收到的送货提醒，对应id
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	@ResponseBody
	public PurchaseNotice getReceivedPurchaseNoticeById(@PathVariable("id") Long id) {
		return purchaseNoticeService.findById(id);
	}

	/**
	 * 作为卖家，收到的送货提醒，对应id
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/{id}/sendItems", method = RequestMethod.GET)
	@ResponseBody
	public List<SaleSendItem> getSendItemsNoticeById(@PathVariable("id") Long id) {
		return purchaseNoticeService.findSendById(id);
	}

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

}
