package com.hw.printer.api.factory;

import com.hw.common.core.domain.R;

import com.hw.common.core.exception.ServiceException;
import com.hw.printer.api.RemotePrinterService;
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 打印机服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemotePrinterFallbackFactory implements FallbackFactory<RemotePrinterService> {
    private static final Logger log = LoggerFactory.getLogger(RemotePrinterFallbackFactory.class);

    @Override
    public RemotePrinterService create(final Throwable throwable) {
        log.error("打印条码服务调用失败:{}", throwable.getMessage());
        return new RemotePrinterService() {
            @Override
            public MesBaseBarcodeInfo printBarCode(MesBaseBarcodeInfo barcodeInfo, String source) {
                throw new ServiceException("打印条码服务调用异常:" + throwable.getMessage());
            }
        };
    }
}
