package com.uas.platform.b2b.mobile.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.mobile.model.InquiryItem;
import com.uas.platform.b2b.mobile.service.InquiryItemService;
import com.uas.platform.b2b.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.persistence.criteria.PredicateUtils;

/**
 * 对移动端的数据接口<br>
 * 卖家对收到的客户采购变更单的处理
 * 
 * @author yingp
 * 
 */
@Controller("mobile.InquiryItemController")
@RequestMapping("/mobile/sale/inquiry")
public class InquiryItemController {

	@Autowired
	private InquiryItemService inquiryItemService;

	@Autowired
	private PurchaseInquiryService purchaseInquiryService;

	/**
	 * 作为卖家，收到的采购变更单
	 * 
	 * @param json
	 * @return
	 */
	@RequestMapping(value = "/items", method = RequestMethod.GET)
	@ResponseBody
	public Page<InquiryItem> getSaleInquiryItems(PageParams params, String keyword) {
		PageInfo info = new PageInfo(params);
		// 我作为卖家，把我的企业ID作为供应商ID传入
		info.expression(PredicateUtils.in("vendUU", SystemSession.getUser().getEnUUs(), false));
		return inquiryItemService.convertInquiryItem(purchaseInquiryService.findAllByPageInfo(info, keyword, null));
	}

	/**
	 * 作为卖家，根据变更单ID查找采购变更单(含明细)
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/items/{id}", method = RequestMethod.GET)
	@ResponseBody
	public InquiryItem getSaleInquiryItemInById(@PathVariable("id") Long id) {
		return inquiryItemService.convertInquiryItem(purchaseInquiryService.findItemByItemId(id));
	}

}
