use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class BucketsDomainServiceImpl method arrangeBuckets.
@Override
public boolean arrangeBuckets(Long itemId, List<Bucket> buckets) {
logger.info("arrangeBuckets|编排库存分桶|{},{}", itemId, JSON.toJSONString(buckets));
if (itemId == null || itemId <= 0 || CollectionUtils.isEmpty(buckets)) {
logger.info("arrangeBuckets|库存分桶参数错误|{}", itemId);
throw new DomainException(PARAMS_INVALID);
}
Optional<Bucket> primaryBucketOptional = buckets.stream().filter(Bucket::isPrimaryBucket).findFirst();
if (!primaryBucketOptional.isPresent()) {
throw new DomainException(PRIMARY_BUCKET_IS_MISSING);
}
if (buckets.stream().filter(Bucket::isPrimaryBucket).count() > 1) {
throw new DomainException(MULTI_PRIMARY_BUCKETS_FOUND_BUT_EXPECT_ONE);
}
buckets.forEach(stockBucket -> {
if (stockBucket.getTotalStocksAmount() == null || stockBucket.getTotalStocksAmount() < 0) {
throw new DomainException(TOTAL_STOCKS_AMOUNT_INVALID);
}
if (stockBucket.getAvailableStocksAmount() == null || stockBucket.getAvailableStocksAmount() <= 0) {
throw new DomainException(AVAILABLE_STOCKS_AMOUNT_INVALID);
}
if (!stockBucket.getAvailableStocksAmount().equals(stockBucket.getTotalStocksAmount()) && stockBucket.isSubBucket()) {
throw new DomainException(AVAILABLE_STOCKS_AMOUNT_NOT_EQUALS_TO_TOTAL_STOCKS_AMOUNT);
}
if (!itemId.equals(stockBucket.getItemId())) {
throw new DomainException(STOCK_BUCKET_ITEM_INVALID);
}
});
boolean success = bucketsRepository.submitBuckets(itemId, buckets);
if (!success) {
return false;
}
StockBucketEvent stockBucketEvent = new StockBucketEvent();
stockBucketEvent.setEventType(StockBucketEventType.ARRANGED);
stockBucketEvent.setItemId(itemId);
domainEventPublisher.publish(stockBucketEvent);
logger.info("arrangeBuckets|编排库存分桶已完成|{}", itemId);
return true;
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class BucketsDomainServiceImpl method suspendBuckets.
@Override
public boolean suspendBuckets(Long itemId) {
logger.info("suspendBuckets|禁用库存分桶|{}", itemId);
if (itemId == null || itemId <= 0) {
throw new DomainException(PARAMS_INVALID);
}
boolean success = bucketsRepository.suspendBuckets(itemId);
if (!success) {
return false;
}
StockBucketEvent stockBucketEvent = new StockBucketEvent();
stockBucketEvent.setEventType(StockBucketEventType.DISABLED);
stockBucketEvent.setItemId(itemId);
domainEventPublisher.publish(stockBucketEvent);
logger.info("suspendBuckets|库存分桶已禁用|{}", itemId);
return true;
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashActivityDomainServiceImpl method offlineActivity.
@Override
public void offlineActivity(Long userId, Long activityId) {
logger.info("activityOffline|下线秒杀活动|{},{}", 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.isOffline(flashActivity.getStatus())) {
return;
}
if (!FlashActivityStatus.isOnline(flashActivity.getStatus())) {
throw new DomainException(FLASH_ACTIVITY_NOT_ONLINE);
}
flashActivity.setStatus(FlashActivityStatus.OFFLINE.getCode());
flashActivityRepository.save(flashActivity);
logger.info("activityOffline|活动已下线|{},{}", userId, flashActivity.getId());
FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
flashActivityEvent.setEventType(FlashActivityEventType.OFFLINE);
flashActivityEvent.setFlashActivity(flashActivity);
domainEventPublisher.publish(flashActivityEvent);
logger.info("activityOffline|活动下线事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashActivityDomainServiceImpl method publishActivity.
@Override
public void publishActivity(Long userId, FlashActivity flashActivity) {
logger.info("activityPublish|发布秒杀活动|{},{}", userId, JSON.toJSONString(flashActivity));
if (flashActivity == null || !flashActivity.validateParamsForCreateOrUpdate()) {
throw new DomainException(ONLINE_FLASH_ACTIVITY_PARAMS_INVALID);
}
flashActivity.setStatus(FlashActivityStatus.PUBLISHED.getCode());
flashActivityRepository.save(flashActivity);
logger.info("activityPublish|活动已发布|{},{}", userId, flashActivity.getId());
FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
flashActivityEvent.setEventType(FlashActivityEventType.PUBLISHED);
flashActivityEvent.setFlashActivity(flashActivity);
domainEventPublisher.publish(flashActivityEvent);
logger.info("activityPublish|活动发布事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method publishFlashItem.
@Override
public void publishFlashItem(FlashItem flashItem) {
logger.info("itemPublish|发布秒杀品|{}", JSON.toJSON(flashItem));
if (flashItem == null || !flashItem.validateParamsForCreate()) {
throw new DomainException(ONLINE_FLASH_ITEM_PARAMS_INVALID);
}
flashItem.setStatus(FlashItemStatus.PUBLISHED.getCode());
flashItemRepository.save(flashItem);
logger.info("itemPublish|秒杀品已发布|{}", flashItem.getId());
FlashItemEvent flashItemEvent = new FlashItemEvent();
flashItemEvent.setEventType(FlashItemEventType.PUBLISHED);
flashItemEvent.setFlashItem(flashItem);
domainEventPublisher.publish(flashItemEvent);
logger.info("itemPublish|秒杀品发布事件已发布|{}", flashItem.getId());
}
Aggregations