package com.usky.ems.factory;

import com.usky.common.core.exception.FeignBadRequestException;
import com.usky.ems.RemoteEmsTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;


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

    @Override
    public RemoteEmsTaskService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteEmsTaskService()
        {
            @Override
            public void sendEnergyData() {
                throw new FeignBadRequestException(500,"定时推送能耗数据到能耗平台"+throwable.getMessage());
            }

            @Override
            public void sendEnergyHeartbeat() {
                throw new FeignBadRequestException(500,"定时推送能耗心跳到能耗平台"+throwable.getMessage());
            }

        };
    }
}
