package com.zd.system.api.factory;

import com.zd.common.core.web.domain.AjaxResult;
import com.zd.system.api.alarm.RemoteAlarmService;
import com.zd.system.api.alarm.domain.AlarmEntrty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 报警服务降级处理
 * @author liubo
 */
@Component
public class RemoteAlarmFallbackFactory implements FallbackFactory<RemoteAlarmService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAlarmFallbackFactory.class);

    @Override
    public RemoteAlarmService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteAlarmService() {
            @Override
            public AjaxResult send(AlarmEntrty alarmEntrty) {
                return AjaxResult.error("发送语音报警失败:" + throwable.getMessage());
            }
        };
    }
}
