From 0ccd279eb3986d0765545e34d67bee8923d68baf Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期三, 18 十二月 2024 14:32:48 +0800
Subject: [PATCH] 12.18

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java |   43 ++++++++++++++++++++-----------------------
 1 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
index 056a580..04feab8 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
@@ -6,13 +6,11 @@
 import com.ruoyi.account.vo.vip.Level;
 import com.ruoyi.account.vo.vip.VipLevel;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.domain.*;
-import com.ruoyi.other.api.feignClient.BaseSettingClient;
-import com.ruoyi.other.api.feignClient.GoodsVipClient;
-import com.ruoyi.other.api.feignClient.RemoteVipSettingClient;
-import com.ruoyi.other.api.feignClient.VipGoodClient;
+import com.ruoyi.other.api.feignClient.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -45,6 +43,8 @@
     private VipCenterService vipCenterService;
     @Resource
     private VipGoodClient vipGoodClient;
+    @Resource
+    private GoodsClient goodsClient;
 
 
     @GetMapping("getVipLevelList")
@@ -79,7 +79,6 @@
 
             // 批量获取 goodsVip 和 vipGoods
             List<Integer> vipIds = vipSettingList.stream().map(VipSetting::getId).collect(Collectors.toList());
-            Map<Integer, R<GoodsVip>> goodsVipMap = getGoodsVips(vipIds);
             Map<Integer, R<List<VipGood>>> vipGoodsMap = getVipGoods(vipIds);
 
             vipSettingList.forEach(vipSetting -> {
@@ -87,25 +86,23 @@
                 BeanUtils.copyBeanProp(level, vipSetting);
                 level.setVipDesc(baseSetting.getContent());
 
-                R<GoodsVip> goodsVipR = goodsVipMap.get(vipSetting.getId());
-                if (R.isSuccess(goodsVipR)) {
-                    R<List<VipGood>> vipGoodR = vipGoodsMap.get(vipSetting.getId());
-                    if (R.isSuccess(vipGoodR)) {
-                        List<VipGood> vipGoodList = vipGoodR.getData();
-                        if (vipGoodList != null && !vipGoodList.isEmpty()) {
-                            List<String> goodsNames = new ArrayList<>();
-                            vipGoodList.forEach(vipGood -> {
-                                String goodJson = vipGood.getGoodJson();
-                                if (isValidJson(goodJson)) {
-                                    Goods goods = JSONObject.parseObject(goodJson, Goods.class);
-                                    goodsNames.add(goods.getName());
-                                } else {
-                                    log.warn("JSON无效: " + goodJson);
-                                }
-                            });
-                            level.setGoodsNames(goodsNames);
+                R<List<VipGood>> vipGoodR = vipGoodsMap.get(vipSetting.getId());
+                if (R.isError(vipGoodR)) {
+                    throw new ServiceException("会员商品获取失败");
+                }
+                List<VipGood> vipGoodList = vipGoodR.getData();
+                if (vipGoodList != null && !vipGoodList.isEmpty()) {
+                    List<String> goodsNames = new ArrayList<>();
+                    vipGoodList.forEach(vipGood -> {
+                        Integer goodId = vipGood.getGoodId();
+                        R<Goods> goodsR = goodsClient.getGoodsById(goodId);
+                        if (R.isError(goodsR)) {
+                         throw new ServiceException("商品信息获取失败");
                         }
-                    }
+                        Goods goods = goodsR.getData();
+                        goodsNames.add(goods.getName());
+                    });
+                    level.setGoodsNames(goodsNames);
                 }
                 levelList.add(level);
             });

--
Gitblit v1.7.1