| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | @RequiredArgsConstructor |
| | |
| | | private final ProcurementRecordOutMapper procurementRecordOutMapper; |
| | | private final ProcurementRecordMapper procurementRecordMapper; |
| | | |
| | | // 获取商品剩余库存 |
| | | public BigDecimal getStockQuantity(Long productModelId) { |
| | | // 获取商品入库数量,出库数量,剩余库存 |
| | | public Map<String, BigDecimal> getStockQuantity(Long productModelId) { |
| | | // 入库数量 |
| | | BigDecimal sumQuantity = procurementRecordMapper.getSumQuantity(productModelId); |
| | | // 出库数量 |
| | | BigDecimal outQuantity = procurementRecordOutMapper.getSumQuantity(productModelId); |
| | | return outQuantity.compareTo(sumQuantity) > 0 ? BigDecimal.ZERO : sumQuantity.subtract(outQuantity); |
| | | // 剩余库存 |
| | | BigDecimal stockQuantity = outQuantity.compareTo(sumQuantity) > 0 ? BigDecimal.ZERO : sumQuantity.subtract(outQuantity); |
| | | Map<String, BigDecimal> stockMap = new HashMap<>(); |
| | | stockMap.put("inboundNum", sumQuantity); |
| | | stockMap.put("outboundNum", outQuantity); |
| | | stockMap.put("stockQuantity", stockQuantity); |
| | | return stockMap; |
| | | } |
| | | } |