From b8c653d18b0aeb325abff9cbea1d9510843ea93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Tue, 3 Sep 2024 16:16:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91=E6=8B=BC=E5=9B=A2=E8=A3=85=E4=BF=AE=E9=87=8D?= =?UTF-8?q?=E6=9E=84=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityController.java | 45 +++++++++++++++++-- .../activity/CombinationActivityRespVO.java | 12 +++++ .../AppCombinationActivityController.java | 38 ++++++++++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 9ba319463..9dbe45503 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -16,19 +16,21 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @Tag(name = "管理后台 - 拼团活动") @RestController @@ -87,6 +89,43 @@ public class CombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); } + @GetMapping("/list") + @Operation(summary = "获得拼团活动详情列表") + @Parameter(name = "combinationActivityIds", description = "拼团活动编号列表", required = true, example = "[1,2,3]") + @PreAuthorize("@ss.hasPermission('product:spu:query')") + public CommonResult> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection combinationActivityIds) { + // 查询拼团活动列表 + List activities = combinationActivityService.getCombinationActivityListByIds(combinationActivityIds); + + // 转换活动列表 + List activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities); + + // 获取商品SPU列表和拼团产品列表 + Set spuIds = activities.stream().map(CombinationActivityDO::getSpuId).collect(Collectors.toSet()); + List spuList = productSpuApi.getSpuList(spuIds); + + Set activityIds = activities.stream().map(CombinationActivityDO::getId).collect(Collectors.toSet()); + List productList = combinationActivityService.getCombinationProductListByActivityIds(activityIds); + + // 创建SPU和产品的映射 + Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); + + // 更新VO列表 + activityVOs.forEach(vo -> { + ProductSpuRespDTO spu = spuMap.get(vo.getSpuId()); + if (spu != null) { + vo.setSpuName(spu.getName()) + .setPicUrl(spu.getPicUrl()) + .setMarketPrice(spu.getMarketPrice()); + } + vo.setProducts(CombinationActivityConvert.INSTANCE.convertList2(productMap.get(vo.getId()))); + }); + + return success(activityVOs); + } + + @GetMapping("/page") @Operation(summary = "获得拼团活动分页") @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index 0ac77c559..e4880970e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -27,4 +27,16 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) private List products; + // ========== 商品字段 ========== + + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 + example = "618大促") + private String spuName; + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 + example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 + example = "50") + private Integer marketPrice; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 867c2d4b8..11a3cfd96 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -26,9 +26,13 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import jakarta.annotation.Resource; + import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; @@ -109,4 +113,38 @@ public class AppCombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); } + @GetMapping("/get-detail-list") + @Operation(summary = "获得拼团活动明细") + @Parameter(name = "combinationActivityIds", description = "活动编号列表", required = true, example = "[1024, 1025]") + public CommonResult> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection combinationActivityIds) { + // 1. 获取活动 + List combinationActivityDOList = activityService.getCombinationActivityListByIds(combinationActivityIds); + + // 过滤掉无效的活动 + List validActivities = combinationActivityDOList.stream() + .filter(combinationActivityDO -> combinationActivityDO != null && + !ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) + .toList(); + + // 如果没有有效的活动,返回 null 或者适当的错误信息 + if (validActivities.isEmpty()) { + return success(null); // 或者 return error("没有有效的活动"); + } + + // 2. 构建结果列表 + List detailRespVOList = new ArrayList<>(); + for (CombinationActivityDO activity : validActivities) { + // 获取活动商品 + List products = activityService.getCombinationProductsByActivityId(activity.getId()); + + // 调用转换方法并添加到结果列表 + AppCombinationActivityDetailRespVO detailRespVO = CombinationActivityConvert.INSTANCE.convert3(activity, products); + detailRespVOList.add(detailRespVO); + } + + // 3. 返回转换后的结果 + return success(detailRespVOList); + } + + } From c935312bf805d74651002ce8a3009a55c9d7025d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Wed, 4 Sep 2024 22:32:30 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/combination/AppCombinationActivityController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 11a3cfd96..42d6c8535 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -128,7 +128,7 @@ public class AppCombinationActivityController { // 如果没有有效的活动,返回 null 或者适当的错误信息 if (validActivities.isEmpty()) { - return success(null); // 或者 return error("没有有效的活动"); + return success(null); } // 2. 构建结果列表 From efd0a86007c3b71113383268a2aa386ace5cdb85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Wed, 4 Sep 2024 22:55:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/combination/CombinationActivityController.java | 8 ++++---- .../app/combination/AppCombinationActivityController.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 9dbe45503..1dba7345f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -89,13 +89,13 @@ public class CombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); } - @GetMapping("/list") + @GetMapping("/detail-list") @Operation(summary = "获得拼团活动详情列表") - @Parameter(name = "combinationActivityIds", description = "拼团活动编号列表", required = true, example = "[1,2,3]") + @Parameter(name = "ids", description = "拼团活动编号列表", required = true, example = "[1,2,3]") @PreAuthorize("@ss.hasPermission('product:spu:query')") - public CommonResult> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection combinationActivityIds) { + public CommonResult> getCombinationActivityDetailList(@RequestParam("ids") Collection ids) { // 查询拼团活动列表 - List activities = combinationActivityService.getCombinationActivityListByIds(combinationActivityIds); + List activities = combinationActivityService.getCombinationActivityListByIds(ids); // 转换活动列表 List activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 42d6c8535..9ae93e263 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -113,12 +113,12 @@ public class AppCombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); } - @GetMapping("/get-detail-list") + @GetMapping("/detail-list") @Operation(summary = "获得拼团活动明细") - @Parameter(name = "combinationActivityIds", description = "活动编号列表", required = true, example = "[1024, 1025]") - public CommonResult> getCombinationActivityDetailList(@RequestParam("combinationActivityIds") Collection combinationActivityIds) { + @Parameter(name = "ids", description = "活动编号列表", required = true, example = "[1024, 1025]") + public CommonResult> getCombinationActivityDetailList(@RequestParam("ids") Collection ids) { // 1. 获取活动 - List combinationActivityDOList = activityService.getCombinationActivityListByIds(combinationActivityIds); + List combinationActivityDOList = activityService.getCombinationActivityListByIds(ids); // 过滤掉无效的活动 List validActivities = combinationActivityDOList.stream() From 39a6eb4792b11df14100a65573a52bc3419c86bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Thu, 5 Sep 2024 10:55:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8=E5=92=8C?= =?UTF-8?q?SPU=E8=AF=A6=E6=83=85=E5=88=86=E5=BC=80=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityController.java | 19 +++---------------- .../activity/CombinationActivityRespVO.java | 12 ------------ .../AppCombinationActivityController.java | 5 +++-- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 1dba7345f..f166b010d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -100,32 +100,19 @@ public class CombinationActivityController { // 转换活动列表 List activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities); - // 获取商品SPU列表和拼团产品列表 - Set spuIds = activities.stream().map(CombinationActivityDO::getSpuId).collect(Collectors.toSet()); - List spuList = productSpuApi.getSpuList(spuIds); - + // 获取拼团产品列表 Set activityIds = activities.stream().map(CombinationActivityDO::getId).collect(Collectors.toSet()); List productList = combinationActivityService.getCombinationProductListByActivityIds(activityIds); // 创建SPU和产品的映射 - Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); - // 更新VO列表 - activityVOs.forEach(vo -> { - ProductSpuRespDTO spu = spuMap.get(vo.getSpuId()); - if (spu != null) { - vo.setSpuName(spu.getName()) - .setPicUrl(spu.getPicUrl()) - .setMarketPrice(spu.getMarketPrice()); - } - vo.setProducts(CombinationActivityConvert.INSTANCE.convertList2(productMap.get(vo.getId()))); - }); + // 往活动VO赋值产品列表 + activityVOs.forEach(vo -> vo.setProducts(CombinationActivityConvert.INSTANCE.convertList2(productMap.get(vo.getId())))); return success(activityVOs); } - @GetMapping("/page") @Operation(summary = "获得拼团活动分页") @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index e4880970e..0ac77c559 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -27,16 +27,4 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) private List products; - // ========== 商品字段 ========== - - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 - example = "618大促") - private String spuName; - @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 - example = "https://www.iocoder.cn/xx.png") - private String picUrl; - @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 - example = "50") - private Integer marketPrice; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 9ae93e263..f113ab0d2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -126,9 +127,9 @@ public class AppCombinationActivityController { !ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) .toList(); - // 如果没有有效的活动,返回 null 或者适当的错误信息 + // 如果没有有效的活动,返回空列表 if (validActivities.isEmpty()) { - return success(null); + return success(ListUtil.empty()); } // 2. 构建结果列表