package com.bonus.system.api.factory;

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


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

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

            @Override
            public AjaxResult list(SysDept dept, String source){
                return AjaxResult.error("获取部门列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getInfo(Long deptId, String source){
                return AjaxResult.error("根据部门编号获取部门失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult add(SysDept dept, String source){
                return AjaxResult.error("添加部门失败:" + throwable.getMessage());
            }


            @Override
            public AjaxResult edit(SysDept dept, String source){
                return AjaxResult.error("修改部门失败:" + throwable.getMessage());
            }


            @Override
            public AjaxResult remove(Long deptId, String source){
                return AjaxResult.error("删除部门失败:" + throwable.getMessage());
            }
        };
    }
}
