package cn.superdesk.uniorder.openapi.service.qchjc.invoice;

import cn.superdesk.uniorder.common.exception.OpenApiException;
import cn.superdesk.uniorder.dubbo.facade.thirdpart.qchjc.invoice.DubboQchjcSupplierInvoiceService;
import cn.superdesk.uniorder.openapi.api._thirdpart.qchjc._dto.invoice.QchjcSupplierInvoiceDto;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.lang.reflect.UndeclaredThrowableException;

/**
 * @author xc
 * @description
 * @date 2022/4/1 20:11
 */
@Slf4j
@Service
public class SupplierInvoiceService {

    @Reference(version = "1.0.0", timeout = 300000, retries = -1)
    private DubboQchjcSupplierInvoiceService dubboQchjcSupplierInvoiceService;

    public void receive(QchjcSupplierInvoiceDto dto) {
        try {
            //保存到中间表-待入库状态
            dubboQchjcSupplierInvoiceService.receive(JSON.toJSONString(dto));
        } catch (UndeclaredThrowableException e) {
            Throwable cause = e.getUndeclaredThrowable().getCause();
            if (cause instanceof OpenApiException) {
                throw (OpenApiException) cause;
            } else {
                throw e;
            }
        }
    }

}
