无关风月
2024-09-27 c436afe89419da51a5ce593ecd69d3a2f65c5faa
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/GoodsFallbackFactory.java
@@ -3,10 +3,14 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.TGoods;
import com.ruoyi.other.api.feignClient.GoodsClient;
import io.seata.core.exception.TransactionException;
import io.seata.tm.api.GlobalTransactionContext;
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
@@ -26,6 +30,22 @@
         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) {
            // 手动进行全局事务回滚
            try {
               GlobalTransactionContext.getCurrent().rollback();
            } catch (TransactionException e) {
               throw new RuntimeException(e);
            }
            return R.fail("修改商品异常");
         }
      };
   }