|
|
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
|
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.bargain.BargainActivityDO;
|
|
|
|
@ -21,12 +22,10 @@ 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 javax.annotation.Resource;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
|
|
|
|
|
|
|
|
|
|
|
|
@Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口
|
|
|
|
@Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@ -42,59 +41,72 @@ public class AppActivityController {
|
|
|
|
private BargainActivityService bargainActivityService;
|
|
|
|
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) {
|
|
|
|
return success(getAppActivityRespVOList(spuId));
|
|
|
|
// 每种活动,只返回一个
|
|
|
|
|
|
|
|
return success(getAppActivityRespVOList(Collections.singletonList(spuId)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/list-by-spu-ids")
|
|
|
|
@GetMapping("/list-by-spu-ids")
|
|
|
|
@Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号
|
|
|
|
@Operation(summary = "获得多个商品,近期参与的每个活动")
|
|
|
|
@Parameter(name = "spuIds", description = "商品编号数组", required = true)
|
|
|
|
@Parameter(name = "spuIds", description = "商品编号数组", required = true)
|
|
|
|
public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) {
|
|
|
|
public CommonResult<Map<Long, List<AppActivityRespVO>>> getActivityListBySpuIds(@RequestParam("spuIds") List<Long> spuIds) {
|
|
|
|
if (CollUtil.isEmpty(spuIds)) {
|
|
|
|
if (CollUtil.isEmpty(spuIds)) {
|
|
|
|
return success(MapUtil.empty());
|
|
|
|
return success(MapUtil.empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO @puhui999:要避免这种 1+n 的查询
|
|
|
|
// 每种活动,只返回一个;key 为 SPU 编号
|
|
|
|
Map<Long, List<AppActivityRespVO>> map = new HashMap<>(spuIds.size());
|
|
|
|
return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId));
|
|
|
|
spuIds.forEach(spuId -> {
|
|
|
|
|
|
|
|
map.put(spuId, getAppActivityRespVOList(spuId));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return success(map);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<AppActivityRespVO> getAppActivityRespVOList(Long spuId) {
|
|
|
|
private List<AppActivityRespVO> getAppActivityRespVOList(Collection<Long> spuIds) {
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(spuIds)) {
|
|
|
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<AppActivityRespVO> activityList = new ArrayList<>();
|
|
|
|
List<AppActivityRespVO> activityList = new ArrayList<>();
|
|
|
|
// 拼团活动
|
|
|
|
// 拼团活动
|
|
|
|
CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId);
|
|
|
|
List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus(
|
|
|
|
if (combination != null) {
|
|
|
|
spuIds, CommonStatusEnum.ENABLE.getStatus());
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
if (CollUtil.isNotEmpty(combinationActivities)) {
|
|
|
|
.setId(combination.getId())
|
|
|
|
combinationActivities.forEach(item -> {
|
|
|
|
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
.setName(combination.getName())
|
|
|
|
.setId(item.getId())
|
|
|
|
.setStartTime(combination.getStartTime())
|
|
|
|
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
|
|
|
|
.setEndTime(combination.getEndTime()));
|
|
|
|
.setName(item.getName())
|
|
|
|
|
|
|
|
.setSpuId(item.getSpuId())
|
|
|
|
|
|
|
|
.setStartTime(item.getStartTime())
|
|
|
|
|
|
|
|
.setEndTime(item.getEndTime()));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 秒杀活动
|
|
|
|
// 秒杀活动
|
|
|
|
SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId);
|
|
|
|
List<SeckillActivityDO> seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatus(
|
|
|
|
if (seckill != null) {
|
|
|
|
spuIds, CommonStatusEnum.ENABLE.getStatus());
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
if (CollUtil.isNotEmpty(seckillActivities)) {
|
|
|
|
.setId(seckill.getId())
|
|
|
|
seckillActivities.forEach(item -> {
|
|
|
|
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType())
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
.setName(seckill.getName())
|
|
|
|
.setId(item.getId())
|
|
|
|
.setStartTime(seckill.getStartTime())
|
|
|
|
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType())
|
|
|
|
.setEndTime(seckill.getEndTime()));
|
|
|
|
.setName(item.getName())
|
|
|
|
|
|
|
|
.setSpuId(item.getSpuId())
|
|
|
|
|
|
|
|
.setStartTime(item.getStartTime())
|
|
|
|
|
|
|
|
.setEndTime(item.getEndTime()));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 秒杀活动
|
|
|
|
// 砍价活动
|
|
|
|
BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId);
|
|
|
|
List<BargainActivityDO> bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatus(
|
|
|
|
if (bargain != null) {
|
|
|
|
spuIds, CommonStatusEnum.ENABLE.getStatus());
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
if (CollUtil.isNotEmpty(bargainActivities)) {
|
|
|
|
.setId(bargain.getId())
|
|
|
|
bargainActivities.forEach(item -> {
|
|
|
|
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType())
|
|
|
|
activityList.add(new AppActivityRespVO()
|
|
|
|
.setName(bargain.getName())
|
|
|
|
.setId(item.getId())
|
|
|
|
.setStartTime(bargain.getStartTime())
|
|
|
|
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType())
|
|
|
|
.setEndTime(bargain.getEndTime()));
|
|
|
|
.setName(item.getName())
|
|
|
|
|
|
|
|
.setSpuId(item.getSpuId())
|
|
|
|
|
|
|
|
.setStartTime(item.getStartTime())
|
|
|
|
|
|
|
|
.setEndTime(item.getEndTime()));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activityList;
|
|
|
|
return activityList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|