diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java index 1b7146441..e18eb20a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -2,6 +2,13 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -11,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.*; @@ -22,24 +30,46 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppActivityController { - // TODO @puhui999:可以实现下 + @Resource + private CombinationActivityService combinationActivityService; + @Resource + private SeckillActivityService seckillActivityService; + @Resource + private BargainActivityService bargainActivityService; + @GetMapping("/list-by-spu-id") @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动,只返回一个 @Parameter(name = "spuId", description = "商品编号", required = true) public CommonResult> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { - // TODO 芋艿,实现 - List randomList = new ArrayList<>(); - Random random = new Random(); - for (int i = 0; i < 3; i++) { // 生成5个随机对象 - AppActivityRespVO vo = new AppActivityRespVO(); - vo.setId(random.nextLong()); // 随机生成一个长整型 ID - vo.setType(i + 1); // 随机生成一个介于0到2之间的整数,对应枚举类型的三种类型之一 - vo.setName(String.format("活动%d", random.nextInt(100))); // 随机生成一个类似于“活动XX”的活动名称,XX为0到99之间的随机整数 - vo.setStartTime(LocalDateTime.now()); // 随机生成一个在过去的一年内的开始时间(以毫秒为单位) - vo.setEndTime(LocalDateTime.now()); // 随机生成一个在未来的一年内的结束时间(以毫秒为单位) - randomList.add(vo); + List respList = new ArrayList<>(); + CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId); + if (combination != null) { + respList.add(new AppActivityRespVO() + .setId(combination.getId()) + .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) + .setName(combination.getName()) + .setStartTime(combination.getStartTime()) + .setEndTime(combination.getEndTime())); } - return success(randomList); + SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId); + if (seckill != null) { + respList.add(new AppActivityRespVO() + .setId(seckill.getId()) + .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) + .setName(seckill.getName()) + .setStartTime(seckill.getStartTime()) + .setEndTime(seckill.getEndTime())); + } + BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId); + if (bargain != null) { + respList.add(new AppActivityRespVO() + .setId(bargain.getId()) + .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) + .setName(bargain.getName()) + .setStartTime(bargain.getStartTime()) + .setEndTime(bargain.getEndTime())); + } + return success(respList); } // TODO @puhui999:可以实现下 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index d3ea59983..7c5cfbfd8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -83,4 +83,11 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } + default BargainActivityDO selectOne(Long spuId) { + return selectOne(new LambdaQueryWrapperX() + .eq(BargainActivityDO::getSpuId, spuId) + .orderByDesc(BargainActivityDO::getCreateTime) + , false); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 5672c34dc..3f5e9ec23 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -40,4 +40,11 @@ public interface CombinationActivityMapper extends BaseMapperX() + .eq(CombinationActivityDO::getSpuId, spuId) + .orderByDesc(CombinationActivityDO::getCreateTime) + , false); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 28f764dae..1c31e74d9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -56,4 +56,11 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } + default SeckillActivityDO selectOne(Long spuId) { + return selectOne(new LambdaQueryWrapperX() + .eq(SeckillActivityDO::getSpuId, spuId) + .orderByDesc(SeckillActivityDO::getCreateTime) + , false); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index a57adc63f..8090ebcb1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java @@ -98,4 +98,12 @@ public interface BargainActivityService { */ List getBargainActivityListByCount(Integer count); + /** + * 获取指定 spu 编号的活动 + * + * @param spuId spu 编号 + * @return 砍价活动 + */ + BargainActivityDO getBargainActivityBySpuId(Long spuId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index e14d5759e..bf4e04084 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -175,4 +175,9 @@ public class BargainActivityServiceImpl implements BargainActivityService { return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); } + @Override + public BargainActivityDO getBargainActivityBySpuId(Long spuId) { + return bargainActivityMapper.selectOne(spuId); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 20f5e5fbd..4dfabddfd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -109,4 +109,12 @@ public interface CombinationActivityService { */ CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); + /** + * 获取指定 spu 编号的活动 + * + * @param spuId spu 编号 + * @return 拼团商品 + */ + CombinationActivityDO getCombinationActivityBySpuId(Long spuId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 0f4f2ccfb..df254d23b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -223,4 +223,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic CombinationProductDO::getSkuId, skuId); } + @Override + public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) { + return combinationActivityMapper.selectOne(spuId); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 04472a15b..f9ef9b194 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -119,4 +119,12 @@ public interface SeckillActivityService { */ SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); + /** + * 获取指定 spu 编号的活动 + * + * @param spuId spu 编号 + * @return 秒杀商品 + */ + SeckillActivityDO getSeckillActivityBySpuId(Long spuId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 6567a1f52..3aa56d098 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -310,4 +310,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { return SeckillActivityConvert.INSTANCE.convert02(activity, product); } + @Override + public SeckillActivityDO getSeckillActivityBySpuId(Long spuId) { + return seckillActivityMapper.selectOne(spuId); + } + }