package com.ruoyi.ext.api.factory;

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

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

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