mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
营销活动:实现 list-by-spu-id 接口
This commit is contained in:
parent
3f6f7f404b
commit
07493bc7e5
@ -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<List<AppActivityRespVO>> getActivityListBySpuId(@RequestParam("spuId") Long spuId) {
|
||||
// TODO 芋艿,实现
|
||||
List<AppActivityRespVO> 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<AppActivityRespVO> 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:可以实现下
|
||||
|
@ -83,4 +83,11 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
|
||||
.last("LIMIT " + count));
|
||||
}
|
||||
|
||||
default BargainActivityDO selectOne(Long spuId) {
|
||||
return selectOne(new LambdaQueryWrapperX<BargainActivityDO>()
|
||||
.eq(BargainActivityDO::getSpuId, spuId)
|
||||
.orderByDesc(BargainActivityDO::getCreateTime)
|
||||
, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,4 +40,11 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
|
||||
.last("LIMIT " + count));
|
||||
}
|
||||
|
||||
default CombinationActivityDO selectOne(Long spuId) {
|
||||
return selectOne(new LambdaQueryWrapperX<CombinationActivityDO>()
|
||||
.eq(CombinationActivityDO::getSpuId, spuId)
|
||||
.orderByDesc(CombinationActivityDO::getCreateTime)
|
||||
, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,4 +56,11 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -98,4 +98,12 @@ public interface BargainActivityService {
|
||||
*/
|
||||
List<BargainActivityDO> getBargainActivityListByCount(Integer count);
|
||||
|
||||
/**
|
||||
* 获取指定 spu 编号的活动
|
||||
*
|
||||
* @param spuId spu 编号
|
||||
* @return 砍价活动
|
||||
*/
|
||||
BargainActivityDO getBargainActivityBySpuId(Long spuId);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -109,4 +109,12 @@ public interface CombinationActivityService {
|
||||
*/
|
||||
CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId);
|
||||
|
||||
/**
|
||||
* 获取指定 spu 编号的活动
|
||||
*
|
||||
* @param spuId spu 编号
|
||||
* @return 拼团商品
|
||||
*/
|
||||
CombinationActivityDO getCombinationActivityBySpuId(Long spuId);
|
||||
|
||||
}
|
||||
|
@ -223,4 +223,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
|
||||
CombinationProductDO::getSkuId, skuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) {
|
||||
return combinationActivityMapper.selectOne(spuId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,4 +119,12 @@ public interface SeckillActivityService {
|
||||
*/
|
||||
SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count);
|
||||
|
||||
/**
|
||||
* 获取指定 spu 编号的活动
|
||||
*
|
||||
* @param spuId spu 编号
|
||||
* @return 秒杀商品
|
||||
*/
|
||||
SeckillActivityDO getSeckillActivityBySpuId(Long spuId);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user