From 893c8ad4d5d55f35c8499c007ce028bc43c6bf9f Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 06 十二月 2024 13:46:45 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 /dev/null                                                                                             |   85 --------------
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java            |   18 +++
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java                         |    7 +
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java       |  163 +++++++++++++++++++++++++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java             |   18 ++
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java |   20 +++
 6 files changed, 224 insertions(+), 87 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java
new file mode 100644
index 0000000..e08c82f
--- /dev/null
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java
@@ -0,0 +1,20 @@
+package com.ruoyi.other.api.factory;
+
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.other.api.domain.VipGood;
+import com.ruoyi.other.api.feignClient.VipGoodClient;
+import org.springframework.cloud.openfeign.FallbackFactory;
+
+import java.util.List;
+
+public class VipGoodClientFallbackFactory implements FallbackFactory<VipGoodClient> {
+    @Override
+    public VipGoodClient create(Throwable cause) {
+        return new VipGoodClient() {
+            @Override
+            public R<List<VipGood>> getVipGoodsByVipId(Integer vipId) {
+                return R.fail("根据会员id获取会员购买商品失败:" + cause.getMessage());
+            }
+        };
+    }
+}
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java
new file mode 100644
index 0000000..ec43dc1
--- /dev/null
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java
@@ -0,0 +1,18 @@
+package com.ruoyi.other.api.feignClient;
+
+import com.ruoyi.common.core.constant.ServiceNameConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.other.api.domain.VipGood;
+import com.ruoyi.other.api.factory.VipGoodClientFallbackFactory;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+@FeignClient(contextId = "VipGoodClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = VipGoodClientFallbackFactory.class)
+public interface VipGoodClient {
+
+    @GetMapping("/vip-good/getVipGoodsByVipId")
+    public R<List<VipGood>> getVipGoodsByVipId(@RequestParam(value = "vipId") Integer vipId);
+}
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenter.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenter.java
deleted file mode 100644
index d964ef6..0000000
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenter.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.ruoyi.account.controller;
-
-import com.ruoyi.account.service.VipSettingService;
-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.security.service.TokenService;
-import com.ruoyi.other.api.domain.BaseSetting;
-import com.ruoyi.other.api.domain.VipSetting;
-import com.ruoyi.other.api.feignClient.BaseSettingClient;
-import com.ruoyi.other.api.feignClient.RemoteVipSettingClient;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.log4j.Log4j2;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-
-@RestController
-@RequestMapping("/vipCenter")
-@Api(tags = "小程序-会员中心")
-@Log4j2
-public class VipCenter {
-    @Resource
-    private RemoteVipSettingClient remoteVipSettingClient;
-    @Resource
-    private BaseSettingClient baseSettingClient;
-    @Resource
-    private VipSettingService vipSettingService;
-    @Resource
-    private TokenService tokenService;
-
-
-    @GetMapping("getVipLevelList")
-    @ApiOperation(value = "会员等级列表", tags = {"会员中心-小程序"})
-    public R<VipLevel> vipLevelList() {
-        R<List<VipSetting>> r = remoteVipSettingClient.list();
-        if (!R.isSuccess(r)){
-            return R.fail("会员等级获取失败");
-        }
-        List<VipSetting> vipSettingList = r.getData();
-        if (vipSettingList == null || vipSettingList.isEmpty()){
-            return R.fail("会员等级获取失败");
-        }
-        R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
-        if (!R.isSuccess(baseSettingR)){
-            log.error("【会员设置说明】获取失败");
-            return R.fail("会员等级获取失败");
-        }
-        BaseSetting baseSetting = baseSettingR.getData();
-        if (baseSetting == null){
-            log.error("【会员设置说明】未设置");
-            return R.fail("会员等级获取失败");
-        }
-        Long userid = tokenService.getLoginUserApplet().getUserid();
-        VipSetting loginUserVipSetting = vipSettingService.getVipSettingByUserId(userid);
-
-        VipLevel vipLevel = new VipLevel();
-        List<Level> levelList = new ArrayList<>();
-        vipSettingList.forEach(vipSetting -> {
-            Level level = new Level();
-            level.setId(vipSetting.getId());
-            level.setName(vipSetting.getVipName());
-            level.setVipInfo(vipSetting.getVipInfo());
-            level.setVipDesc(baseSetting.getContent());
-            level.setVipLevelUpShop(vipSetting.getVipLevelUpShop());
-            level.setVipLevelUpShare(vipSetting.getVipLevelUpShare());
-            level.setKeepBuyDay(vipSetting.getKeepBuyDay());
-            level.setKeepBuyPoint(vipSetting.getKeepBuyPoint());
-            level.setKeepShareDay(vipSetting.getKeepShareDay());
-            level.setKeepSharePoint(vipSetting.getKeepSharePoint());
-            level.setKeepShopDay(vipSetting.getKeepShopDay());
-            level.setKeepShopPoint(vipSetting.getKeepShopPoint());
-            levelList.add(level);
-        });
-        vipLevel.setLevelList(levelList);
-        vipLevel.setCurrentLevel(loginUserVipSetting.getId());
-        return R.ok(vipLevel);
-    }
-
-}
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
new file mode 100644
index 0000000..d7d820a
--- /dev/null
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
@@ -0,0 +1,163 @@
+package com.ruoyi.account.controller;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.account.service.VipSettingService;
+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.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 io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@RestController
+@RequestMapping("/vipCenter")
+@Api(tags = "小程序-会员中心")
+@Log4j2
+public class VipCenterController {
+    @Resource
+    private RemoteVipSettingClient remoteVipSettingClient;
+    @Resource
+    private BaseSettingClient baseSettingClient;
+    @Resource
+    private GoodsVipClient goodsVipClient;
+    @Resource
+    private VipSettingService vipSettingService;
+    @Resource
+    private TokenService tokenService;
+    @Resource
+    private VipGoodClient vipGoodClient;
+
+
+    @GetMapping("getVipLevelList")
+    @ApiOperation(value = "会员等级列表", tags = {"会员中心-小程序"})
+    public R<VipLevel> vipLevelList() {
+        try {
+            R<List<VipSetting>> r = remoteVipSettingClient.list();
+            if (!checkSuccess(r)) {
+                return R.fail("会员等级获取失败");
+            }
+            List<VipSetting> vipSettingList = r.getData();
+            if (vipSettingList == null || vipSettingList.isEmpty()) {
+                return R.fail("会员等级获取失败");
+            }
+
+            R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
+            if (!checkSuccess(baseSettingR)) {
+                log.error("【会员设置说明】获取失败:{}", baseSettingR.getMsg());
+                return R.fail("会员等级获取失败");
+            }
+            BaseSetting baseSetting = baseSettingR.getData();
+            if (baseSetting == null) {
+                log.error("【会员设置说明】未设置");
+                return R.fail("会员等级获取失败");
+            }
+
+            Long userid = tokenService.getLoginUserApplet().getUserid();
+            VipSetting loginUserVipSetting = vipSettingService.getVipSettingByUserId(userid);
+
+            VipLevel vipLevel = new VipLevel();
+            List<Level> levelList = new ArrayList<>();
+
+            // 批量获取 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 -> {
+                Level level = new Level();
+                level.setId(vipSetting.getId());
+                level.setName(vipSetting.getVipName());
+                level.setVipInfo(vipSetting.getVipInfo());
+                level.setVipDesc(baseSetting.getContent());
+                level.setVipLevelUpShop(vipSetting.getVipLevelUpShop());
+                level.setVipLevelUpShare(vipSetting.getVipLevelUpShare());
+                level.setKeepBuyDay(vipSetting.getKeepBuyDay());
+                level.setKeepBuyPoint(vipSetting.getKeepBuyPoint());
+                level.setKeepShareDay(vipSetting.getKeepShareDay());
+                level.setKeepSharePoint(vipSetting.getKeepSharePoint());
+                level.setKeepShopDay(vipSetting.getKeepShopDay());
+                level.setKeepShopPoint(vipSetting.getKeepShopPoint());
+
+                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);
+                        }
+                    }
+                }
+                levelList.add(level);
+            });
+
+            vipLevel.setLevelList(levelList);
+            vipLevel.setCurrentLevel(loginUserVipSetting.getId());
+            return R.ok(vipLevel);
+        } catch (Exception e) {
+            log.error("会员等级获取失败", e);
+            return R.fail("会员等级获取失败");
+        }
+    }
+
+    private boolean checkSuccess(R<?> r) {
+        if (!R.isSuccess(r)) {
+            log.error("请求失败: " + r.getMsg());
+        }
+        return R.isSuccess(r);
+    }
+
+    private Map<Integer, R<GoodsVip>> getGoodsVips(List<Integer> vipIds) {
+        Map<Integer, R<GoodsVip>> result = new HashMap<>();
+        for (Integer vipId : vipIds) {
+            R<GoodsVip> goodsVipR = goodsVipClient.getGoodsVip(vipId);
+            result.put(vipId, goodsVipR);
+        }
+        return result;
+    }
+
+    private Map<Integer, R<List<VipGood>>> getVipGoods(List<Integer> vipIds) {
+        Map<Integer, R<List<VipGood>>> result = new HashMap<>();
+        for (Integer vipId : vipIds) {
+            R<List<VipGood>> vipGoodR = vipGoodClient.getVipGoodsByVipId(vipId);
+            result.put(vipId, vipGoodR);
+        }
+        return result;
+    }
+
+    private boolean isValidJson(String json) {
+        try {
+            JSONObject.parseObject(json);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+}
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java
index 855de5c..96636bf 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java
@@ -33,7 +33,7 @@
 
     @ApiModelProperty(value = "升级会员的直推用户人数要求")
     private Integer vipDirectNum;
-    @ApiModelProperty(value = "升级会员的团队数要求")
+    @ApiModelProperty(value = "升级会员的团队数要求/准代人数")
     private Integer vipTeamNum;
 
     @ApiModelProperty(value = "保级:消费x天")
@@ -54,6 +54,11 @@
     @ApiModelProperty(value = "保级:门店x分")
     private BigDecimal keepShopPoint;
 
+    @ApiModelProperty(value = "指定购买商品")
+    private List<String> goodsNames;
+
+
+
 
 
 
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java
index 4f867f2..db942f8 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java
@@ -1,8 +1,17 @@
 package com.ruoyi.other.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.other.api.domain.VipGood;
+import com.ruoyi.other.service.VipGoodService;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * <p>
@@ -14,7 +23,14 @@
  */
 @RestController
 @RequestMapping("/vip-good")
-public class VipGoodController {
+public class VipGoodController extends BaseController {
+    @Resource
+    private VipGoodService vipGoodService;
 
+    @GetMapping("getVipGoodsByVipId")
+    public R<List<VipGood>> getVipGoodsByVipId(Integer vipId){
+        return R.ok(vipGoodService.list(new LambdaQueryWrapper<VipGood>()
+                .eq(VipGood::getVipId, vipId)));
+    }
 }
 

--
Gitblit v1.7.1