package com.yanzhu.system.api.factory;

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

import java.util.List;
import java.util.Map;

/**
 * 文件服务降级处理
 * 
 * @author JiangYuQi
 */
@Component
public class RemoteProFallbackFactory implements FallbackFactory<RemoteProService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteProFallbackFactory.class);

    @Override
    public RemoteProService create(Throwable throwable)
    {
        log.error("项目服务调用失败:{}", throwable.getMessage());
        return new RemoteProService()
        {
            @Override
            public R<Map<String,Object>> info(Long id, String source)
            {
                return R.fail("查询项目失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Map<String, Object>>> getProjects(Long userId, String source)
            {
                return R.fail("获取用户项目信息失败:" + throwable.getMessage());
            }
        };
    }
}
