Search in sources :

Example 1 with PlaceOrderTask

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

the class RocketMQOrderTaskConsumerService method onMessage.

@Override
public void onMessage(String message) {
    logger.info("handleOrderTask|接收下单任务消息|{}", message);
    if (StringUtils.isEmpty(message)) {
        logger.info("handleOrderTask|接收下单任务消息为空|{}", message);
        return;
    }
    try {
        PlaceOrderTask placeOrderTask = JSON.parseObject(message, PlaceOrderTask.class);
        queuedPlaceOrderService.handlePlaceOrderTask(placeOrderTask);
        logger.info("handleOrderTask|下单任务消息处理完成|{}", placeOrderTask.getPlaceOrderTaskId());
    } catch (Exception e) {
        logger.error("handleOrderTask|下单任务消息处理失败|{}", message);
    }
}
Also used : PlaceOrderTask(com.actionworks.flashsale.app.model.PlaceOrderTask)

Example 2 with PlaceOrderTask

use of com.actionworks.flashsale.app.model.PlaceOrderTask 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)

Example 3 with PlaceOrderTask

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

the class PlaceOrderTaskBuilder method with.

public static PlaceOrderTask with(Long userId, FlashPlaceOrderCommand flashPlaceOrderCommand) {
    if (flashPlaceOrderCommand == null) {
        return null;
    }
    PlaceOrderTask placeOrderTask = new PlaceOrderTask();
    BeanUtils.copyProperties(flashPlaceOrderCommand, placeOrderTask);
    placeOrderTask.setUserId(userId);
    return placeOrderTask;
}
Also used : PlaceOrderTask(com.actionworks.flashsale.app.model.PlaceOrderTask)

Aggregations

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