package com.xunmei.system.api.factory;

import com.xunmei.common.core.domain.R;
import com.xunmei.system.api.RemoteOrgService;
import com.xunmei.system.api.RemoteSyncOrgAndUserService;
import com.xunmei.system.api.domain.SysOrg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

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

    @Override
    public RemoteSyncOrgAndUserService create(Throwable throwable)
    {
        log.error("同步服务调用失败:{}", throwable.getMessage());
        return new RemoteSyncOrgAndUserService()
        {
            @Override
            public R<Boolean> syncOrgAndUser(String source) {
                return R.fail("同步机构、用户失败:" + throwable.getMessage());
            }
        };
    }
}
