package com.fjhx.wms.service;

import com.fjhx.item.ItemService;
import com.fjhx.wms.entity.stock.po.Stock;
import com.fjhx.wms.service.stock.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private StockService stockService;

    @Override
    public BigDecimal getStockQuantity(Long productId) {
        List<Stock> list = stockService.list(q -> q.eq(Stock::getProductId, productId));
        BigDecimal quantity = list.stream().map(Stock::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);

        return quantity;
    }
}
