Commit 8283f203dd174986d981b7a700f9ebcd56ae5f73
1 parent
19c4a5c9
【代码补全】商城:uni-app端秒杀列表的接口
Showing
3 changed files
with
37 additions
and
0 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java
| @@ -35,6 +35,7 @@ import java.time.Duration; | @@ -35,6 +35,7 @@ import java.time.Duration; | ||
| 35 | import java.time.LocalDate; | 35 | import java.time.LocalDate; |
| 36 | import java.time.LocalDateTime; | 36 | import java.time.LocalDateTime; |
| 37 | import java.time.LocalTime; | 37 | import java.time.LocalTime; |
| 38 | +import java.util.Collections; | ||
| 38 | import java.util.List; | 39 | import java.util.List; |
| 39 | 40 | ||
| 40 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 41 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| @@ -149,4 +150,21 @@ public class AppSeckillActivityController { | @@ -149,4 +150,21 @@ public class AppSeckillActivityController { | ||
| 149 | return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime)); | 150 | return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime)); |
| 150 | } | 151 | } |
| 151 | 152 | ||
| 153 | + @GetMapping("/list-by-ids") | ||
| 154 | + @Operation(summary = "获得拼团活动列表,基于活动编号数组") | ||
| 155 | + @Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]") | ||
| 156 | + public CommonResult<List<AppSeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) { | ||
| 157 | + // 1. 获得开启的活动列表 | ||
| 158 | + List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByIds(ids); | ||
| 159 | + activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus())); | ||
| 160 | + if (CollUtil.isEmpty(activityList)) { | ||
| 161 | + return success(Collections.emptyList()); | ||
| 162 | + } | ||
| 163 | + // 2. 拼接返回 | ||
| 164 | + List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds( | ||
| 165 | + convertList(activityList, SeckillActivityDO::getId)); | ||
| 166 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); | ||
| 167 | + return success(SeckillActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList)); | ||
| 168 | + } | ||
| 169 | + | ||
| 152 | } | 170 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java
| @@ -16,6 +16,9 @@ public class AppSeckillActivityRespVO { | @@ -16,6 +16,9 @@ public class AppSeckillActivityRespVO { | ||
| 16 | @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | 16 | @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") |
| 17 | private Long spuId; | 17 | private Long spuId; |
| 18 | 18 | ||
| 19 | + @Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜") | ||
| 20 | + private String spuName; // 从 SPU 的 name 读取 | ||
| 21 | + | ||
| 19 | @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 | 22 | @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 |
| 20 | example = "https://www.iocoder.cn/xx.png") | 23 | example = "https://www.iocoder.cn/xx.png") |
| 21 | private String picUrl; | 24 | private String picUrl; |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/SeckillActivityConvert.java
| @@ -104,6 +104,22 @@ public interface SeckillActivityConvert { | @@ -104,6 +104,22 @@ public interface SeckillActivityConvert { | ||
| 104 | }); | 104 | }); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | + default List<AppSeckillActivityRespVO> convertAppList(List<SeckillActivityDO> list, | ||
| 108 | + List<SeckillProductDO> productList, | ||
| 109 | + List<ProductSpuRespDTO> spuList) { | ||
| 110 | + List<AppSeckillActivityRespVO> activityList = BeanUtils.toBean(list, AppSeckillActivityRespVO.class); | ||
| 111 | + Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); | ||
| 112 | + Map<Long, List<SeckillProductDO>> productMap = convertMultiMap(productList, SeckillProductDO::getActivityId); | ||
| 113 | + return CollectionUtils.convertList(activityList, item -> { | ||
| 114 | + // 设置 product 信息 | ||
| 115 | + item.setSeckillPrice(getMinValue(productMap.get(item.getId()), SeckillProductDO::getSeckillPrice)); | ||
| 116 | + // 设置 SPU 信息 | ||
| 117 | + findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()) | ||
| 118 | + .setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); | ||
| 119 | + return item; | ||
| 120 | + }); | ||
| 121 | + } | ||
| 122 | + | ||
| 107 | List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list); | 123 | List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list); |
| 108 | 124 | ||
| 109 | List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList); | 125 | List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList); |