package com.bonus.system.api.factory;

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

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

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

            @Override
            public AjaxResult list(SysMenu menu, String source) {
                return AjaxResult.error("根据条件获取菜单列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getInfo(Long menuId, String source) {
                return AjaxResult.error("根据ID获取菜单信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult treeselect(SysMenu menu, String source) {
                return AjaxResult.error("根据条件获取菜单树失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult roleMenuTreeselect(Long roleId, String source) {
                return AjaxResult.error("根据角色ID获取菜单树失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult add(SysMenu menu, String source) {
                return AjaxResult.error("新增菜单失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult edit(SysMenu menu, String source) {
                return AjaxResult.error("修改菜单失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getRouters(String source) {
                return AjaxResult.error("获取登录用户的菜单树失败:" + throwable.getMessage());
            }
        };
    }
}
