package com.prolog.cs.biz.inbound.controller.erp;

import com.prolog.cs.biz.inbound.dto.ReceiveAsnDTO;
import com.prolog.cs.biz.inbound.service.OmsAsnBillDService;
import com.prolog.cs.biz.inbound.service.rcv.RcvInstockLinesService;
import com.prolog.framework.common.message.RestMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "erp-wms下发订单")
@RestController
@RequestMapping("/erp-request")
public class ErpController {

	@Resource
	private OmsAsnBillDService asnService;

	@Resource
	private RcvInstockLinesService rcvInstockLinesService;

	@ApiOperation("保存入库单-提供给erp下发入库单，接口平台调用")
	@PostMapping("/receiveAsn")
	public RestMessage<Object> saveAsnBillByOms(@RequestBody List<ReceiveAsnDTO> saveDTOs) {
		asnService.saveAsnBill(saveDTOs);
		return RestMessage.newInstance(true, "保存成功", null);
	}


	@ApiOperation("回传erp入库单-单据上架完成后，接口平台定时任务调用")
	@PostMapping("/returnInboundAsn")
	public RestMessage<String> returnInboundAsnTask() {
		try {
			rcvInstockLinesService.autoOmsIncomingBackTask();
		} catch (Exception e) {
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
		return RestMessage.newInstance(true, "执行成功", null);
	}

}
