Pu Zhibing
2024-12-31 8f22c7b297417ac7df12cb07eb9edd3a77dd01a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.ruoyi.integration.api.factory;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.integration.api.feignClient.IotInterfaceClient;
import com.ruoyi.integration.api.feignClient.SwitchwayGateClient;
import com.ruoyi.integration.api.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
/**
 * 充电桩服务降级处理
 *
 * @author ruoyi
 */
@Component
public class IotInterfaceFallbackFactory implements org.springframework.cloud.openfeign.FallbackFactory<IotInterfaceClient> {
    private static final Logger log = LoggerFactory.getLogger(IotInterfaceFallbackFactory.class);
    
    @Override
    public IotInterfaceClient create(Throwable throwable) {
        log.error("调用失败:{}", throwable.getMessage());
        return new IotInterfaceClient() {
            
            
            @Override
            public R<AddDeviceResp> addDevice(AddDevice addDevice) {
                return R.fail("添加设备失败:" + throwable.getMessage());
            }
            
            @Override
            public R<DeleteDeviceResp> deleteDevice(String deviceId) {
                return R.fail("删除设备失败:" + throwable.getMessage());
            }
            
            @Override
            public R<ShowDeviceResp> showDeviceRequest(String deviceId) {
                return R.fail("查询设备失败:" + throwable.getMessage());
            }
        };
    }
}