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;
}
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);
}
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;
}
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);
}
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();
}
Aggregations