Search in sources :

Example 1 with OrderTaskSubmitResult

use of com.actionworks.flashsale.app.model.result.OrderTaskSubmitResult in project flash-sale by ThoughtsBeta.

the class QueuedPlaceOrderService method doPlaceOrder.

@Override
public PlaceOrderResult doPlaceOrder(Long userId, FlashPlaceOrderCommand placeOrderCommand) {
    logger.info("placeOrder|开始下单|{},{}", userId, JSON.toJSONString(placeOrderCommand));
    if (placeOrderCommand == null || !placeOrderCommand.validateParams()) {
        return PlaceOrderResult.failed(INVALID_PARAMS);
    }
    AppSimpleResult<FlashItemDTO> flashItemResult = flashItemAppService.getFlashItem(placeOrderCommand.getItemId());
    if (!flashItemResult.isSuccess() || flashItemResult.getData() == null) {
        logger.info("placeOrder|获取秒杀品失败|{},{}", userId, placeOrderCommand.getActivityId());
        return PlaceOrderResult.failed(GET_ITEM_FAILED);
    }
    FlashItemDTO flashItemDTO = flashItemResult.getData();
    if (!flashItemDTO.isOnSale()) {
        logger.info("placeOrder|当前非在售时间|{},{}", userId, placeOrderCommand.getActivityId());
        return PlaceOrderResult.failed(ITEM_NOT_ON_SALE);
    }
    String placeOrderTaskId = orderTaskIdGenerateService.generatePlaceOrderTaskId(userId, placeOrderCommand.getItemId());
    PlaceOrderTask placeOrderTask = PlaceOrderTaskBuilder.with(userId, placeOrderCommand);
    placeOrderTask.setPlaceOrderTaskId(placeOrderTaskId);
    OrderTaskSubmitResult submitResult = placeOrderTaskService.submit(placeOrderTask);
    logger.info("placeOrder|任务提交结果|{},{},{}", userId, placeOrderTaskId, JSON.toJSONString(placeOrderTask));
    if (!submitResult.isSuccess()) {
        logger.info("placeOrder|下单任务提交失败|{},{}", userId, placeOrderCommand.getActivityId());
        return PlaceOrderResult.failed(submitResult.getCode(), submitResult.getMessage());
    }
    logger.info("placeOrder|下单任务提交完成|{},{}", userId, placeOrderTaskId);
    return PlaceOrderResult.ok(placeOrderTaskId);
}
Also used : OrderTaskSubmitResult(com.actionworks.flashsale.app.model.result.OrderTaskSubmitResult) PlaceOrderTask(com.actionworks.flashsale.app.model.PlaceOrderTask) FlashItemDTO(com.actionworks.flashsale.app.model.dto.FlashItemDTO)

Aggregations

PlaceOrderTask (com.actionworks.flashsale.app.model.PlaceOrderTask)1 FlashItemDTO (com.actionworks.flashsale.app.model.dto.FlashItemDTO)1 OrderTaskSubmitResult (com.actionworks.flashsale.app.model.result.OrderTaskSubmitResult)1