Search in sources :

Example 1 with FlashItem

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());
    });
}
Also used : FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition) Scheduled(org.springframework.scheduling.annotation.Scheduled) BetaTrace(com.actionworks.flashsale.config.annotion.BetaTrace)

Example 2 with FlashItem

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;
}
Also used : FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem)

Example 3 with 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);
}
Also used : FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Example 4 with FlashItem

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);
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashItemEvent(com.actionworks.flashsale.domain.event.FlashItemEvent) FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem)

Example 5 with FlashItem

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);
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashItemEvent(com.actionworks.flashsale.domain.event.FlashItemEvent) FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem)

Aggregations

FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)15 PagesQueryCondition (com.actionworks.flashsale.domain.model.PagesQueryCondition)4 DistributedLock (com.actionworks.flashsale.lock.DistributedLock)4 BizException (com.actionworks.flashsale.app.exception.BizException)3 FlashItemsCache (com.actionworks.flashsale.app.service.item.cache.model.FlashItemsCache)2 BetaTrace (com.actionworks.flashsale.config.annotion.BetaTrace)2 FlashItemEvent (com.actionworks.flashsale.domain.event.FlashItemEvent)2 DomainException (com.actionworks.flashsale.domain.exception.DomainException)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 AuthResult (com.actionworks.flashsale.app.auth.model.AuthResult)1 AppException (com.actionworks.flashsale.app.exception.AppException)1 FlashItemDTO (com.actionworks.flashsale.app.model.dto.FlashItemDTO)1 FlashItemCache (com.actionworks.flashsale.app.service.item.cache.model.FlashItemCache)1 OrderNoGenerateContext (com.actionworks.flashsale.app.util.OrderNoGenerateContext)1 AuthException (com.actionworks.flashsale.controller.exception.AuthException)1 StockDeduction (com.actionworks.flashsale.domain.model.StockDeduction)1 FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)1 FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)1 FlashItemDO (com.actionworks.flashsale.persistence.model.FlashItemDO)1 DefaultRedisScript (org.springframework.data.redis.core.script.DefaultRedisScript)1