use of com.actionworks.flashsale.app.model.dto.StockBucketSummaryDTO 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);
}
Aggregations