| | |
| | | int result; |
| | | Long salesLedgerId = salesLedgerProduct.getSalesLedgerId(); |
| | | salesLedgerProduct.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity())); |
| | | salesLedgerProduct.setTotalQuantity(normalizeTotalQuantity( |
| | | salesLedgerProduct.getTotalQuantity(), |
| | | salesLedgerProduct.getQuantity(), |
| | | salesLedgerProduct.getSingleQuantity() |
| | | )); |
| | | if (salesLedgerProduct.getId() == null) { |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | result = salesLedgerProductMapper.insert(salesLedgerProduct); |
| | |
| | | productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId()); |
| | | productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))); |
| | | productionPlan.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | productionPlan.setQtyRequired(salesLedgerProduct.getQuantity()); |
| | | productionPlan.setQtyRequired(normalizeTotalQuantity( |
| | | salesLedgerProduct.getTotalQuantity(), |
| | | salesLedgerProduct.getQuantity(), |
| | | salesLedgerProduct.getSingleQuantity() |
| | | )); |
| | | productionPlan.setSource("销售"); |
| | | productionPlan.setStatus(0); |
| | | productionPlan.setRequiredDate(salesLedger.getDeliveryDate());//需求日期=交货日期 |
| | |
| | | return singleQuantity; |
| | | } |
| | | |
| | | private BigDecimal normalizeTotalQuantity(BigDecimal totalQuantity, BigDecimal quantity, BigDecimal singleQuantity) { |
| | | if (totalQuantity != null && totalQuantity.compareTo(BigDecimal.ZERO) > 0) { |
| | | return totalQuantity; |
| | | } |
| | | if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return quantity.multiply(normalizeSingleQuantity(singleQuantity)); |
| | | } |
| | | |
| | | private String generateNextPlanNo(String datePrefix) { |
| | | QueryWrapper<ProductionPlan> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.likeRight("mps_no", "JH" + datePrefix); |