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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

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

import com.uas.platform.b2b.erp.model.SaleForecastDown;
import com.uas.platform.b2b.erp.service.SaleForecastDownService;
import com.uas.platform.b2b.service.PurchaseForecastOrderService;


/**
 * 对卖家ERP的数据接口
 * 
 * @author shenj
 *
 */
@Controller
@RequestMapping("/erp/sale/forecastDown")
public class SaleForecastDownController {

	@Autowired
	private SaleForecastDownService saleForecastDownService;

	@Autowired
	private PurchaseForecastOrderService purchaseForecastOrderService;
	/**
	 * 卖家ERP从平台获取未回复的订单
	 * 
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public List<SaleForecastDown> getOrders() {
		return saleForecastDownService.convertPurchaseForecastDown(purchaseForecastOrderService.findNotUploadOrder());
	}
	
	
	/**
	 * 平台的结案、反结案客户采购单传到供应商ERP之后，修改平台里面的上传状态
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	public void onEndDownSuccess(@RequestParam("data") String data) throws UnsupportedEncodingException {
		purchaseForecastOrderService.onEndDownSuccess(URLDecoder.decode(data, "UTF-8").split(","));
	}
}
