package com.xueyi.system.api.organize.feign.factory;

import com.xueyi.common.core.web.result.R;
import com.xueyi.system.api.organize.domain.dto.SysDeptDto;
import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto;
import com.xueyi.system.api.organize.feign.RemoteDeptService;
import com.xueyi.system.api.organize.feign.RemoteEnterpriseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 部门服务 降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemoteEnterpriseFallbackFactory implements FallbackFactory<RemoteEnterpriseService> {

    @Override
    public RemoteEnterpriseService create(Throwable throwable) {
        log.error("部门服务调用失败:{}", throwable.getMessage());
        return new RemoteEnterpriseService() {
            @Override
            public R<SysEnterpriseDto> getInfo(Long enterpriseId) {
                return R.fail("获取企业信息失败:" + throwable.getMessage());
            }
        };
    }
}