use of com.actionworks.flashsale.domain.model.entity.FlashItem in project flash-sale by ThoughtsBeta.
the class FlashItemWarmUpScheduler method warmUpFlashItemTask.
@Scheduled(cron = "*/5 * * * * ?")
@BetaTrace
public void warmUpFlashItemTask() {
logger.info("warmUpFlashItemTask|秒杀品预热调度");
PagesQueryCondition pagesQueryCondition = new PagesQueryCondition();
pagesQueryCondition.setStockWarmUp(0);
PageResult<FlashItem> pageResult = flashItemDomainService.getFlashItems(pagesQueryCondition);
pageResult.getData().forEach(flashItem -> {
boolean initSuccess = itemStockCacheService.alignItemStocks(flashItem.getId());
if (!initSuccess) {
logger.info("warmUpFlashItemTask|秒杀品库存已经初始化预热失败", flashItem.getId());
return;
}
flashItem.setStockWarmUp(1);
flashItemDomainService.publishFlashItem(flashItem);
logger.info("warmUpFlashItemTask|秒杀品库存已经初始化预热成功", flashItem.getId());
});
}
use of com.actionworks.flashsale.domain.model.entity.FlashItem in project flash-sale by ThoughtsBeta.
the class FlashItemAppBuilder method toDomain.
public static FlashItem toDomain(FlashItemPublishCommand flashItemPublishCommand) {
FlashItem flashItem = new FlashItem();
BeanUtils.copyProperties(flashItemPublishCommand, flashItem);
return flashItem;
}
use of com.actionworks.flashsale.domain.model.entity.FlashItem in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method getFlashItems.
@Override
public PageResult<FlashItem> getFlashItems(PagesQueryCondition pagesQueryCondition) {
if (pagesQueryCondition == null) {
pagesQueryCondition = new PagesQueryCondition();
}
List<FlashItem> flashItems = flashItemRepository.findFlashItemsByCondition(pagesQueryCondition.buildParams());
Integer total = flashItemRepository.countFlashItemsByCondition(pagesQueryCondition);
logger.info("Get flash items:{}", flashItems.size());
return PageResult.with(flashItems, total);
}
use of com.actionworks.flashsale.domain.model.entity.FlashItem in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method onlineFlashItem.
@Override
public void onlineFlashItem(Long itemId) {
logger.info("itemOnline|上线秒杀品|{}", itemId);
if (itemId == null) {
throw new DomainException(PARAMS_INVALID);
}
Optional<FlashItem> flashItemOptional = flashItemRepository.findById(itemId);
if (!flashItemOptional.isPresent()) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
FlashItem flashItem = flashItemOptional.get();
if (FlashItemStatus.isOnline(flashItem.getStatus())) {
return;
}
flashItem.setStatus(FlashItemStatus.ONLINE.getCode());
flashItemRepository.save(flashItem);
logger.info("itemOnline|秒杀品已上线|{}", itemId);
FlashItemEvent flashItemPublishEvent = new FlashItemEvent();
flashItemPublishEvent.setEventType(FlashItemEventType.ONLINE);
flashItemPublishEvent.setFlashItem(flashItem);
domainEventPublisher.publish(flashItemPublishEvent);
logger.info("itemOnline|秒杀品上线事件已发布|{}", itemId);
}
use of com.actionworks.flashsale.domain.model.entity.FlashItem in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method offlineFlashItem.
@Override
public void offlineFlashItem(Long itemId) {
logger.info("itemOffline|下线秒杀品|{}", itemId);
if (itemId == null) {
throw new DomainException(PARAMS_INVALID);
}
Optional<FlashItem> flashItemOptional = flashItemRepository.findById(itemId);
if (!flashItemOptional.isPresent()) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
FlashItem flashItem = flashItemOptional.get();
if (FlashItemStatus.isOffline(flashItem.getStatus())) {
return;
}
flashItem.setStatus(FlashItemStatus.OFFLINE.getCode());
flashItemRepository.save(flashItem);
logger.info("itemOffline|秒杀品已下线|{}", itemId);
FlashItemEvent flashItemEvent = new FlashItemEvent();
flashItemEvent.setEventType(FlashItemEventType.OFFLINE);
flashItemEvent.setFlashItem(flashItem);
domainEventPublisher.publish(flashItemEvent);
logger.info("itemOffline|秒杀品下线事件已发布|{}", itemId);
}
Aggregations