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 c04e6a8e1..59a9e781e 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 @@ -1,23 +1,13 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity; -import cn.hutool.core.collection.CollUtil; -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.module.product.api.spu.ProductSpuApi; 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.discount.DiscountActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.discount.DiscountProductDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; -import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; 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.discount.DiscountActivityService; -import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService; import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -29,12 +19,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口 @RestController @@ -48,125 +36,31 @@ public class AppActivityController { private SeckillActivityService seckillActivityService; @Resource private BargainActivityService bargainActivityService; - @Resource - private DiscountActivityService discountActivityService; - @Resource - private RewardActivityService rewardActivityService; - - @Resource - private ProductSpuApi productSpuApi; @GetMapping("/list-by-spu-id") - @Operation(summary = "获得单个商品,近期参与的每个活动") + @Operation(summary = "获得单个商品,进行中的拼团、秒杀、砍价活动信息", description = "每种活动,只返回一个") @Parameter(name = "spuId", description = "商品编号", required = true) public CommonResult> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { - // 每种活动,只返回一个 - return success(getAppActivityList(Collections.singletonList(spuId))); - } - - @GetMapping("/list-by-spu-ids") - @Operation(summary = "获得多个商品,近期参与的每个活动") - @Parameter(name = "spuIds", description = "商品编号数组", required = true) - public CommonResult>> getActivityListBySpuIds(@RequestParam("spuIds") List spuIds) { - if (CollUtil.isEmpty(spuIds)) { - return success(MapUtil.empty()); - } - // 每种活动,只返回一个;key 为 SPU 编号 - return success(convertMultiMap(getAppActivityList(spuIds), AppActivityRespVO::getSpuId)); - } - - private List getAppActivityList(Collection spuIds) { - if (CollUtil.isEmpty(spuIds)) { - return new ArrayList<>(); - } - // 获取开启的且开始的且没有结束的活动 - List activityList = new ArrayList<>(); - LocalDateTime now = LocalDateTime.now(); + List activityVOList = new ArrayList<>(); // 1. 拼团活动 - getCombinationActivities(spuIds, now, activityList); + CombinationActivityDO combinationActivity = combinationActivityService.getMatchCombinationActivityBySpuId(spuId); + if (combinationActivity != null) { + activityVOList.add(new AppActivityRespVO(combinationActivity.getId(), PromotionTypeEnum.COMBINATION_ACTIVITY.getType(), + combinationActivity.getName(), combinationActivity.getSpuId(), combinationActivity.getStartTime(), combinationActivity.getEndTime())); + } // 2. 秒杀活动 - getSeckillActivities(spuIds, now, activityList); + SeckillActivityDO seckillActivity = seckillActivityService.getMatchSeckillActivityBySpuId(spuId); + if (seckillActivity != null) { + activityVOList.add(new AppActivityRespVO(seckillActivity.getId(), PromotionTypeEnum.SECKILL_ACTIVITY.getType(), + seckillActivity.getName(), seckillActivity.getSpuId(), seckillActivity.getStartTime(), seckillActivity.getEndTime())); + } // 3. 砍价活动 - getBargainActivities(spuIds, now, activityList); - // 4. 限时折扣活动 - getDiscountActivities(spuIds, now, activityList); - // 5. 满减送活动 - getRewardActivityList(spuIds, now, activityList); - return activityList; - } - - private void getCombinationActivities(Collection spuIds, LocalDateTime now, List activityList) { - List combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatusAndDateTimeLt( - spuIds, CommonStatusEnum.ENABLE.getStatus(), now); - if (CollUtil.isEmpty(combinationActivities)) { - return; - } - - combinationActivities.forEach(item -> { - activityList.add(new AppActivityRespVO(item.getId(), PromotionTypeEnum.COMBINATION_ACTIVITY.getType(), - item.getName(), item.getSpuId(), item.getStartTime(), item.getEndTime())); - }); - } - - private void getSeckillActivities(Collection spuIds, LocalDateTime now, List activityList) { - List seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatusAndDateTimeLt( - spuIds, CommonStatusEnum.ENABLE.getStatus(), now); - if (CollUtil.isEmpty(seckillActivities)) { - return; - } - - seckillActivities.forEach(item -> { - activityList.add(new AppActivityRespVO(item.getId(), PromotionTypeEnum.SECKILL_ACTIVITY.getType(), - item.getName(), item.getSpuId(), item.getStartTime(), item.getEndTime())); - }); - } - - private void getBargainActivities(Collection spuIds, LocalDateTime now, List activityList) { - List bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatusAndDateTimeLt( - spuIds, CommonStatusEnum.ENABLE.getStatus(), now); - if (CollUtil.isNotEmpty(bargainActivities)) { - return; - } - - bargainActivities.forEach(item -> { - activityList.add(new AppActivityRespVO(item.getId(), PromotionTypeEnum.BARGAIN_ACTIVITY.getType(), - item.getName(), item.getSpuId(), item.getStartTime(), item.getEndTime())); - }); - } - - private void getDiscountActivities(Collection spuIds, LocalDateTime now, List activityList) { - List discountActivities = discountActivityService.getDiscountActivityBySpuIdsAndStatusAndDateTimeLt( - spuIds, CommonStatusEnum.ENABLE.getStatus(), now); - if (CollUtil.isEmpty(discountActivities)) { - return; - } - - List products = discountActivityService.getDiscountProductsByActivityId( - convertSet(discountActivities, DiscountActivityDO::getId)); - Map productMap = convertMap(products, DiscountProductDO::getActivityId, DiscountProductDO::getSpuId); - discountActivities.forEach(item -> activityList.add(new AppActivityRespVO(item.getId(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType(), - item.getName(), productMap.get(item.getId()), item.getStartTime(), item.getEndTime()))); - } - - private void getRewardActivityList(Collection spuIds, LocalDateTime now, List activityList) { - List rewardActivities = rewardActivityService.getRewardActivityBySpuIdsAndStatusAndDateTimeLt( - spuIds, CommonStatusEnum.ENABLE.getStatus(), now); - if (CollUtil.isEmpty(rewardActivities)) { - return; - } - - Map> spuIdAndActivityMap = spuIds.stream().collect(Collectors.toMap(spuId -> spuId, spuId -> rewardActivities.stream() - .filter(activity -> PromotionProductScopeEnum.isAll(activity.getProductScope()) - || PromotionProductScopeEnum.isSpu(activity.getProductScope()) // 商品范围 - && CollUtil.contains(activity.getProductScopeValues(), spuId) - || PromotionProductScopeEnum.isCategory(activity.getProductScope()) // 分类范围 - && CollUtil.contains(activity.getProductScopeValues(), productSpuApi.getSpu(spuId).getCategoryId())) - .max(Comparator.comparing(RewardActivityDO::getCreateTime)))); - for (Long supId : spuIdAndActivityMap.keySet()) { - spuIdAndActivityMap.get(supId).ifPresent(rewardActivity -> activityList.add( - new AppActivityRespVO(rewardActivity.getId(), PromotionTypeEnum.REWARD_ACTIVITY.getType(), - rewardActivity.getName(), supId, rewardActivity.getStartTime(), rewardActivity.getEndTime()))); + BargainActivityDO bargainActivity = bargainActivityService.getMatchBargainActivityBySpuId(spuId); + if (bargainActivity != null) { + activityVOList.add(new AppActivityRespVO(bargainActivity.getId(), PromotionTypeEnum.BARGAIN_ACTIVITY.getType(), + bargainActivity.getName(), bargainActivity.getSpuId(), bargainActivity.getStartTime(), bargainActivity.getEndTime())); } + return success(activityVOList); } } 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 72d604e77..08783bd34 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 @@ -6,14 +6,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.time.LocalDateTime; -import java.util.Collection; import java.util.List; -import java.util.Map; /** * 砍价活动 Mapper @@ -86,35 +83,13 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } - /** - * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - * - * @param spuIds spu 编号 - * @param status 状态 - * @return 包含 spuId 和 activityId 的 map 对象列表 - */ - default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(Collection spuIds, Integer status) { - return selectMaps(new QueryWrapper() - .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id - .in("spu_id", spuIds) - .eq("status", status) - .groupBy("spu_id")); - } - - /** - * 获取指定活动编号的活动列表且 - * 开始时间和结束时间小于给定时间 dateTime 的活动列表 - * - * @param ids 活动编号 - * @param dateTime 指定日期 - * @return 活动列表 - */ - default List selectListByIdsAndDateTimeLt(Collection ids, LocalDateTime dateTime) { - return selectList(new LambdaQueryWrapperX() - .in(BargainActivityDO::getId, ids) - .lt(BargainActivityDO::getStartTime, dateTime) - .gt(BargainActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间,也就是说获取指定时间段的活动 - .orderByDesc(BargainActivityDO::getCreateTime)); + default BargainActivityDO selectBySpuIdAndStatusAndNow(Long spuId, Integer status) { + LocalDateTime now = LocalDateTime.now(); + return selectOne(new LambdaQueryWrapperX() + .eq(BargainActivityDO::getSpuId, spuId) + .eq(BargainActivityDO::getStatus, status) + .lt(BargainActivityDO::getStartTime, now) + .gt(BargainActivityDO::getEndTime, now)); // 开始时间 < now < 结束时间,也就是说获取指定时间段的活动 } } 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 55e975c45..df909a67c 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 @@ -6,14 +6,10 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.Collection; import java.util.List; -import java.util.Map; /** * 拼团活动 Mapper @@ -39,40 +35,13 @@ public interface CombinationActivityMapper extends BaseMapperX selectListByStatus(Integer status, Integer count) { - return selectList(new LambdaQueryWrapperX() + default CombinationActivityDO selectBySpuIdAndStatusAndNow(Long spuId, Integer status) { + LocalDateTime now = LocalDateTime.now(); + return selectOne(new LambdaQueryWrapperX() + .eq(CombinationActivityDO::getSpuId, spuId) .eq(CombinationActivityDO::getStatus, status) - .last("LIMIT " + count)); + .lt(CombinationActivityDO::getStartTime, now) + .gt(CombinationActivityDO::getEndTime, now)); // 开始时间 < now < 结束时间,也就是说获取指定时间段的活动 } - /** - * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - * @param spuIds spu 编号 - * @param status 状态 - * @return 包含 spuId 和 activityId 的 map 对象列表 - */ - default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { - return selectMaps(new QueryWrapper() - .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id - .in("spu_id", spuIds) - .eq("status", status) - .groupBy("spu_id")); - } - - /** - * 获取指定活动编号的活动列表且 - * 开始时间和结束时间小于给定时间 dateTime 的活动列表 - * - * @param ids 活动编号 - * @param dateTime 指定日期 - * @return 活动列表 - */ - default List selectListByIdsAndDateTimeLt(Collection ids, LocalDateTime dateTime) { - return selectList(new LambdaQueryWrapperX() - .in(CombinationActivityDO::getId, ids) - .lt(CombinationActivityDO::getStartTime, dateTime) - .gt(CombinationActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间,也就是说获取指定时间段的活动 - .orderByDesc(CombinationActivityDO::getCreateTime)); - } - -} +} \ No newline at end of file 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 3d30111fd..51d3309b3 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 @@ -8,15 +8,11 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.Collection; import java.util.List; -import java.util.Map; /** * 秒杀活动 Mapper @@ -77,35 +73,13 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } - /** - * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - * - * @param spuIds spu 编号 - * @param status 状态 - * @return 包含 spuId 和 activityId 的 map 对象列表 - */ - default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { - return selectMaps(new QueryWrapper() - .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id - .in("spu_id", spuIds) - .eq("status", status) - .groupBy("spu_id")); - } - - /** - * 获取指定活动编号的活动列表且 - * 开始时间和结束时间小于给定时间 dateTime 的活动列表 - * - * @param ids 活动编号 - * @param dateTime 指定日期 - * @return 活动列表 - */ - default List selectListByIdsAndDateTimeLt(Collection ids, LocalDateTime dateTime) { - return selectList(new LambdaQueryWrapperX() - .in(SeckillActivityDO::getId, ids) - .lt(SeckillActivityDO::getStartTime, dateTime) - .gt(SeckillActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间,也就是说获取指定时间段的活动 - .orderByDesc(SeckillActivityDO::getCreateTime)); + default SeckillActivityDO selectBySpuIdAndStatusAndNow(Long spuId, Integer status) { + LocalDateTime now = LocalDateTime.now(); + return selectOne(new LambdaQueryWrapperX() + .eq(SeckillActivityDO::getSpuId, spuId) + .eq(SeckillActivityDO::getStatus, status) + .lt(SeckillActivityDO::getStartTime, now) + .gt(SeckillActivityDO::getEndTime, now)); // 开始时间 < now < 结束时间,也就是说获取指定时间段的活动 } } 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 789a3c520..73d13d597 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 @@ -6,10 +6,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; - import jakarta.validation.Valid; -import java.time.LocalDateTime; -import java.util.Collection; + import java.util.List; import java.util.Set; @@ -108,13 +106,11 @@ public interface BargainActivityService { List getBargainActivityListByCount(Integer count); /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * 获得 SPU 进行中的砍价活动 * - * @param spuIds spu 编号 - * @param status 状态 - * @param dateTime 日期时间 - * @return 砍价活动列表 + * @param spuId SPU 编号数组 + * @return 砍价活动 */ - List getBargainActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime); + BargainActivityDO getMatchBargainActivityBySpuId(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 f145fc665..165b0167e 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 @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.promotion.service.bargain; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -15,17 +13,17 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainActivityMapper; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.time.LocalDateTime; -import java.util.*; +import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -194,15 +192,8 @@ public class BargainActivityServiceImpl implements BargainActivityService { } @Override - public List getBargainActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime) { - // 1. 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - List> spuIdAndActivityIdMaps = bargainActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); - if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { - return Collections.emptyList(); - } - // 2. 查询活动详情 - return bargainActivityMapper.selectListByIdsAndDateTimeLt( - convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); + public BargainActivityDO getMatchBargainActivityBySpuId(Long spuId) { + return bargainActivityMapper.selectBySpuIdAndStatusAndNow(spuId, CommonStatusEnum.ENABLE.getStatus()); } } 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 6f9b62729..759d6a589 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 @@ -7,9 +7,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; - import jakarta.validation.Valid; -import java.time.LocalDateTime; + import java.util.Collection; import java.util.Collections; import java.util.List; @@ -109,22 +108,20 @@ public interface CombinationActivityService { PageResult getCombinationActivityPage(PageParam pageParam); /** - * 获取指定活动、指定 sku 编号的商品 + * 获取指定活动、指定 SKU 编号的商品 * * @param activityId 活动编号 - * @param skuId sku 编号 + * @param skuId SKU 编号 * @return 活动商品信息 */ CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * 获得 SPU 进行中的拼团活动 * - * @param spuIds spu 编号 - * @param status 状态 - * @param dateTime 日期时间 - * @return 拼团活动列表 + * @param spuId SPU 编号数组 + * @return 拼团活动 */ - List getCombinationActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime); + CombinationActivityDO getMatchCombinationActivityBySpuId(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 f45a2168e..8e168f4f9 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 @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -20,19 +19,18 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationA import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationProductMapper; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; -import java.time.LocalDateTime; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -178,7 +176,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic combinationProductMapper.updateBatch(diffList.get(1)); } if (CollUtil.isNotEmpty(diffList.get(2))) { - combinationProductMapper.deleteBatchIds(CollectionUtils.convertList(diffList.get(2), CombinationProductDO::getId)); + combinationProductMapper.deleteByIds(CollectionUtils.convertList(diffList.get(2), CombinationProductDO::getId)); } } @@ -238,15 +236,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getCombinationActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime) { - // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - List> spuIdAndActivityIdMaps = combinationActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); - if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { - return Collections.emptyList(); - } - // 2.查询活动详情 - return combinationActivityMapper.selectListByIdsAndDateTimeLt( - convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); + public CombinationActivityDO getMatchCombinationActivityBySpuId(Long spuId) { + return combinationActivityMapper.selectBySpuIdAndStatusAndNow(spuId, CommonStatusEnum.ENABLE.getStatus()); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityService.java index e08c7e2b5..aea898177 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityService.java @@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.discount.DiscountActivit import cn.iocoder.yudao.module.promotion.dal.dataobject.discount.DiscountProductDO; import jakarta.validation.Valid; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -91,14 +90,11 @@ public interface DiscountActivityService { List getDiscountProductsByActivityId(Collection activityIds); /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * 获取指定 SPU 编号最近参加的活动,每个 spuId 只返回一条记录 * - * @param spuIds spu 编号 - * @param status 状态 - * @param dateTime 当前日期时间 + * @param spuIds SPU 编号数组 * @return 折扣活动列表 */ - List getDiscountActivityBySpuIdsAndStatusAndDateTimeLt( - Collection spuIds, Integer status, LocalDateTime dateTime); + List getDiscountActivityListBySpuIds(Collection spuIds); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java index 2b4b858b0..89a4a9bdf 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java @@ -189,16 +189,17 @@ public class DiscountActivityServiceImpl implements DiscountActivityService { } @Override - public List getDiscountActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime) { + public List getDiscountActivityListBySpuIds(Collection spuIds) { // 1. 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - List> spuIdAndActivityIdMaps = discountProductMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); + List> spuIdAndActivityIdMaps = discountProductMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus( + spuIds, CommonStatusEnum.ENABLE.getStatus()); if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { return Collections.emptyList(); } // 2. 查询活动详情 return discountActivityMapper.selectListByIdsAndDateTimeLt( - convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); + convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), LocalDateTime.now()); } } 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 b01aa6b77..f2a353dd6 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 @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityD import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import jakarta.validation.Valid; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -130,14 +129,12 @@ public interface SeckillActivityService { SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * 获得 SPU 进行中的秒杀活动 * - * @param spuIds spu 编号 - * @param status 状态 - * @param dateTime 日期时间 - * @return 秒杀活动列表 + * @param spuId SPU 编号数组 + * @return 秒杀活动 */ - List getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime); + SeckillActivityDO getMatchSeckillActivityBySpuId(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 eb007fa9e..bdb199455 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 @@ -1,8 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -30,7 +28,6 @@ import org.springframework.validation.annotation.Validated; import java.time.LocalDateTime; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -56,8 +53,10 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { private SeckillActivityMapper seckillActivityMapper; @Resource private SeckillProductMapper seckillProductMapper; + @Resource private SeckillConfigService seckillConfigService; + @Resource private ProductSpuApi productSpuApi; @Resource @@ -219,7 +218,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { seckillProductMapper.updateBatch(diffList.get(1)); } if (isNotEmpty(diffList.get(2))) { - seckillProductMapper.deleteBatchIds(convertList(diffList.get(2), SeckillProductDO::getId)); + seckillProductMapper.deleteByIds(convertList(diffList.get(2), SeckillProductDO::getId)); } } @@ -249,7 +248,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { seckillActivityMapper.deleteById(id); // 删除活动商品 List products = seckillProductMapper.selectListByActivityId(id); - seckillProductMapper.deleteBatchIds(convertSet(products, SeckillProductDO::getId)); + seckillProductMapper.deleteByIds(convertSet(products, SeckillProductDO::getId)); } private SeckillActivityDO validateSeckillActivityExists(Long id) { @@ -325,20 +324,13 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } @Override - public List getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime) { - // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 - List> spuIdAndActivityIdMaps = seckillActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); - if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { - return Collections.emptyList(); - } - // 2.查询活动详情 - return seckillActivityMapper.selectListByIdsAndDateTimeLt( - convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); + public SeckillActivityDO getMatchSeckillActivityBySpuId(Long spuId) { + return seckillActivityMapper.selectBySpuIdAndStatusAndNow(spuId, CommonStatusEnum.ENABLE.getStatus()); } @Override public List getSeckillActivityListByIds(Collection ids) { - return List.of(); + return seckillActivityMapper.selectBatchIds(ids); } }