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;
}
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|秒杀商品预热任务执行结束");
}
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;
}
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);
}
Aggregations