use of com.actionworks.flashsale.app.exception.AppException 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