| | |
| | | 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 io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private VipCenterService vipCenterService; |
| | | @Resource |
| | | private VipGoodClient vipGoodClient; |
| | | |
| | | |
| | | @GetMapping("getVipLevelList") |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3); |
| | | if (checkSuccess(baseSettingR)) { |
| | | if (R.isError(baseSettingR)) { |
| | | log.error("【会员设置说明】获取失败:{}", baseSettingR.getMsg()); |
| | | return R.fail("会员等级获取失败"); |
| | | } |
| | |
| | | |
| | | // 批量获取 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 -> { |
| | |
| | | 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 -> { |
| | | 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); |
| | | }); |
| | |
| | | |
| | | |
| | | |
| | | 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) { |
| | |
| | | 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); |
| | | R<List<VipGood>> vipGoodR = vipGoodClient.getVipGoodsByVipId(vipId); |
| | | result.put(vipId, vipGoodR); |
| | | } |
| | | return result; |
| | | } |