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

import com.prolog.common.RestMsgHelper;
import com.prolog.cs.biz.inbound.vo.CancelOrderOmsVO;
import com.prolog.cs.biz.outbound.model.OmsDoBillHDO;
import com.prolog.cs.biz.outbound.model.dto.LicenseImageDTO;
import com.prolog.cs.biz.outbound.model.dto.OmsDoBillHDTO;
import com.prolog.cs.biz.outbound.model.vo.OmsBillReceiveVo;
import com.prolog.cs.biz.outbound.service.IOmsDoBillHService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api(tags = "出库单")
@RestController
@RequestMapping("/outboundOrder")
@Validated
public class OmsDoBillHController {

    @Autowired
    private IOmsDoBillHService iOmsDoBillHService;

    @UserLog
    @ApiOperation(value = "查询出库单头")
    @PostMapping("/queryDoBillHList")
    public RestMessage<Page<OmsDoBillHDO>> queryDoBillHList(@RequestBody OmsDoBillHDO omsDoBillHDO) {
        return RestMessage.success("操作成功", iOmsDoBillHService.queryDoBillHList(omsDoBillHDO));
    }

    @UserLog
    @ApiOperation(value = "保存出库单头")
    @PostMapping("/saveDoBillH")
    public RestMessage<Boolean> saveDoBillH(@RequestBody OmsDoBillHDTO omsDoBillHDTO) {
        Boolean result = iOmsDoBillHService.saveDoBillH(omsDoBillHDTO);
        return RestMessage.doSuccess(result);
    }

    @ApiOperation(value = "保存出库单头")
    @PostMapping("/oms/bill/receive")
    public RestMessage<Boolean> receiveOmsBill(@RequestBody List<OmsBillReceiveVo> omsBillReceiveVoList) {
        Boolean result = iOmsDoBillHService.receiveOmsBill(omsBillReceiveVoList);
        return RestMessage.doSuccess(result);
    }

    @UserLog
    @ApiOperation(value = "批量查询OMS订单信息")
    @PostMapping("/getDoBillHByBillNos")
    public RestMessage<List<OmsDoBillHDO>> getDoBillHByBillNos(@Valid @NotEmpty(message = "billNos不能为空") @RequestParam("billNos") String[] billNos, @Valid @NotBlank(message = "warehouseId不能为空") @RequestParam("warehouseId") String warehouseId) {
        return RestMessage.success("操作成功", iOmsDoBillHService.getDoBillHByBillNos(billNos, warehouseId));
    }

    /**
     * 取消asn单
     */
    @UserLog("提供OMS调用取消订单")
    @ApiOperation("提供OMS调用取消订单")
    @PostMapping("/oms/bill/cancelOrderOms")
    public RestMessage<List<CancelOrderOmsVO>> cancelOrderOms(@RequestBody List<CancelOrderOmsVO> cancelList) {
        return RestMessage.doSuccess(iOmsDoBillHService.cancelOrderOms(cancelList));
    }

    /**
     * 证照图片下传
     */
    @UserLog("证照图片下传")
    @ApiOperation("提供OMS调用证照图片下传")
    @PostMapping("/oms/bill/licenseImageDownload")
    public RestMessage<List<LicenseImageDTO>> licenseImageDownload(@RequestBody List<LicenseImageDTO> imageList) {
        return iOmsDoBillHService.licenseImageDownload(imageList);
    }

    @UserLog("取消订单")
    @ApiOperation("取消订单")
    @GetMapping("/cancelBill")
    public RestMessage cancelBill(@RequestParam("billid") @Valid @NotEmpty(message = "请求参数不能为空") String billId) {
        return RestMsgHelper.run(()->iOmsDoBillHService.cancelBill(billId));
    }

    /**
     * 取消asn单
     */
    @UserLog("提供OMS调用取消订单")
    @ApiOperation("提供OMS调用取消订单")
    @GetMapping("/bill/getInvoices")
    public RestMessage<List<String>> getInvoices(@RequestParam(name = "billno") String billno) {
        return RestMessage.doSuccess(iOmsDoBillHService.getInvoices(billno));
    }
}
