luodangjia
2024-12-16 a8d2cb07f6440dc54dc4005b0b06d5a47cb1517d
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
@@ -1,10 +1,13 @@
package com.ruoyi.account.controller;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.account.service.VipCenterService;
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.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;
@@ -13,10 +16,9 @@
import com.ruoyi.other.api.feignClient.VipGoodClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -41,6 +43,8 @@
    @Resource
    private TokenService tokenService;
    @Resource
    private VipCenterService vipCenterService;
    @Resource
    private VipGoodClient vipGoodClient;
@@ -49,7 +53,7 @@
    public R<VipLevel> vipLevelList() {
        try {
            R<List<VipSetting>> r = remoteVipSettingClient.list();
            if (!checkSuccess(r)) {
            if (R.isError(r)) {
                return R.fail("会员等级获取失败");
            }
            List<VipSetting> vipSettingList = r.getData();
@@ -58,7 +62,7 @@
            }
            R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
            if (!checkSuccess(baseSettingR)) {
            if (R.isError(baseSettingR)) {
                log.error("【会员设置说明】获取失败:{}", baseSettingR.getMsg());
                return R.fail("会员等级获取失败");
            }
@@ -76,43 +80,30 @@
            // 批量获取 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());
                BeanUtils.copyBeanProp(level, vipSetting);
                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);
                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 -> {
                        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);
            });
@@ -126,13 +117,17 @@
        }
    }
    private boolean checkSuccess(R<?> r) {
        if (!R.isSuccess(r)) {
            log.error("请求失败: " + r.getMsg());
        }
        return R.isSuccess(r);
    @GetMapping("/check")
    @ApiOperation(value = "会员申请检查", tags = {"会员中心-小程序"})
    public R<Boolean> check(@ApiParam("4:准代理,5:代理,6:总代理,7:合伙人") @RequestParam Integer type) {
        return R.ok(vipCenterService.check(type));
    }
    private Map<Integer, R<GoodsVip>> getGoodsVips(List<Integer> vipIds) {
        Map<Integer, R<GoodsVip>> result = new HashMap<>();
        for (Integer vipId : vipIds) {