package com.yanzhu.system.api.factory;

import com.yanzhu.common.core.domain.R;
import com.yanzhu.system.api.RemoteFlowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

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

    @Override
    public RemoteFlowService create(Throwable throwable)
    {
        log.error("业务服务调用失败:{}", throwable.getMessage());
        return new RemoteFlowService()
        {
            @Override
            public R<Long> addSubdeptsEntity(Map<String, Object> data, String source)
            {
                return R.fail("保存分包单位信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> addSubdeptsGroupEntity(Map<String, Object> data, String source)
            {
                return R.fail("保存分包单位班组信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> addSubdeptsUsersEntity(Map<String, Object> data, String source)
            {
                return R.fail("保存分包单位班组用户信息失败:" + throwable.getMessage());
            }
        };
    }
}
