Search in sources :

Example 1 with FlashOrderEvent

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

the class FlashOrderDomainServiceImpl method placeOrder.

@Override
public boolean placeOrder(Long userId, FlashOrder flashOrder) {
    logger.info("placeOrder|下单|{},{}", userId, JSON.toJSONString(flashOrder));
    if (flashOrder == null || !flashOrder.validateParamsForCreate()) {
        throw new DomainException(PARAMS_INVALID);
    }
    flashOrder.setStatus(FlashOrderStatus.CREATED.getCode());
    boolean saveSuccess = flashOrderRepository.save(flashOrder);
    if (saveSuccess) {
        FlashOrderEvent flashOrderEvent = new FlashOrderEvent();
        flashOrderEvent.setEventType(FlashOrderEventType.CREATED);
        domainEventPublisher.publish(flashOrderEvent);
    }
    logger.info("placeOrder|订单已创建成功|{},{}", userId, JSON.toJSONString(flashOrder));
    return saveSuccess;
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashOrderEvent(com.actionworks.flashsale.domain.event.FlashOrderEvent)

Example 2 with FlashOrderEvent

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

the class FlashOrderDomainServiceImpl method cancelOrder.

@Override
public boolean cancelOrder(Long userId, Long orderId) {
    logger.info("placeOrder|取消订单|{},{}", userId, orderId);
    if (StringUtils.isEmpty(userId) || orderId == null) {
        throw new DomainException(PARAMS_INVALID);
    }
    Optional<FlashOrder> flashOrderOptional = flashOrderRepository.findById(orderId);
    if (!flashOrderOptional.isPresent()) {
        throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
    }
    FlashOrder flashOrder = flashOrderOptional.get();
    if (!flashOrder.getUserId().equals(userId)) {
        throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
    }
    if (FlashOrderStatus.isCancled(flashOrder.getStatus())) {
        return false;
    }
    flashOrder.setStatus(FlashOrderStatus.CANCELED.getCode());
    boolean saveSuccess = flashOrderRepository.updateStatus(flashOrder);
    if (saveSuccess) {
        FlashOrderEvent flashOrderEvent = new FlashOrderEvent();
        flashOrderEvent.setEventType(FlashOrderEventType.CANCEL);
        domainEventPublisher.publish(flashOrderEvent);
    }
    logger.info("placeOrder|订单已取消|{},{}", userId, orderId);
    return saveSuccess;
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder) FlashOrderEvent(com.actionworks.flashsale.domain.event.FlashOrderEvent)

Aggregations

FlashOrderEvent (com.actionworks.flashsale.domain.event.FlashOrderEvent)2 DomainException (com.actionworks.flashsale.domain.exception.DomainException)2 FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)1