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

import com.prolog.cs.biz.outbound.model.vo.ReceiveDoBillVO;
import com.prolog.cs.biz.outbound.model.vo.ReceiveInvoiceVO;
import com.prolog.cs.biz.outbound.service.IOmsDoBillHService;
import com.prolog.cs.biz.outbound.service.InvoicePdfService;
import com.prolog.framework.common.message.RestMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;

@Api(tags = "erp-wms下传出库单")
@RestController
@RequestMapping("/erp-outRequest")

public class ErpController {

    @Autowired
    private IOmsDoBillHService iOmsDoBillHService;
    @Autowired
    private InvoicePdfService invoicePdfService;

    @ApiOperation(value = "保存出库单-提供给erp下发出库单，接口平台调用")
    @PostMapping("/receiveDoBill")
    public RestMessage<Boolean> receiveDoBill(@RequestBody List<ReceiveDoBillVO> receiveDoBillVOS) {
        Boolean result = iOmsDoBillHService.receiveDoBill(receiveDoBillVOS);
        return RestMessage.doSuccess(result);
    }

    @ApiOperation(value = "定时任务调用-波次下发完成后进行出库单开票通知(wms-erp)")
    @PostMapping("/stockOutInvoice")
    public RestMessage<String> stockOutInvoice() {
        try {
            iOmsDoBillHService.stockOutInvoice();
        } catch (Exception e) {
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
        return RestMessage.newInstance(true, "执行成功", null);
    }

    @ApiOperation(value = "定时任务调用-处理直通出库任务（更改任务状态及生成barcode数据）")
    @PostMapping("/autoCheckZtBill")
    public RestMessage<String> autoCheckZtBill() {
        try {
            iOmsDoBillHService.autoCheckZtBill();
        } catch (Exception e) {
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
        return RestMessage.newInstance(true, "执行成功", null);
    }

    @ApiOperation(value = "保存发票-提供给erp同步发票，接口平台调用")
    @PostMapping("/receiveInvoice")
    public RestMessage<Boolean> receiveInvoice(@RequestBody ReceiveInvoiceVO vo) {
        invoicePdfService.receiveInvoice(vo);
        return RestMessage.doSuccess(null);
    }

}
