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); + } + + }