Search in sources :

Example 1 with FlashOrder

use of com.actionworks.flashsale.domain.model.entity.FlashOrder in project flash-sale by ThoughtsBeta.

the class FlashOrderAppBuilder method toDomain.

public static FlashOrder toDomain(PlaceOrderTask PlaceOrderTask) {
    if (PlaceOrderTask == null) {
        return null;
    }
    FlashOrder flashOrder = new FlashOrder();
    BeanUtils.copyProperties(PlaceOrderTask, flashOrder);
    return flashOrder;
}
Also used : FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder)

Example 2 with FlashOrder

use of com.actionworks.flashsale.domain.model.entity.FlashOrder in project flash-sale by ThoughtsBeta.

the class FlashOrderDomainServiceImpl method getOrdersByUser.

@Override
public PageResult<FlashOrder> getOrdersByUser(Long userId, PagesQueryCondition pagesQueryCondition) {
    if (pagesQueryCondition == null) {
        pagesQueryCondition = new PagesQueryCondition();
    }
    List<FlashOrder> flashOrders = flashOrderRepository.findFlashOrdersByCondition(pagesQueryCondition.buildParams());
    int total = flashOrderRepository.countFlashOrdersByCondition(pagesQueryCondition.buildParams());
    logger.info("Get flash orders:{},{}", userId, flashOrders.size());
    return PageResult.with(flashOrders, total);
}
Also used : FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Example 3 with FlashOrder

use of com.actionworks.flashsale.domain.model.entity.FlashOrder in project flash-sale by ThoughtsBeta.

the class FlashOrderBuilder method toDomainObject.

public static FlashOrder toDomainObject(FlashOrderDO flashOrderDO) {
    FlashOrder flashOrder = new FlashOrder();
    BeanUtils.copyProperties(flashOrderDO, flashOrder);
    return flashOrder;
}
Also used : FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder)

Example 4 with FlashOrder

use of com.actionworks.flashsale.domain.model.entity.FlashOrder in project flash-sale by ThoughtsBeta.

the class FlashOrderRepositoryImpl method findById.

@Override
public Optional<FlashOrder> findById(Long orderId) {
    FlashOrderDO flashOrderDO = flashOrderMapper.getById(orderId);
    if (flashOrderDO == null) {
        return Optional.empty();
    }
    FlashOrder flashOrder = FlashOrderBuilder.toDomainObject(flashOrderDO);
    return Optional.of(flashOrder);
}
Also used : FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder) FlashOrderDO(com.actionworks.flashsale.persistence.model.FlashOrderDO)

Example 5 with FlashOrder

use of com.actionworks.flashsale.domain.model.entity.FlashOrder in project flash-sale by ThoughtsBeta.

the class DefaultFlashOrderAppService method cancelOrder.

@Override
@Transactional
public AppResult cancelOrder(Long userId, Long orderId) {
    logger.info("cancelOrder|取消订单|{},{}", userId, orderId);
    if (userId == null || orderId == null) {
        throw new BizException(INVALID_PARAMS);
    }
    FlashOrder flashOrder = flashOrderDomainService.getOrder(userId, orderId);
    if (flashOrder == null) {
        throw new BizException(ORDER_NOT_FOUND);
    }
    boolean cancelSuccess = flashOrderDomainService.cancelOrder(userId, orderId);
    if (!cancelSuccess) {
        logger.info("cancelOrder|订单取消失败|{}", orderId);
        return AppResult.buildFailure(ORDER_CANCEL_FAILED);
    }
    StockDeduction stockDeduction = new StockDeduction().setItemId(flashOrder.getItemId()).setQuantity(flashOrder.getQuantity());
    boolean stockRecoverSuccess = stockDeductionDomainService.increaseItemStock(stockDeduction);
    if (!stockRecoverSuccess) {
        logger.info("cancelOrder|库存恢复失败|{}", orderId);
        throw new BizException(ORDER_CANCEL_FAILED);
    }
    boolean stockInRedisRecoverSuccess = itemStockCacheService.increaseItemStock(stockDeduction);
    if (!stockInRedisRecoverSuccess) {
        logger.info("cancelOrder|Redis库存恢复失败|{}", orderId);
        throw new BizException(ORDER_CANCEL_FAILED);
    }
    logger.info("cancelOrder|订单取消成功|{}", orderId);
    return AppResult.buildSuccess();
}
Also used : FlashOrder(com.actionworks.flashsale.domain.model.entity.FlashOrder) BizException(com.actionworks.flashsale.app.exception.BizException) StockDeduction(com.actionworks.flashsale.domain.model.StockDeduction) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)10 BizException (com.actionworks.flashsale.app.exception.BizException)3 StockDeduction (com.actionworks.flashsale.domain.model.StockDeduction)3 OrderNoGenerateContext (com.actionworks.flashsale.app.util.OrderNoGenerateContext)2 PagesQueryCondition (com.actionworks.flashsale.domain.model.PagesQueryCondition)2 Transactional (org.springframework.transaction.annotation.Transactional)2 FlashItemDTO (com.actionworks.flashsale.app.model.dto.FlashItemDTO)1 FlashOrderEvent (com.actionworks.flashsale.domain.event.FlashOrderEvent)1 DomainException (com.actionworks.flashsale.domain.exception.DomainException)1 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)1 FlashOrderDO (com.actionworks.flashsale.persistence.model.FlashOrderDO)1