package com.yanzhu.system.api.factory;

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

/**
 * 部门服务降级处理
 *
 * @author JiangYuQi
 */
@Component
public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteDeptFallbackFactory.class);

    @Override
    public RemoteDeptService create(Throwable throwable) {
        log.error("部门服务调用失败:{}", throwable.getMessage());
        return new RemoteDeptService() {
            @Override
            public R<SysDept> getDeptInfo(Long deptId, String source) {
                return R.fail("获取部门失败:" + throwable.getMessage());
            }
        };
    }
}
