Search in sources :

Example 1 with FlashItemEvent

use of com.actionworks.flashsale.domain.event.FlashItemEvent in project flash-sale by ThoughtsBeta.

the class FlashItemDomainServiceImpl method publishFlashItem.

@Override
public void publishFlashItem(FlashItem flashItem) {
    logger.info("itemPublish|发布秒杀品|{}", JSON.toJSON(flashItem));
    if (flashItem == null || !flashItem.validateParamsForCreate()) {
        throw new DomainException(ONLINE_FLASH_ITEM_PARAMS_INVALID);
    }
    flashItem.setStatus(FlashItemStatus.PUBLISHED.getCode());
    flashItemRepository.save(flashItem);
    logger.info("itemPublish|秒杀品已发布|{}", flashItem.getId());
    FlashItemEvent flashItemEvent = new FlashItemEvent();
    flashItemEvent.setEventType(FlashItemEventType.PUBLISHED);
    flashItemEvent.setFlashItem(flashItem);
    domainEventPublisher.publish(flashItemEvent);
    logger.info("itemPublish|秒杀品发布事件已发布|{}", flashItem.getId());
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashItemEvent(com.actionworks.flashsale.domain.event.FlashItemEvent)

Example 2 with FlashItemEvent

use of com.actionworks.flashsale.domain.event.FlashItemEvent 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 3 with FlashItemEvent

use of com.actionworks.flashsale.domain.event.FlashItemEvent 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

FlashItemEvent (com.actionworks.flashsale.domain.event.FlashItemEvent)3 DomainException (com.actionworks.flashsale.domain.exception.DomainException)3 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)2