package com.bonus.system.api.factory;

import com.bonus.common.core.domain.R;
import com.bonus.system.api.RemoteTcpService;
import com.bonus.system.api.domain.SysTcpMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * tcp服务降级处理
 *
 * @author bonus
 */
@Component
public class RemoteTcpFallbackFactory implements FallbackFactory<RemoteTcpService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteTcpFallbackFactory.class);

    @Override
    public RemoteTcpService create(Throwable throwable) {
        log.error("tcp服务调用失败:{}", throwable.getMessage());
        return new RemoteTcpService() {
            @Override
            public R setMessage(SysTcpMessage sysTcpMessage, String source) {
                return R.fail("近电感应设备设置失败:" + throwable.getMessage());
            }
        };
    }
}
