Search in sources :

Example 1 with StockBucketSummaryDTO

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);
}
Also used : Bucket(com.actionworks.flashsale.domain.model.Bucket) StockBucketSummaryDTO(com.actionworks.flashsale.app.model.dto.StockBucketSummaryDTO) StockBucketException(com.actionworks.flashsale.app.exception.StockBucketException) StockBucketDTO(com.actionworks.flashsale.app.model.dto.StockBucketDTO)

Aggregations

StockBucketException (com.actionworks.flashsale.app.exception.StockBucketException)1 StockBucketDTO (com.actionworks.flashsale.app.model.dto.StockBucketDTO)1 StockBucketSummaryDTO (com.actionworks.flashsale.app.model.dto.StockBucketSummaryDTO)1 Bucket (com.actionworks.flashsale.domain.model.Bucket)1