use of com.actionworks.flashsale.app.model.result.PlaceOrderResult in project flash-sale by ThoughtsBeta.
the class DefaultFlashOrderAppService method placeOrder.
@Override
@Transactional
public AppSimpleResult<PlaceOrderResult> placeOrder(Long userId, FlashPlaceOrderCommand placeOrderCommand) {
logger.info("placeOrder|下单|{},{}", userId, JSON.toJSONString(placeOrderCommand));
if (userId == null || placeOrderCommand == null || !placeOrderCommand.validateParams()) {
throw new BizException(INVALID_PARAMS);
}
String placeOrderLockKey = getPlaceOrderLockKey(userId);
DistributedLock placeOrderLock = lockFactoryService.getDistributedLock(placeOrderLockKey);
try {
boolean isLockSuccess = placeOrderLock.tryLock(5, 5, TimeUnit.SECONDS);
if (!isLockSuccess) {
return AppSimpleResult.failed(FREQUENTLY_ERROR.getErrCode(), FREQUENTLY_ERROR.getErrDesc());
}
boolean isPassRiskInspect = securityService.inspectRisksByPolicy(userId);
if (!isPassRiskInspect) {
logger.info("placeOrder|综合风控检验未通过|{}", userId);
return AppSimpleResult.failed(PLACE_ORDER_FAILED);
}
PlaceOrderResult placeOrderResult = placeOrderService.doPlaceOrder(userId, placeOrderCommand);
if (!placeOrderResult.isSuccess()) {
return AppSimpleResult.failed(placeOrderResult.getCode(), placeOrderResult.getMessage());
}
logger.info("placeOrder|下单完成|{}", userId);
return AppSimpleResult.ok(placeOrderResult);
} catch (Exception e) {
logger.error("placeOrder|下单失败|{},{}", userId, JSON.toJSONString(placeOrderCommand), e);
return AppSimpleResult.failed(PLACE_ORDER_FAILED);
} finally {
placeOrderLock.unlock();
}
}
use of com.actionworks.flashsale.app.model.result.PlaceOrderResult in project flash-sale by ThoughtsBeta.
the class FlashOrderController method placeOrder.
@PostMapping(value = "/flash-orders")
@SentinelResource("PlaceOrderResource")
public SingleResponse<PlaceOrderResult> placeOrder(@RequestAttribute Long userId, @RequestBody FlashPlaceOrderRequest flashPlaceOrderRequest) {
FlashPlaceOrderCommand placeOrderCommand = FlashOrderBuilder.toCommand(flashPlaceOrderRequest);
AppSimpleResult<PlaceOrderResult> placeOrderResult = flashOrderAppService.placeOrder(userId, placeOrderCommand);
if (!placeOrderResult.isSuccess() || placeOrderResult.getData() == null) {
return ResponseBuilder.withSingle(placeOrderResult);
}
return SingleResponse.of(placeOrderResult.getData());
}
Aggregations