package com.yanzhu.system.api.factory;

import com.yanzhu.system.api.RemoteUserService;
import com.yanzhu.system.api.domain.SysUserUniopen;
import com.yanzhu.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.yanzhu.common.core.domain.R;
import com.yanzhu.system.api.domain.SysUser;

import java.util.List;
import java.util.Map;

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

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<Map<String,Object>> getMaOpenId(String code, String source)
            {
                return R.fail("获取小程序授权失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUserUniopen> findByMaOpenId(String maOpenId, String source)
            {
                return R.fail("查询小程序授权失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfo(String username, Long deptId, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getSysUserInfo(Long userId, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> updateUserInfo(SysUser sysUser, String source) {
                return R.fail("修改用户失败:" + throwable.getMessage());
            }
        };
    }
}
