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..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 @@ -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,30 @@ public class CombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); } + @GetMapping("/detail-list") + @Operation(summary = "获得拼团活动详情列表") + @Parameter(name = "ids", description = "拼团活动编号列表", required = true, example = "[1,2,3]") + @PreAuthorize("@ss.hasPermission('product:spu:query')") + public CommonResult> getCombinationActivityDetailList(@RequestParam("ids") Collection ids) { + // 查询拼团活动列表 + List activities = combinationActivityService.getCombinationActivityListByIds(ids); + + // 转换活动列表 + List activityVOs = CombinationActivityConvert.INSTANCE.convertList(activities); + + // 获取拼团产品列表 + Set activityIds = activities.stream().map(CombinationActivityDO::getId).collect(Collectors.toSet()); + List productList = combinationActivityService.getCombinationProductListByActivityIds(activityIds); + + // 创建SPU和产品的映射 + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); + + // 往活动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/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..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; @@ -26,9 +27,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 +114,38 @@ public class AppCombinationActivityController { return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); } + @GetMapping("/detail-list") + @Operation(summary = "获得拼团活动明细") + @Parameter(name = "ids", description = "活动编号列表", required = true, example = "[1024, 1025]") + public CommonResult> getCombinationActivityDetailList(@RequestParam("ids") Collection ids) { + // 1. 获取活动 + List combinationActivityDOList = activityService.getCombinationActivityListByIds(ids); + + // 过滤掉无效的活动 + List validActivities = combinationActivityDOList.stream() + .filter(combinationActivityDO -> combinationActivityDO != null && + !ObjectUtil.equal(combinationActivityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) + .toList(); + + // 如果没有有效的活动,返回空列表 + if (validActivities.isEmpty()) { + return success(ListUtil.empty()); + } + + // 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); + } + + }