Commit 9d7285c4ed044bf7491bae4ee740aecb87f4b589
1 parent
07493bc7
营销活动:实现 list-by-spu-ids 接口
Showing
3 changed files
with
29 additions
and
28 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.app.activity; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.map.MapUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 6 | import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; |
| 5 | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| ... | ... | @@ -19,8 +21,10 @@ import org.springframework.web.bind.annotation.RequestParam; |
| 19 | 21 | import org.springframework.web.bind.annotation.RestController; |
| 20 | 22 | |
| 21 | 23 | import javax.annotation.Resource; |
| 22 | -import java.time.LocalDateTime; | |
| 23 | -import java.util.*; | |
| 24 | +import java.util.ArrayList; | |
| 25 | +import java.util.HashMap; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 24 | 28 | |
| 25 | 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 26 | 30 | |
| ... | ... | @@ -41,6 +45,26 @@ public class AppActivityController { |
| 41 | 45 | @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动,只返回一个 |
| 42 | 46 | @Parameter(name = "spuId", description = "商品编号", required = true) |
| 43 | 47 | public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { |
| 48 | + return success(getAppActivityRespVOList(spuId)); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @GetMapping("/list-by-spu-ids") | |
| 52 | + @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 | |
| 53 | + @Parameter(name = "spuIds", description = "商品编号数组", required = true) | |
| 54 | + public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) { | |
| 55 | + | |
| 56 | + if (CollUtil.isEmpty(spuIds)) { | |
| 57 | + return success(MapUtil.empty()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + Map<Long, List<AppActivityRespVO>> map = new HashMap<>(spuIds.size()); | |
| 61 | + spuIds.forEach(spuId -> { | |
| 62 | + map.put(spuId, getAppActivityRespVOList(spuId)); | |
| 63 | + }); | |
| 64 | + return success(map); | |
| 65 | + } | |
| 66 | + | |
| 67 | + private List<AppActivityRespVO> getAppActivityRespVOList(Long spuId) { | |
| 44 | 68 | List<AppActivityRespVO> respList = new ArrayList<>(); |
| 45 | 69 | CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId); |
| 46 | 70 | if (combination != null) { |
| ... | ... | @@ -69,30 +93,7 @@ public class AppActivityController { |
| 69 | 93 | .setStartTime(bargain.getStartTime()) |
| 70 | 94 | .setEndTime(bargain.getEndTime())); |
| 71 | 95 | } |
| 72 | - return success(respList); | |
| 73 | - } | |
| 74 | - | |
| 75 | - // TODO @puhui999:可以实现下 | |
| 76 | - @GetMapping("/list-by-spu-ids") | |
| 77 | - @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 | |
| 78 | - @Parameter(name = "spuIds", description = "商品编号数组", required = true) | |
| 79 | - public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) { | |
| 80 | - // TODO 芋艿,实现 | |
| 81 | - List<AppActivityRespVO> randomList = new ArrayList<>(); | |
| 82 | - Random random = new Random(); | |
| 83 | - for (int i = 0; i < 5; i++) { // 生成5个随机对象 | |
| 84 | - AppActivityRespVO vo = new AppActivityRespVO(); | |
| 85 | - vo.setId(random.nextLong()); // 随机生成一个长整型 ID | |
| 86 | - vo.setType(random.nextInt(3)); // 随机生成一个介于0到2之间的整数,对应枚举类型的三种类型之一 | |
| 87 | - vo.setName(String.format("活动%d", random.nextInt(100))); // 随机生成一个类似于“活动XX”的活动名称,XX为0到99之间的随机整数 | |
| 88 | - vo.setStartTime(LocalDateTime.now()); // 随机生成一个在过去的一年内的开始时间(以毫秒为单位) | |
| 89 | - vo.setEndTime(LocalDateTime.now()); // 随机生成一个在未来的一年内的结束时间(以毫秒为单位) | |
| 90 | - randomList.add(vo); | |
| 91 | - } | |
| 92 | - Map<Long, List<AppActivityRespVO>> map = new HashMap<>(); | |
| 93 | - map.put(109L, randomList); | |
| 94 | - map.put(2L, randomList); | |
| 95 | - return success(map); | |
| 96 | + return respList; | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java