营销活动:实现 list-by-spu-id 接口

This commit is contained in:
puhui999 2023-10-06 01:04:36 +08:00
parent 3f6f7f404b
commit 07493bc7e5
10 changed files with 103 additions and 13 deletions

View File

@ -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.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; 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.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; 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.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -22,24 +30,46 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated @Validated
public class AppActivityController { public class AppActivityController {
// TODO @puhui999可以实现下 @Resource
private CombinationActivityService combinationActivityService;
@Resource
private SeckillActivityService seckillActivityService;
@Resource
private BargainActivityService bargainActivityService;
@GetMapping("/list-by-spu-id") @GetMapping("/list-by-spu-id")
@Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动只返回一个 @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动只返回一个
@Parameter(name = "spuId", description = "商品编号", required = true) @Parameter(name = "spuId", description = "商品编号", required = true)
public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { public CommonResult<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) {
// TODO 芋艿实现 List<AppActivityRespVO> respList = new ArrayList<>();
List<AppActivityRespVO> randomList = new ArrayList<>(); CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId);
Random random = new Random(); if (combination != null) {
for (int i = 0; i < 3; i++) { // 生成5个随机对象 respList.add(new AppActivityRespVO()
AppActivityRespVO vo = new AppActivityRespVO(); .setId(combination.getId())
vo.setId(random.nextLong()); // 随机生成一个长整型 ID .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
vo.setType(i + 1); // 随机生成一个介于0到2之间的整数对应枚举类型的三种类型之一 .setName(combination.getName())
vo.setName(String.format("活动%d", random.nextInt(100))); // 随机生成一个类似于活动XX的活动名称XX为0到99之间的随机整数 .setStartTime(combination.getStartTime())
vo.setStartTime(LocalDateTime.now()); // 随机生成一个在过去的一年内的开始时间以毫秒为单位 .setEndTime(combination.getEndTime()));
vo.setEndTime(LocalDateTime.now()); // 随机生成一个在未来的一年内的结束时间以毫秒为单位
randomList.add(vo);
} }
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可以实现下 // TODO @puhui999可以实现下

View File

@ -83,4 +83,11 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
.last("LIMIT " + count)); .last("LIMIT " + count));
} }
default BargainActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<BargainActivityDO>()
.eq(BargainActivityDO::getSpuId, spuId)
.orderByDesc(BargainActivityDO::getCreateTime)
, false);
}
} }

View File

@ -40,4 +40,11 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
.last("LIMIT " + count)); .last("LIMIT " + count));
} }
default CombinationActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<CombinationActivityDO>()
.eq(CombinationActivityDO::getSpuId, spuId)
.orderByDesc(CombinationActivityDO::getCreateTime)
, false);
}
} }

View File

@ -56,4 +56,11 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
.apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0"));
} }
default SeckillActivityDO selectOne(Long spuId) {
return selectOne(new LambdaQueryWrapperX<SeckillActivityDO>()
.eq(SeckillActivityDO::getSpuId, spuId)
.orderByDesc(SeckillActivityDO::getCreateTime)
, false);
}
} }

View File

@ -98,4 +98,12 @@ public interface BargainActivityService {
*/ */
List<BargainActivityDO> getBargainActivityListByCount(Integer count); List<BargainActivityDO> getBargainActivityListByCount(Integer count);
/**
* 获取指定 spu 编号的活动
*
* @param spuId spu 编号
* @return 砍价活动
*/
BargainActivityDO getBargainActivityBySpuId(Long spuId);
} }

View File

@ -175,4 +175,9 @@ public class BargainActivityServiceImpl implements BargainActivityService {
return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
} }
@Override
public BargainActivityDO getBargainActivityBySpuId(Long spuId) {
return bargainActivityMapper.selectOne(spuId);
}
} }

View File

@ -109,4 +109,12 @@ public interface CombinationActivityService {
*/ */
CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId);
/**
* 获取指定 spu 编号的活动
*
* @param spuId spu 编号
* @return 拼团商品
*/
CombinationActivityDO getCombinationActivityBySpuId(Long spuId);
} }

View File

@ -223,4 +223,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
CombinationProductDO::getSkuId, skuId); CombinationProductDO::getSkuId, skuId);
} }
@Override
public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) {
return combinationActivityMapper.selectOne(spuId);
}
} }

View File

@ -119,4 +119,12 @@ public interface SeckillActivityService {
*/ */
SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count);
/**
* 获取指定 spu 编号的活动
*
* @param spuId spu 编号
* @return 秒杀商品
*/
SeckillActivityDO getSeckillActivityBySpuId(Long spuId);
} }

View File

@ -310,4 +310,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
return SeckillActivityConvert.INSTANCE.convert02(activity, product); return SeckillActivityConvert.INSTANCE.convert02(activity, product);
} }
@Override
public SeckillActivityDO getSeckillActivityBySpuId(Long spuId) {
return seckillActivityMapper.selectOne(spuId);
}
} }