package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteRocketMqService;
import com.ruoyi.system.api.domain.RmAlarmRecordRemote;
import com.ruoyi.system.api.domain.RmDeployScriptRemote;
import com.ruoyi.system.api.domain.RmMonitorPolicyRemote;
import com.ruoyi.system.api.domain.RmNetworkInterfaceRemote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

    @Override
    public RemoteRocketMqService create(Throwable throwable)
    {
        log.error("rocketMq服务调用失败:{}", throwable.getMessage());
        return new RemoteRocketMqService()
        {
            @Override
            public R<Map> sendAsyncProducerMessage(String topic, String tag, String key, String value, String source) {
                Map<String, Object> errorMap = new HashMap<>();
                errorMap.put("msg", "生产者发送消息失败");
                errorMap.put("error", throwable.getMessage());
                return R.fail(errorMap);
            }

            @Override
            public R<List<RmAlarmRecordRemote>> getAlarmList(RmAlarmRecordRemote rmAlarmRecordRemote, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Map> alarmHandlingStatus(String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<List<RmNetworkInterfaceRemote>> getNetworkInterfaceList(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Integer> bindPublicIp(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<String> innerIssueSwitchPolicy(Long id, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<List<RmMonitorPolicyRemote>> getPolicyMsgInner(RmMonitorPolicyRemote rmMonitorPolicyRemote, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Integer> updatePolicyMsgInner(RmMonitorPolicyRemote rmMonitorPolicyRemote, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Integer> issueDefaultPolicyByClientId(String clientId, String source) {
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Integer> addDeployScript(RmDeployScriptRemote addData, String source) {
                return R.fail(throwable.getMessage());
            }
        };
    }
}
