puzhibing
2024-08-28 fe2e226da5a7505b343517e828f0d8c3a496fb7a
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
43
44
45
46
package com.ruoyi.other.api.factory;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.TCoupon;
import com.ruoyi.other.api.domain.TGoods;
import com.ruoyi.other.api.feignClient.CouponClient;
import com.ruoyi.other.api.feignClient.GoodsClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2024/8/16 13:48
 */
@Component
public class CouponFallbackFactory implements FallbackFactory<CouponClient> {
    
    private static final Logger log = LoggerFactory.getLogger(CouponFallbackFactory.class);
    
    @Override
    public CouponClient create(Throwable throwable) {
        log.error("优惠券调用失败:{}", throwable.getMessage());
        return new CouponClient() {
            
            @Override
            public R<TCoupon> getCouponById1(Integer id) {
                return R.fail("根据id获取优惠券信息失败:" + throwable.getMessage());
            }
 
            @Override
            public R<List<Integer>> getCouponIdsByName(String name) {
                return R.fail("根据名称查询优惠券ids:" + throwable.getMessage());
            }
            
            @Override
            public R updateCoupon(TCoupon coupon) {
                throw new RuntimeException("修改优惠券失败");
            }
        };
    }
    
}