Search in sources :

Example 6 with SeckillItem

use of com.whoiszxl.entity.SeckillItem in project shopzz by whoiszxl.

the class DefaultPlaceOrderServiceImpl method checkSeckillItem.

private boolean checkSeckillItem(Long seckillItemId) {
    SeckillItemCache seckillItemCache = seckillItemCachedService.getCachedSeckillItem(seckillItemId, null);
    // 2. 校验缓存是否需要延迟加载
    if (!seckillItemCache.isLater()) {
        log.info("从缓存中获取秒杀商品信息需要延迟加载, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 3. 校验活动是否存在
    if (!seckillItemCache.isExist() || seckillItemCache.getSeckillItem() == null) {
        log.info("秒杀商品不存在, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 4. 校验活动是否上线
    SeckillItem seckillItem = seckillItemCache.getSeckillItem();
    if (!seckillItem.getStatus().equals(StatusEnum.OPEN.getCode())) {
        log.info("秒杀商品未开启, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 5. 校验活动是否在进行中
    LocalDateTime now = LocalDateTime.now();
    if (!seckillItem.getStartTime().isBefore(now) || !seckillItem.getEndTime().isAfter(now)) {
        log.info("秒杀商品未在开启时间内, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    return false;
}
Also used : SeckillItem(com.whoiszxl.entity.SeckillItem) LocalDateTime(java.time.LocalDateTime) SeckillItemCache(com.whoiszxl.cqrs.cache.SeckillItemCache)

Example 7 with SeckillItem

use of com.whoiszxl.entity.SeckillItem in project shopzz by whoiszxl.

the class SeckillItemWarmUpTask method warmUpSeckillItem.

/**
 * 秒杀商品预热任务,五秒一次
 * TODO 修改为xxl-job调用
 */
@Scheduled(cron = "*/5 * * * * ?")
public void warmUpSeckillItem() {
    log.info("warmUpSeckillItem|秒杀商品预热任务开始执行");
    // 获取DB中所有未预热的秒杀商品
    List<SeckillItem> seckillItemList = seckillItemService.list(Wrappers.<SeckillItem>lambdaQuery().eq(SeckillItem::getWarmUpStatus, WarmUpStatusEnum.NO.getCode()));
    for (SeckillItem seckillItem : seckillItemList) {
        boolean initFlag = stockCacheService.initItemStock(seckillItem.getId());
        if (!initFlag) {
            log.info("warmUpSeckillItem|秒杀商品预热失败|{}", seckillItem.getId());
            continue;
        }
        seckillItemService.update(Wrappers.<SeckillItem>lambdaUpdate().set(SeckillItem::getWarmUpStatus, WarmUpStatusEnum.YES.getCode()).set(SeckillItem::getStatus, SeckillItemStatusEnum.OPEN.getCode()).eq(SeckillItem::getId, seckillItem.getId()));
        log.info("warmUpSeckillItem|秒杀商品预热成功|{}", seckillItem.getId());
    }
    log.info("warmUpSeckillItem|秒杀商品预热任务执行结束");
}
Also used : SeckillItem(com.whoiszxl.entity.SeckillItem) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 8 with SeckillItem

use of com.whoiszxl.entity.SeckillItem in project shopzz by whoiszxl.

the class QueuedPlaceOrderServiceImpl method checkSeckillItem.

private boolean checkSeckillItem(Long seckillItemId) {
    SeckillItemCache seckillItemCache = seckillItemCachedService.getCachedSeckillItem(seckillItemId, null);
    // 2. 校验缓存是否需要延迟加载
    if (seckillItemCache.isLater()) {
        log.info("从缓存中获取秒杀商品信息需要延迟加载, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 3. 校验活动是否存在
    if (!seckillItemCache.isExist() || seckillItemCache.getSeckillItem() == null) {
        log.info("秒杀商品不存在, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 4. 校验活动是否上线
    SeckillItem seckillItem = seckillItemCache.getSeckillItem();
    if (!seckillItem.getStatus().equals(StatusEnum.OPEN.getCode())) {
        log.info("秒杀商品未开启, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    // 5. 校验活动是否在进行中
    LocalDateTime now = LocalDateTime.now();
    if (!seckillItem.getStartTime().isBefore(now) || !seckillItem.getEndTime().isAfter(now)) {
        log.info("秒杀商品未在开启时间内, 秒杀商品ID: {}", seckillItemId);
        return false;
    }
    return true;
}
Also used : SeckillItem(com.whoiszxl.entity.SeckillItem) LocalDateTime(java.time.LocalDateTime) SeckillItemCache(com.whoiszxl.cqrs.cache.SeckillItemCache)

Example 9 with SeckillItem

use of com.whoiszxl.entity.SeckillItem in project shopzz by whoiszxl.

the class SeckillItemAdminController method update.

@SaCheckLogin
@PutMapping
@ApiOperation(value = "更新秒杀商品", notes = "更新秒杀商品", response = ResponseResult.class)
public ResponseResult<Boolean> update(@RequestBody SeckillItemUpdateCommand bannerSaveCommand) {
    SeckillItem seckillItem = dozerUtils.map(bannerSaveCommand, SeckillItem.class);
    boolean updateFlag = seckillItemService.updateById(seckillItem);
    return ResponseResult.buildByFlag(updateFlag);
}
Also used : SeckillItem(com.whoiszxl.entity.SeckillItem) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SeckillItem (com.whoiszxl.entity.SeckillItem)9 SeckillItemCache (com.whoiszxl.cqrs.cache.SeckillItemCache)4 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)2 SeckillOrder (com.whoiszxl.entity.SeckillOrder)2 ApiOperation (io.swagger.annotations.ApiOperation)2 LocalDateTime (java.time.LocalDateTime)2 DistributedLock (com.whoiszxl.DistributedLock)1 DefaultRedisScript (org.springframework.data.redis.core.script.DefaultRedisScript)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 Transactional (org.springframework.transaction.annotation.Transactional)1