package cn.superdesk.uniorder.openapi.api._thirdpart.qchjc.invoice;

import cn.superdesk.uniorder.openapi.annotation.QchjcRequestLog;
import cn.superdesk.uniorder.openapi.api._thirdpart.qchjc._dto.invoice.QchjcCustomerInvoiceDto;
import cn.superdesk.uniorder.openapi.api.base.O;
import cn.superdesk.uniorder.openapi.config.exception.ParameterNotValidException;
import cn.superdesk.uniorder.openapi.service.qchjc.invoice.CustomerInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author xc
 * @description
 * @date 2022/3/31 15:02
 */
@Api(value = "thirdpart-qchjc-invoice-customer", tags = {"thirdpart-qchjc-invoice-customer"})
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/v0/thirdpart/qchjc/invoice/customer")
public class CustomerInvoiceRestApi {

    private final CustomerInvoiceService customerInvoiceService;


    @ApiOperation(value = "采购单位发票单接收")
    @RequestMapping(value = "/receive", method = RequestMethod.POST)
    @ResponseBody
    @QchjcRequestLog(value = "采购单位发票单接收")
    public O<QchjcCustomerInvoiceDto> invoiceReceive(@RequestBody @Validated QchjcCustomerInvoiceDto dto, BindingResult result) {

        if (result.hasErrors()) {
            throw new ParameterNotValidException(result);
        }

        //log.info("receive qchjc customer invoice apply, param : {}", JSON.toJSONString(dto));
        customerInvoiceService.receive(dto);

        return new O<QchjcCustomerInvoiceDto>()
                .setResultCode(200)
                .setResultMessage("同步成功")
                .setSuccess(true);
    }
}
