use of com.actionworks.flashsale.domain.model.Bucket in project flash-sale by ThoughtsBeta.
the class DefaultBucketsArrangementService method queryStockBucketsSummary.
@Override
public StockBucketSummaryDTO queryStockBucketsSummary(Long itemId) {
if (itemId == null) {
throw new StockBucketException("参数错误");
}
List<Bucket> buckets = bucketsDomainService.getBucketsByItem(itemId);
int remainAvailableStocks = buckets.stream().mapToInt(Bucket::getAvailableStocksAmount).sum();
Optional<Bucket> primaryBucketOptional = buckets.stream().filter(Bucket::isPrimaryBucket).findFirst();
if (!primaryBucketOptional.isPresent()) {
return new StockBucketSummaryDTO();
}
List<StockBucketDTO> subBuckets = buckets.stream().map(StockBucketBuilder::toStockBucketDTO).collect(toList());
return new StockBucketSummaryDTO().setTotalStocksAmount(primaryBucketOptional.get().getTotalStocksAmount()).setAvailableStocksAmount(remainAvailableStocks).setBuckets(subBuckets);
}
use of com.actionworks.flashsale.domain.model.Bucket in project flash-sale by ThoughtsBeta.
the class DefaultBucketsArrangementService method initStockBuckets.
private void initStockBuckets(Long itemId, Integer totalStockAmount, Integer bucketsQuantity) {
Bucket primaryBucket = new Bucket().initPrimary().setTotalStocksAmount(totalStockAmount).setItemId(itemId);
List<Bucket> presentBuckets = buildBuckets(itemId, totalStockAmount, bucketsQuantity, primaryBucket);
submitBucketsToArrange(itemId, presentBuckets);
}
use of com.actionworks.flashsale.domain.model.Bucket in project flash-sale by ThoughtsBeta.
the class DefaultBucketsArrangementService method arrangeStockBucketsBasedTotalMode.
/**
* 根据总量库存重新分桶
*/
private void arrangeStockBucketsBasedTotalMode(Long itemId, Integer totalStockAmount, Integer bucketsAmount, List<Bucket> existingBuckets) {
// 重新分桶
int remainAvailableStocks = existingBuckets.stream().filter(Bucket::isSubBucket).mapToInt(Bucket::getAvailableStocksAmount).sum();
Optional<Bucket> primaryBucketOptional = existingBuckets.stream().filter(Bucket::isPrimaryBucket).findFirst();
if (!primaryBucketOptional.isPresent()) {
return;
}
// 回收分桶库存到主桶
Bucket primaryBucket = primaryBucketOptional.get();
primaryBucket.addAvailableStocks(remainAvailableStocks);
int soldStocksAmount = primaryBucket.getTotalStocksAmount() - primaryBucket.getAvailableStocksAmount();
if (soldStocksAmount > totalStockAmount) {
throw new StockBucketException("已售库存大于当期所设库存总量!");
}
primaryBucket.setTotalStocksAmount(totalStockAmount);
List<Bucket> presentBuckets = buildBuckets(itemId, totalStockAmount, bucketsAmount, primaryBucket);
submitBucketsToArrange(itemId, presentBuckets);
}
use of com.actionworks.flashsale.domain.model.Bucket in project flash-sale by ThoughtsBeta.
the class BucketBuilder method toDomainObject.
public static Bucket toDomainObject(BucketDO bucketDO) {
Bucket bucket = new Bucket();
BeanUtils.copyProperties(bucketDO, bucket);
return bucket;
}
Aggregations