From 901e3c96c76f168ddbeaa10562a4d2d6f4d3ba8c Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 25 五月 2026 15:07:09 +0800
Subject: [PATCH] refactor(approve): 重构审批业务状态同步逻辑
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index fe385f1..47a8a6c 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -388,6 +388,12 @@
for (SalesLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) {
SalesLedgerProduct salesLedgerProduct = new SalesLedgerProduct();
BeanUtils.copyProperties(salesLedgerProductImportDto, salesLedgerProduct);
+ salesLedgerProduct.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity()));
+ salesLedgerProduct.setTotalQuantity(normalizeTotalQuantity(
+ salesLedgerProduct.getTotalQuantity(),
+ salesLedgerProduct.getQuantity(),
+ salesLedgerProduct.getSingleQuantity()
+ ));
salesLedgerProduct.setSalesLedgerId(salesLedger.getId());
salesLedgerProduct.setType(1);
// 璁$畻涓嶅惈绋庢�讳环
@@ -590,7 +596,11 @@
public void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, SaleEnum type) {
// 鎸塈D鍒嗙粍锛屽尯鍒嗘柊澧炲拰鏇存柊鐨勮褰�
Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream()
- .peek(p -> p.setSalesLedgerId(salesLedgerId))
+ .peek(p -> {
+ p.setSalesLedgerId(salesLedgerId);
+ p.setSingleQuantity(normalizeSingleQuantity(p.getSingleQuantity()));
+ p.setTotalQuantity(normalizeTotalQuantity(p.getTotalQuantity(), p.getQuantity(), p.getSingleQuantity()));
+ })
.collect(Collectors.partitioningBy(p -> p.getId() != null));
List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
@@ -620,6 +630,23 @@
return entity;
}
+ private BigDecimal normalizeSingleQuantity(BigDecimal singleQuantity) {
+ if (singleQuantity == null || singleQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+ return BigDecimal.ONE;
+ }
+ 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));
+ }
+
@Transactional(readOnly = true)
public String generateSalesContractNo() {
LocalDate currentDate = LocalDate.now();
--
Gitblit v1.9.3