package com.ruoyi.ext.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.ext.api.RemoteDictDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 字典服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteDictDataFallbackFactory implements FallbackFactory<RemoteDictDataService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteDictDataFallbackFactory.class);

    @Override
    public RemoteDictDataService create(Throwable throwable)
    {
        log.error("字典服务调用失败:{}", throwable.getMessage());
        return new RemoteDictDataService()
        {
            @Override
            public AjaxResult getDictDataByDictType(String dictType, String source) {
                return AjaxResult.error("获取字典失败:" + throwable.getMessage());
            }
        };
    }
}
