package com.usky.system.factory;


import com.usky.common.core.bean.ApiResult;
import com.usky.system.RemoteUserService;
import com.usky.system.domain.SysUser;
import com.usky.system.domain.SysUserVO;
import com.usky.system.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@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 ApiResult<LoginUser> getUserInfo(String username)
            {
                return ApiResult.error("500","获取用户失败:" + throwable.getMessage());
            }

            @Override
            public ApiResult<Boolean> registerUserInfo(SysUserVO sysUser)
            {
                return ApiResult.error("500","注册用户失败:" + throwable.getMessage());
            }

            @Override
            public ApiResult<List<SysUser>> userList() {
                return ApiResult.error("500","获取用户信息:" + throwable.getMessage());
            }

            @Override
            public ApiResult<List<SysUser>> userByIdList(List<Integer> userIds) {
                return ApiResult.error("500","获取用户信息:" + throwable.getMessage());
            }

            @Override
            public ApiResult<List<SysUser>> userAllList() {
                return ApiResult.error("500","获取所有用户信息:" + throwable.getMessage());
            }
        };
    }
}
