Search in sources :

Example 11 with BizException

use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.

the class DefaultActivityAppService method publishFlashActivity.

@Override
public AppResult publishFlashActivity(Long userId, FlashActivityPublishCommand flashActivityPublishCommand) {
    logger.info("activityPublish|发布秒杀活动|{},{}", userId, JSON.toJSONString(flashActivityPublishCommand));
    if (userId == null || flashActivityPublishCommand == null || !flashActivityPublishCommand.validate()) {
        throw new BizException(INVALID_PARAMS);
    }
    AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_CREATE);
    if (!authResult.isSuccess()) {
        throw new AuthException(UNAUTHORIZED_ACCESS);
    }
    DistributedLock activityCreateLock = lockFactoryService.getDistributedLock(getActivityCreateLockKey(userId));
    try {
        boolean isLockSuccess = activityCreateLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
        if (!isLockSuccess) {
            throw new BizException(FREQUENTLY_ERROR);
        }
        flashActivityDomainService.publishActivity(userId, toDomain(flashActivityPublishCommand));
        logger.info("activityPublish|活动已发布");
        return AppResult.buildSuccess();
    } catch (Exception e) {
        logger.error("activityPublish|活动发布失败|{}", userId, e);
        throw new BizException("活动发布失败");
    } finally {
        activityCreateLock.unlock();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) BizException(com.actionworks.flashsale.app.exception.BizException) AuthException(com.actionworks.flashsale.controller.exception.AuthException) AuthResult(com.actionworks.flashsale.app.auth.model.AuthResult) AuthException(com.actionworks.flashsale.controller.exception.AuthException) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 12 with BizException

use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.

the class DefaultActivityAppService method modifyFlashActivity.

@Override
public AppResult modifyFlashActivity(Long userId, Long activityId, FlashActivityPublishCommand flashActivityPublishCommand) {
    logger.info("activityModification|秒杀活动修改|{},{},{}", userId, activityId, JSON.toJSONString(flashActivityPublishCommand));
    if (userId == null || flashActivityPublishCommand == null || !flashActivityPublishCommand.validate()) {
        throw new BizException(INVALID_PARAMS);
    }
    AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_MODIFICATION);
    if (!authResult.isSuccess()) {
        throw new AuthException(UNAUTHORIZED_ACCESS);
    }
    DistributedLock activityModificationLock = lockFactoryService.getDistributedLock(getActivityModificationLockKey(activityId));
    try {
        boolean isLockSuccess = activityModificationLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
        if (!isLockSuccess) {
            throw new BizException(FREQUENTLY_ERROR);
        }
        FlashActivity flashActivity = toDomain(flashActivityPublishCommand);
        flashActivity.setId(activityId);
        flashActivityDomainService.modifyActivity(userId, flashActivity);
        logger.info("activityModification|活动已修改");
        return AppResult.buildSuccess();
    } catch (Exception e) {
        logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
        throw new BizException("活动修改失败");
    } finally {
        activityModificationLock.unlock();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) BizException(com.actionworks.flashsale.app.exception.BizException) AuthException(com.actionworks.flashsale.controller.exception.AuthException) AuthResult(com.actionworks.flashsale.app.auth.model.AuthResult) AuthException(com.actionworks.flashsale.controller.exception.AuthException) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 13 with BizException

use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.

the class DefaultActivityAppService method offlineFlashActivity.

@Override
public AppResult offlineFlashActivity(Long userId, Long activityId) {
    logger.info("activityOffline|下线活动|{},{}", userId, activityId);
    if (userId == null || activityId == null) {
        throw new BizException(INVALID_PARAMS);
    }
    AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_MODIFICATION);
    if (!authResult.isSuccess()) {
        throw new AuthException(UNAUTHORIZED_ACCESS);
    }
    DistributedLock activityModificationLock = lockFactoryService.getDistributedLock(getActivityModificationLockKey(activityId));
    try {
        boolean isLockSuccess = activityModificationLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
        if (!isLockSuccess) {
            throw new BizException(FREQUENTLY_ERROR);
        }
        flashActivityDomainService.offlineActivity(userId, activityId);
        logger.info("activityOffline|活动已下线");
        return AppResult.buildSuccess();
    } catch (Exception e) {
        logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
        throw new BizException("活动修改失败");
    } finally {
        activityModificationLock.unlock();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) BizException(com.actionworks.flashsale.app.exception.BizException) AuthException(com.actionworks.flashsale.controller.exception.AuthException) AuthResult(com.actionworks.flashsale.app.auth.model.AuthResult) AuthException(com.actionworks.flashsale.controller.exception.AuthException) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 14 with BizException

