【BUG】修改秒杀根据时间段开判断是否开启活动

This commit is contained in:
痴货 2024-09-14 19:52:31 +08:00
parent 7873f1400e
commit b092906a66
3 changed files with 24 additions and 3 deletions

View File

@ -98,9 +98,10 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
* @param dateTime 指定日期 * @param dateTime 指定日期
* @return 活动列表 * @return 活动列表
*/ */
default List<SeckillActivityDO> selectListByIdsAndDateTimeLt(Collection<Long> ids, LocalDateTime dateTime) { default List<SeckillActivityDO> selectListByIdsAndDateTimeLt(Collection<Long> ids, List<Long> confidIds, LocalDateTime dateTime) {
return selectList(new LambdaQueryWrapperX<SeckillActivityDO>() return selectList(new LambdaQueryWrapperX<SeckillActivityDO>()
.in(SeckillActivityDO::getId, ids) .in(SeckillActivityDO::getId, ids)
.in(SeckillActivityDO::getConfigIds,confidIds)
.lt(SeckillActivityDO::getStartTime, dateTime) .lt(SeckillActivityDO::getStartTime, dateTime)
.gt(SeckillActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间也就是说获取指定时间段的活动 .gt(SeckillActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间也就是说获取指定时间段的活动
.orderByDesc(SeckillActivityDO::getCreateTime)); .orderByDesc(SeckillActivityDO::getCreateTime));

View File

@ -1,12 +1,16 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig; package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@Mapper @Mapper
@ -23,4 +27,13 @@ public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> {
return selectList(SeckillConfigDO::getStatus, status); return selectList(SeckillConfigDO::getStatus, status);
} }
default List<SeckillConfigDO> selectListByIdsAndDateTimeLt(LocalDateTime dateTime){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
String format = formatter.format(dateTime);
return selectList(new LambdaQueryWrapper<SeckillConfigDO>()
.eq(SeckillConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
.lt(SeckillConfigDO::getStartTime, format)
.gt(SeckillConfigDO::getEndTime, format));
}
} }

View File

@ -23,6 +23,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig.SeckillConfigMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -33,6 +34,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import static cn.hutool.core.collection.CollUtil.isNotEmpty; import static cn.hutool.core.collection.CollUtil.isNotEmpty;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -57,6 +59,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Resource @Resource
private SeckillProductMapper seckillProductMapper; private SeckillProductMapper seckillProductMapper;
@Resource @Resource
private SeckillConfigMapper seckillConfigMapper;
@Resource
private SeckillConfigService seckillConfigService; private SeckillConfigService seckillConfigService;
@Resource @Resource
private ProductSpuApi productSpuApi; private ProductSpuApi productSpuApi;
@ -331,9 +335,12 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) {
return Collections.emptyList(); return Collections.emptyList();
} }
// 2.查询活动详情 // 2.查询当前时间属于哪个时间段
List<SeckillConfigDO> seckillConfigList= seckillConfigMapper.selectListByIdsAndDateTimeLt(dateTime);
List<Long> confidIds = seckillConfigList.stream().map(SeckillConfigDO::getId).collect(Collectors.toList());
// 3.查询活动详情
return seckillActivityMapper.selectListByIdsAndDateTimeLt( return seckillActivityMapper.selectListByIdsAndDateTimeLt(
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), confidIds, dateTime);
} }
} }