| | |
| | | if (!updateList.isEmpty()) { |
| | | for (SalesLedgerProduct product : updateList) { |
| | | product.setType(type.getCode()); |
| | | SalesLedgerProduct db = salesLedgerProductMapper.selectById(product.getId()); |
| | | if (db != null) { |
| | | BigDecimal stockedQty = product.getStockedQuantity() != null ? product.getStockedQuantity() : db.getStockedQuantity(); |
| | | BigDecimal orderQty = product.getQuantity() != null ? product.getQuantity() : db.getQuantity(); |
| | | product.setStockedQuantity(stockedQty); |
| | | product.setProductStockStatus(calculateProductStockStatus(stockedQty, orderQty)); |
| | | } else { |
| | | product.setProductStockStatus(0); |
| | | } |
| | | product.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(product); |
| | | // 清空销售产品绑定的加工 |
| | |
| | | salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity()); |
| | | salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProduct.setProductStockStatus(0); |
| | | BigDecimal stockedQty = salesLedgerProduct.getStockedQuantity(); |
| | | BigDecimal orderQty = salesLedgerProduct.getQuantity(); |
| | | salesLedgerProduct.setProductStockStatus(calculateProductStockStatus(stockedQty, orderQty)); |
| | | salesLedgerProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | // 绑定产品额外加工 |
| | |
| | | // salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct); |
| | | } |
| | | } |
| | | refreshSalesLedgerStockStatus(salesLedgerId); |
| | | } |
| | | |
| | | private int calculateProductStockStatus(BigDecimal stockedQty, BigDecimal orderQty) { |
| | | BigDecimal stocked = stockedQty == null ? BigDecimal.ZERO : stockedQty; |
| | | BigDecimal order = orderQty == null ? BigDecimal.ZERO : orderQty; |
| | | if (stocked.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return 0; |
| | | } |
| | | if (order.compareTo(BigDecimal.ZERO) > 0 && stocked.compareTo(order) < 0) { |
| | | return 1; |
| | | } |
| | | return 2; |
| | | } |
| | | |
| | | private void refreshSalesLedgerStockStatus(Long salesLedgerId) { |
| | | if (salesLedgerId == null) return; |
| | | SalesLedger ledger = baseMapper.selectById(salesLedgerId); |
| | | if (ledger == null) return; |
| | | List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList( |
| | | Wrappers.<SalesLedgerProduct>lambdaQuery() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId) |
| | | .eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode())); |
| | | if (CollectionUtils.isEmpty(allProducts)) { |
| | | ledger.setStockStatus(0); |
| | | baseMapper.updateById(ledger); |
| | | return; |
| | | } |
| | | boolean anyInbound = allProducts.stream().anyMatch(p -> { |
| | | BigDecimal sq = p.getStockedQuantity(); |
| | | return sq != null && sq.compareTo(BigDecimal.ZERO) > 0; |
| | | }); |
| | | boolean allFull = allProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2)); |
| | | ledger.setStockStatus(allFull ? 2 : (anyInbound ? 1 : 0)); |
| | | baseMapper.updateById(ledger); |
| | | } |
| | | |
| | | private SalesLedger convertToEntity(SalesLedgerDto dto) { |