package com.bonus.system.api.factory;

import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.system.api.RemoteProfileService;
import com.bonus.system.api.domain.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

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

    @Override
    public RemoteProfileService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteProfileService()
        {
            @Override
            public AjaxResult profile(String source) {
                return AjaxResult.error("获取当前登录用户个人信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult updateProfile(SysUser user, String source) {
                return AjaxResult.error("修改当前登录用户个人信息失败:" + throwable.getMessage());
            }
        };
    }
}
