Search in sources :

Example 1 with BizException

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);
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) FlashActivityCache(com.actionworks.flashsale.app.service.activity.cache.model.FlashActivityCache) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 2 with BizException

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);
}
Also used : FlashItemCache(com.actionworks.flashsale.app.service.item.cache.model.FlashItemCache) BizException(com.actionworks.flashsale.app.exception.BizException) FlashItemDTO(com.actionworks.flashsale.app.model.dto.FlashItemDTO)

Example 3 with BizException

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);
    }
}
Also used : QueuedPlaceOrderService(com.actionworks.flashsale.app.service.placeorder.queued.QueuedPlaceOrderService) OrderTaskHandleResult(com.actionworks.flashsale.app.model.result.OrderTaskHandleResult) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 4 with BizException

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();
    }
}
Also used : PlaceOrderResult(com.actionworks.flashsale.app.model.result.PlaceOrderResult) DistributedLock(com.actionworks.flashsale.lock.DistributedLock) BizException(com.actionworks.flashsale.app.exception.BizException) BizException(com.actionworks.flashsale.app.exception.BizException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with BizException

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();
    }
}
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

BizException (com.actionworks.flashsale.app.exception.BizException)16 DistributedLock (com.actionworks.flashsale.lock.DistributedLock)9 AuthResult (com.actionworks.flashsale.app.auth.model.AuthResult)7 AuthException (com.actionworks.flashsale.controller.exception.AuthException)7 StockDeduction (com.actionworks.flashsale.domain.model.StockDeduction)3 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)3 FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)3 Transactional (org.springframework.transaction.annotation.Transactional)3 FlashItemDTO (com.actionworks.flashsale.app.model.dto.FlashItemDTO)2 OrderNoGenerateContext (com.actionworks.flashsale.app.util.OrderNoGenerateContext)2 FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)2 AppException (com.actionworks.flashsale.app.exception.AppException)1 FlashActivityDTO (com.actionworks.flashsale.app.model.dto.FlashActivityDTO)1 OrderTaskHandleResult (com.actionworks.flashsale.app.model.result.OrderTaskHandleResult)1 PlaceOrderResult (com.actionworks.flashsale.app.model.result.PlaceOrderResult)1 FlashActivityCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivityCache)1 FlashItemCache (com.actionworks.flashsale.app.service.item.cache.model.FlashItemCache)1 QueuedPlaceOrderService (com.actionworks.flashsale.app.service.placeorder.queued.QueuedPlaceOrderService)1 DomainException (com.actionworks.flashsale.domain.exception.DomainException)1 FlowException (com.alibaba.csp.sentinel.slots.block.flow.FlowException)1