package com.vctgo.system.api.factory;

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

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author vctgo
 */
@Component
public class RemoteTenantFallbackFactory implements FallbackFactory<RemoteTenantService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteTenantFallbackFactory.class);

    @Override
    public RemoteTenantService create(Throwable throwable) {
        log.error("租户服务调用失败:{}", throwable.getMessage());
        return new RemoteTenantService() {

            @Override
            public R<List<SysTenant>> allTenantList() {
                return R.fail("获取租户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysTenant>> getTenantList(String sysTenant) {
                return R.fail("条件查询租户管理列表失败:" + throwable.getMessage());
            }
        };
    }
}
