Search in sources :

Example 11 with DomainException

use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.

the class BucketsDomainServiceImpl method resumeBuckets.

@Override
public boolean resumeBuckets(Long itemId) {
    logger.info("resumeBuckets|启用库存分桶|{}", itemId);
    if (itemId == null || itemId <= 0) {
        throw new DomainException(PARAMS_INVALID);
    }
    boolean success = bucketsRepository.resumeStockBuckets(itemId);
    if (!success) {
        return false;
    }
    StockBucketEvent stockBucketEvent = new StockBucketEvent();
    stockBucketEvent.setEventType(StockBucketEventType.ENABLED);
    stockBucketEvent.setItemId(itemId);
    domainEventPublisher.publish(stockBucketEvent);
    logger.info("suspendBuckets|库存桶已禁用|{}", itemId);
    return true;
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) StockBucketEvent(com.actionworks.flashsale.domain.event.StockBucketEvent)

Example 12 with DomainException

use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.

the class FlashActivityDomainServiceImpl method onlineActivity.

@Override
public void onlineActivity(Long userId, Long activityId) {
    logger.info("activityOnline|上线秒杀活动|{},{}", userId, activityId);
    if (StringUtils.isEmpty(userId) || activityId == null) {
        throw new DomainException(PARAMS_INVALID);
    }
    Optional<FlashActivity> flashActivityOptional = flashActivityRepository.findById(activityId);
    if (!flashActivityOptional.isPresent()) {
        throw new DomainException(FLASH_ACTIVITY_DOES_NOT_EXIST);
    }
    FlashActivity flashActivity = flashActivityOptional.get();
    if (FlashActivityStatus.isOnline(flashActivity.getStatus())) {
        return;
    }
    flashActivity.setStatus(FlashActivityStatus.ONLINE.getCode());
    flashActivityRepository.save(flashActivity);
    logger.info("activityOnline|活动已上线|{},{}", userId, flashActivity.getId());
    FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
    flashActivityEvent.setEventType(FlashActivityEventType.ONLINE);
    flashActivityEvent.setFlashActivity(flashActivity);
    domainEventPublisher.publish(flashActivityEvent);
    logger.info("activityOnline|活动上线事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
Also used : FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashActivityEvent(com.actionworks.flashsale.domain.event.FlashActivityEvent)

Example 13 with DomainException

use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.

the class FlashActivityDomainServiceImpl method modifyActivity.

@Override
public void modifyActivity(Long userId, FlashActivity flashActivity) {
    logger.info("activityModification|秒杀活动修改|{},{}", userId, JSON.toJSONString(flashActivity));
    if (flashActivity == null || !flashActivity.validateParamsForCreateOrUpdate()) {
        throw new DomainException(ONLINE_FLASH_ACTIVITY_PARAMS_INVALID);
    }
    flashActivityRepository.save(flashActivity);
    logger.info("activityModification|活动已修改|{},{}", userId, flashActivity.getId());
    FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
    flashActivityEvent.setEventType(FlashActivityEventType.MODIFIED);
    flashActivityEvent.setFlashActivity(flashActivity);
    domainEventPublisher.publish(flashActivityEvent);
    logger.info("activityModification|活动修改事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
Also used : DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashActivityEvent(com.actionworks.flashsale.domain.event.FlashActivityEvent)

Aggregations

DomainException (com.actionworks.flashsale.domain.exception.DomainException)13 FlashActivityEvent (com.actionworks.flashsale.domain.event.FlashActivityEvent)4 FlashItemEvent (com.actionworks.flashsale.domain.event.FlashItemEvent)3 StockBucketEvent (com.actionworks.flashsale.domain.event.StockBucketEvent)3 FlashOrderEvent (com.actionworks.flashsale.domain.event.FlashOrderEvent)2 FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)2 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)2 BizException (com.actionworks.flashsale.app.exception.BizException)1 Bucket (com.actionworks.flashsale.domain.model.Bucket)1 FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)1 FlowException (com.alibaba.csp.sentinel.slots.block.flow.FlowException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)1