| | |
| | | throw new BaseException("理论入库数量必须大于0"); |
| | | } |
| | | |
| | | BigDecimal approvedStockInNum = getApprovedPurchaseStockInNum( |
| | | BigDecimal occupiedStockInNum = getOccupiedPurchaseStockInNum( |
| | | purchaseLedger.getId(), |
| | | purchaseLedger.getPurchaseContractNumber(), |
| | | salesLedgerProduct.getId(), |
| | | salesLedgerProduct.getProductModelId() |
| | | ); |
| | | BigDecimal remainingStockInNum = salesLedgerProduct.getQuantity().subtract(approvedStockInNum); |
| | | BigDecimal remainingStockInNum = salesLedgerProduct.getQuantity().subtract(occupiedStockInNum); |
| | | if (remainingStockInNum.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new BaseException("产品【" + productModel.getModel() + "】已完成入库"); |
| | | } |
| | |
| | | return count; |
| | | } |
| | | |
| | | private BigDecimal getApprovedPurchaseStockInNum(Long purchaseLedgerId, String purchaseContractNumber, Long productId, Long productModelId) { |
| | | private BigDecimal getOccupiedPurchaseStockInNum(Long purchaseLedgerId, String purchaseContractNumber, Long productId, Long productModelId) { |
| | | if (purchaseLedgerId == null || productId == null || productModelId == null || !StringUtils.hasText(purchaseContractNumber)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | List<StockInRecord> stockRecords = findDirectStockRecords(purchaseLedgerId, purchaseContractNumber, productModelId, productId); |
| | | return stockRecords.stream() |
| | | .filter(Objects::nonNull) |
| | | .filter(item -> ReviewStatusEnum.APPROVED.getCode().equals(item.getApprovalStatus())) |
| | | .map(StockInRecord::getStockInNum) |
| | | .filter(item -> item.getApprovalStatus() == null |
| | | || ReviewStatusEnum.PENDING_REVIEW.getCode().equals(item.getApprovalStatus()) |
| | | || ReviewStatusEnum.APPROVED.getCode().equals(item.getApprovalStatus())) |
| | | .map(item -> item.getTheoryStockInNum() != null ? item.getTheoryStockInNum() : item.getStockInNum()) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |