Search in sources :

Example 1 with AppException

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();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) AppException(com.actionworks.flashsale.app.exception.AppException) BizException(com.actionworks.flashsale.app.exception.BizException) FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) BizException(com.actionworks.flashsale.app.exception.BizException) AppException(com.actionworks.flashsale.app.exception.AppException)

Aggregations

AppException (com.actionworks.flashsale.app.exception.AppException)1 BizException (com.actionworks.flashsale.app.exception.BizException)1 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)1 DistributedLock (com.actionworks.flashsale.lock.DistributedLock)1