use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method getFlashActivity.
@Override
public AppSimpleResult<FlashActivityDTO> getFlashActivity(Long userId, Long activityId, Long version) {
if (userId == null || activityId == null) {
throw new BizException(INVALID_PARAMS);
}
FlashActivityCache flashActivityCache = flashActivityCacheService.getCachedActivity(activityId, version);
if (!flashActivityCache.isExist()) {
throw new BizException(ACTIVITY_NOT_FOUND.getErrDesc());
}
if (flashActivityCache.isLater()) {
return AppSimpleResult.tryLater();
}
FlashActivityDTO flashActivityDTO = FlashActivityAppBuilder.toFlashActivityDTO(flashActivityCache.getFlashActivity());
flashActivityDTO.setVersion(flashActivityCache.getVersion());
return AppSimpleResult.ok(flashActivityDTO);
}
use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.
the class DefaultFlashItemAppService method getFlashItem.
@Override
public AppSimpleResult<FlashItemDTO> getFlashItem(Long itemId) {
FlashItemCache flashItemCache = flashItemCacheService.getCachedItem(itemId, null);
if (!flashItemCache.isExist()) {
throw new BizException(ACTIVITY_NOT_FOUND.getErrDesc());
}
if (flashItemCache.isLater()) {
return AppSimpleResult.tryLater();
}
updateLatestItemStock(null, flashItemCache.getFlashItem());
FlashItemDTO flashItemDTO = FlashItemAppBuilder.toFlashItemDTO(flashItemCache.getFlashItem());
flashItemDTO.setVersion(flashItemCache.getVersion());
return AppSimpleResult.ok(flashItemDTO);
}
use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.
the class DefaultFlashOrderAppService method getPlaceOrderTaskResult.
@Override
public AppSimpleResult<OrderTaskHandleResult> getPlaceOrderTaskResult(Long userId, Long itemId, String placeOrderTaskId) {
if (userId == null || itemId == null || StringUtils.isEmpty(placeOrderTaskId)) {
throw new BizException(INVALID_PARAMS);
}
if (placeOrderService instanceof QueuedPlaceOrderService) {
QueuedPlaceOrderService queuedPlaceOrderService = (QueuedPlaceOrderService) placeOrderService;
OrderTaskHandleResult orderTaskHandleResult = queuedPlaceOrderService.getPlaceOrderResult(userId, itemId, placeOrderTaskId);
if (!orderTaskHandleResult.isSuccess()) {
return AppSimpleResult.failed(orderTaskHandleResult.getCode(), orderTaskHandleResult.getMessage(), orderTaskHandleResult);
}
return AppSimpleResult.ok(orderTaskHandleResult);
} else {
return AppSimpleResult.failed(ORDER_TYPE_NOT_SUPPORT);
}
}
use of com.actionworks.flashsale.app.exception.BizException 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.exception.BizException in project flash-sale by ThoughtsBeta.
the class DefaultBucketsAPPService method arrangeStockBuckets.
@Override
public AppSimpleResult arrangeStockBuckets(Long userId, Long itemId, BucketsArrangementCommand arrangementCommand) {
logger.info("arrangeBuckets|编排库存分桶|{},{},{}", userId, itemId, JSON.toJSON(arrangementCommand));
String arrangementKey = getArrangementKey(userId, itemId);
DistributedLock arrangementLock = lockFactoryService.getDistributedLock(arrangementKey);
try {
boolean isLockSuccess = arrangementLock.tryLock(5, 5, TimeUnit.SECONDS);
if (!isLockSuccess) {
return AppSimpleResult.failed(FREQUENTLY_ERROR.getErrCode(), FREQUENTLY_ERROR.getErrDesc());
}
FlashItem flashItem = flashItemDomainService.getFlashItem(itemId);
if (flashItem == null) {
throw new BizException(ITEM_NOT_FOUND.getErrDesc());
}
bucketsArrangementService.arrangeStockBuckets(itemId, arrangementCommand.getTotalStocksAmount(), arrangementCommand.getBucketsQuantity(), arrangementCommand.getArrangementMode());
logger.info("arrangeBuckets|库存编排完成|{}", itemId);
return AppSimpleResult.ok(true);
} catch (AppException e) {
logger.error("arrangeBuckets|库存编排失败|{}", itemId, e);
return AppSimpleResult.failed(BUSINESS_ERROR.getErrCode(), e.getMessage());
} catch (Exception e) {
logger.error("arrangeBuckets|库存编排错误|{}", itemId, e);
return AppSimpleResult.failed(ARRANGE_STOCK_BUCKETS_FAILED);
} finally {
arrangementLock.unlock();
}
}
Aggregations