use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.

the class DefaultActivityAppService method onlineFlashActivity.

@Override
public AppResult onlineFlashActivity(Long userId, Long activityId) {
    logger.info("activityOnline|上线活动|{},{}", userId, activityId);
    if (userId == null || activityId == null) {
        throw new BizException(INVALID_PARAMS);
    }
    AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_CREATE);
    if (!authResult.isSuccess()) {
        throw new AuthException(UNAUTHORIZED_ACCESS);
    }
    DistributedLock activityModificationLock = lockFactoryService.getDistributedLock(getActivityModificationLockKey(activityId));
    try {
        boolean isLockSuccess = activityModificationLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
        if (!isLockSuccess) {
            throw new BizException(FREQUENTLY_ERROR);
        }
        flashActivityDomainService.onlineActivity(userId, activityId);
        logger.info("activityOnline|活动已上线");
        return AppResult.buildSuccess();
    } catch (Exception e) {
        logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
        throw new BizException("活动修改失败");
    } finally {
        activityModificationLock.unlock();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) BizException(com.actionworks.flashsale.app.exception.BizException) AuthException(com.actionworks.flashsale.controller.exception.AuthException) AuthResult(com.actionworks.flashsale.app.auth.model.AuthResult) AuthException(com.actionworks.flashsale.controller.exception.AuthException) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 15 with BizException

use of com.actionworks.flashsale.app.exception.BizException in project flash-sale by ThoughtsBeta.

the class DefaultFlashItemAppService method publishFlashItem.

@Override
public AppResult publishFlashItem(Long userId, Long activityId, FlashItemPublishCommand itemPublishCommand) {
    logger.info("itemPublish|发布秒杀品|{},{},{}", userId, activityId, JSON.toJSON(itemPublishCommand));
    if (userId == null || activityId == null || itemPublishCommand == null || !itemPublishCommand.validate()) {
        throw new BizException(INVALID_PARAMS);
    }
    AuthResult authResult = authorizationService.auth(userId, FLASH_ITEM_CREATE);
    if (!authResult.isSuccess()) {
        throw new AuthException(UNAUTHORIZED_ACCESS);
    }
    DistributedLock itemCreateLock = lockFactoryService.getDistributedLock(getItemCreateLockKey(userId));
    try {
        boolean isLockSuccess = itemCreateLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
        if (!isLockSuccess) {
            throw new BizException(FREQUENTLY_ERROR);
        }
        FlashActivity flashActivity = flashActivityDomainService.getFlashActivity(activityId);
        if (flashActivity == null) {
            throw new BizException(ACTIVITY_NOT_FOUND);
        }
        FlashItem flashItem = toDomain(itemPublishCommand);
        flashItem.setActivityId(activityId);
        flashItem.setStockWarmUp(0);
        flashItemDomainService.publishFlashItem(flashItem);
        logger.info("itemPublish|秒杀品已发布");
        return AppResult.buildSuccess();
    } catch (Exception e) {
        logger.error("itemPublish|秒杀品发布失败|{}", userId, e);
        throw new BizException("秒杀品发布失败");
    } finally {
        itemCreateLock.unlock();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) BizException(com.actionworks.flashsale.app.exception.BizException) FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) AuthException(com.actionworks.flashsale.controller.exception.AuthException) AuthResult(com.actionworks.flashsale.app.auth.model.AuthResult) AuthException(com.actionworks.flashsale.controller.exception.AuthException) BizException(com.actionworks.flashsale.app.exception.BizException)

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