From fe64e0bbc83ab7e89cbe0d6a9f779a4ac3919608 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 21 九月 2026 11:13:58 +0800
Subject: [PATCH] fix: 销售订单未下发/发货则可以进行编辑
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
index 28ce78a..38013f1 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.AmountUtils;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.utils.StockUtils;
@@ -38,6 +39,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -177,12 +179,9 @@
result = salesLedgerProductMapper.insert(salesLedgerProduct);
addProductionData(salesLedgerProduct);
} else {
- //鏌ヨ鍘熸湰鐨勪骇鍝佸瀷鍙穒d
result = salesLedgerProductMapper.updateById(salesLedgerProduct);
- /*鍒犻櫎瀵瑰簲鐨勭敓浜ф暟鎹苟閲嶆柊鏂板*/
- deleteProductionData(Arrays.asList(salesLedgerProduct.getId()));
-
- addProductionData(salesLedgerProduct);
+ /*鍚屾瀵瑰簲鐨勭敓浜ф暟鎹細璁″垝鏈笅鍙戞椂鍘熷湴鏇存柊闇�姹傛暟閲忥紝淇濈暀鐢熶骇璁″垝鍙�*/
+ syncProductionData(salesLedgerProduct);
}
// 濡傛灉鎻掑叆鎴栨洿鏂版垚鍔燂紝骞朵笖鏈� salesLedgerId锛屾墠缁х画鏇存柊涓昏〃閲戦
@@ -238,6 +237,38 @@
}
/**
+ * 鍚屾鐢熶骇鏁版嵁
+ * 闇�瑕佺敓浜э細鐢熶骇璁″垝宸蹭笅鍙戞椂绂佹淇敼锛涙湭涓嬪彂鏃跺師鍦版洿鏂伴渶姹傛暟閲忥紝淇濈暀鐢熶骇璁″垝鍙凤紱
+ * 鏀逛负璧板簱瀛橈細鍒犻櫎鏈笅鍙戠殑鐢熶骇璁″垝銆�
+ */
+ public void syncProductionData(SalesLedgerProduct salesLedgerProduct) {
+ if (salesLedgerProduct.getId() == null) {
+ return;
+ }
+ List<ProductionPlan> productionPlans = listProductionData(salesLedgerProduct.getId());
+ if (CollectionUtils.isEmpty(productionPlans)) {
+ //鍘熸潵涓嶉渶瑕佺敓浜э紝鐜板湪鏀逛负闇�瑕佺敓浜э紝琛ュ缓鐢熶骇璁″垝
+ if (Boolean.TRUE.equals(salesLedgerProduct.getIsProduction())) {
+ addProductionData(salesLedgerProduct);
+ }
+ return;
+ }
+ //鏀逛负璧板簱瀛橈紝鍒犻櫎鏈笅鍙戠殑鐢熶骇璁″垝
+ if (!Boolean.TRUE.equals(salesLedgerProduct.getIsProduction())) {
+ deleteProductionData(Collections.singletonList(salesLedgerProduct.getId()));
+ return;
+ }
+ if (productionPlans.stream().anyMatch(plan -> plan.getStatus() != null && plan.getStatus() != 0)) {
+ throw new ServiceException("鐢熶骇璁″垝宸蹭笅鍙戯紝涓嶈兘淇敼璇ラ攢鍞骇鍝�");
+ }
+ for (ProductionPlan productionPlan : productionPlans) {
+ productionPlan.setQtyRequired(salesLedgerProduct.getQuantity());
+ productionPlan.setProductModelId(salesLedgerProduct.getProductModelId());
+ productionPlanMapper.updateById(productionPlan);
+ }
+ }
+
+ /**
* 鍒犻櫎鐢熶骇璁″垝
*/
public void deleteProductionData(List<Long> productIds) {
@@ -246,12 +277,12 @@
}
List<ProductionPlan> productionPlans = productionPlanMapper.selectList(
new LambdaQueryWrapper<ProductionPlan>()
- .in(ProductionPlan::getSalesLedgerProductId, productIds.stream().map(Long::intValue).collect(Collectors.toList())));
+ .in(ProductionPlan::getSalesLedgerProductId, productIds));
if (CollectionUtils.isEmpty(productionPlans)) {
return;
}
//濡傛灉鐢熶骇璁″垝宸蹭笅鍙戝垯涓嶈兘鍒犻櫎
- if (productionPlans.stream().anyMatch(productionPlan -> productionPlan.getStatus() != 0)) {
+ if (productionPlans.stream().anyMatch(productionPlan -> productionPlan.getStatus() != null && productionPlan.getStatus() != 0)) {
throw new RuntimeException("鐢熶骇璁″垝宸蹭笅鍙戯紝涓嶈兘鍒犻櫎璇ラ攢鍞骇鍝�");
}
List<Long> ids = productionPlans.stream().map(ProductionPlan::getId).collect(Collectors.toList());
@@ -259,6 +290,14 @@
}
/**
+ * 鏌ヨ閿�鍞骇鍝佸搴旂殑鐢熶骇璁″垝
+ */
+ private List<ProductionPlan> listProductionData(Long productId) {
+ return productionPlanMapper.selectList(new LambdaQueryWrapper<ProductionPlan>()
+ .eq(ProductionPlan::getSalesLedgerProductId, productId));
+ }
+
+ /**
* 閫氱敤鏂规硶锛氭牴鎹富琛↖D鍜屽瓙琛ㄥ垪琛紝鏇存柊涓昏〃鐨勫悎鍚岄噾棰�
*/
public <T, S> void updateMainContractAmount(
--
Gitblit v1.9.3