Pu Zhibing
9 天以前 7a4f9541331bef779a506b38a27ed5c3373c0bec
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/GoodsFallbackFactory.java
New file
@@ -0,0 +1,44 @@
package com.ruoyi.other.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.TGoods;
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 GoodsFallbackFactory implements FallbackFactory<GoodsClient> {
   private static final Logger log = LoggerFactory.getLogger(GoodsFallbackFactory.class);
   @Override
   public GoodsClient create(Throwable throwable) {
      log.error("商品调用失败:{}", throwable.getMessage());
      return new GoodsClient() {
         @Override
         public R<TGoods> getGoodsById(Integer id) {
            return R.fail("根据id获取商品信息失败:" + throwable.getMessage());
         }
         @Override
         public R<List<Integer>> getGoodsIdsByName(String name) {
            return R.fail("根据商品名称获取商品ids失败:" + throwable.getMessage());
         }
         @Override
         public R updateGoods(TGoods goods) {
            return R.fail("修改商品异常");
         }
      };
   }
}