package com.securitycontrol.system.api.factory;

import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.system.api.RemoteSourceService;
import com.securitycontrol.system.api.domain.TbSourceFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 资源文件
 * 降级服务
 *
 * @author czc
 */
@Component
public class RemoteSourceFallbackFactory implements FallbackFactory<RemoteSourceService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteSourceFallbackFactory.class);


    @Override
    public RemoteSourceService create(Throwable throwable) {
        log.error("资源文件服务调用失败:{}", throwable.getMessage());
        return new RemoteSourceService(){

            @Override
            public Result<List<TbSourceFile>> getSourceFile(String sourceId, String sourceType, String source) {
                return Result.fail("第三方文件资源服务调用失败:" + throwable.getMessage());
            }
        };
    }


}
