package com.xueyi.system.api.sms.feign.factory;

import com.alibaba.fastjson.JSONObject;
import com.xueyi.common.core.web.result.R;
import com.xueyi.system.api.sms.domain.vo.SmsReqEntity;
import com.xueyi.system.api.sms.feign.RemoteSmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 会议室服务 降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemoteSmsFallbackFactory implements FallbackFactory<RemoteSmsService> {

    @Override
    public RemoteSmsService create(Throwable throwable) {
        log.error("短信服务调用失败:{}", throwable.getMessage());
        return new RemoteSmsService() {
            @Override
            public JSONObject sendSms(SmsReqEntity smsReqEntity) {
                return  R.fail("短信服务调用失败:" + throwable.getMessage()).toJson1();
            }
        };
    }
}