use of com.actionworks.flashsale.app.model.dto.StockBucketDTO 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.app.model.dto.StockBucketDTO in project flash-sale by ThoughtsBeta.
the class StockBucketBuilder method toStockBucketDTO.
public static StockBucketDTO toStockBucketDTO(Bucket bucket) {
if (bucket == null) {
return null;
}
StockBucketDTO stockBucketDTO = new StockBucketDTO();
BeanUtils.copyProperties(bucket, stockBucketDTO);
return stockBucketDTO;
}
Aggregations