mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【BUG】修改秒杀根据时间段开判断是否开启活动
This commit is contained in:
parent
7873f1400e
commit
b092906a66
@ -98,9 +98,10 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
|
||||
* @param dateTime 指定日期
|
||||
* @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>()
|
||||
.in(SeckillActivityDO::getId, ids)
|
||||
.in(SeckillActivityDO::getConfigIds,confidIds)
|
||||
.lt(SeckillActivityDO::getStartTime, dateTime)
|
||||
.gt(SeckillActivityDO::getEndTime, dateTime)// 开始时间 < 指定时间 < 结束时间,也就是说获取指定时间段的活动
|
||||
.orderByDesc(SeckillActivityDO::getCreateTime));
|
||||
|
@ -1,12 +1,16 @@
|
||||
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.mybatis.core.mapper.BaseMapperX;
|
||||
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.dal.dataobject.seckill.SeckillConfigDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@ -23,4 +27,13 @@ public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.mysql.seckill.seckillactivity.SeckillActivityMapper;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -33,6 +34,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.hutool.core.collection.CollUtil.isNotEmpty;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@ -57,6 +59,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
@Resource
|
||||
private SeckillProductMapper seckillProductMapper;
|
||||
@Resource
|
||||
private SeckillConfigMapper seckillConfigMapper;
|
||||
@Resource
|
||||
private SeckillConfigService seckillConfigService;
|
||||
@Resource
|
||||
private ProductSpuApi productSpuApi;
|
||||
@ -331,9 +335,12 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) {
|
||||
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(
|
||||
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime);
|
||||
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), confidIds, dateTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user