package com.usky.cdi.factory;

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

@Component
public class RemotecdiTaskFactory implements FallbackFactory<RemotecdiTaskService> {
    private static final Logger log = LoggerFactory.getLogger(RemotecdiTaskFactory.class);

    @Override
    public RemotecdiTaskService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemotecdiTaskService() {
            @Override
            public void synchronizeDeviceData(Integer tenantId, Long engineeringId, String username, String password) {
                throw new FeignBadRequestException(500, "人防设备数据定时推送异常(带租户)" + throwable.getMessage());
            }

            @Override
            public void allData(Long engineeringId, String username, String password) {
                throw new FeignBadRequestException(500, "人防设备数据定时推送异常" + throwable.getMessage());
            }

        };
    }
}
