From 950dae8b64157cc3850ab64f4e4727dd139a5e3c Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 11 三月 2026 15:50:02 +0800
Subject: [PATCH] 撤回生产订单
---
src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java | 7 +++
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java | 39 ++++++++++---------
src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java | 32 +++++++++++++--
doc/宁夏-中盛建材.sql | 1
4 files changed, 56 insertions(+), 23 deletions(-)
diff --git "a/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql" "b/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
index b831f87..f51e9b0 100644
--- "a/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
+++ "b/doc/\345\256\201\345\244\217-\344\270\255\347\233\233\345\273\272\346\235\220.sql"
@@ -103,6 +103,7 @@
production_plan_id bigint not null default 0 comment '鐢熶骇璁″垝id',
create_time datetime null comment '褰曞叆鏃堕棿',
update_time datetime null comment '鏇存柊鏃堕棿',
+ assigned_quantity DECIMAL(10, 4) default 0 not null comment '涓嬪彂鏁伴噺',
index idx_product_order_id (product_order_id),
index idx_production_plan_id (production_plan_id),
unique idx_product_order_production_plan (product_order_id, production_plan_id)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
index 95e3f14..15a2d3c 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -15,10 +15,15 @@
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductOrderService;
+import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper;
+import com.ruoyi.productionPlan.mapper.ProductionPlanMapper;
+import com.ruoyi.productionPlan.pojo.ProductOrderPlan;
+import com.ruoyi.productionPlan.pojo.ProductionPlan;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.quality.pojo.QualityInspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
@@ -49,6 +54,12 @@
@Autowired
private ProductionProductMainMapper productionProductMainMapper;
+
+ @Autowired
+ private ProductOrderPlanMapper productOrderPlanMapper;
+
+ @Autowired
+ private ProductionPlanMapper productionPlanMapper;
@Autowired
private ProductionProductOutputMapper productionProductOutputMapper;
@@ -123,14 +134,25 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public Boolean revoke(ProductOrder productOrder) {
- //鍒ゆ柇鏄惁浜х敓宸ュ崟
- List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery().eq(ProductionProductMain::getProductOrderId, productOrder.getId()));
- if (!productionProductMains.isEmpty()) {
- throw new RuntimeException("鐢熶骇璁㈠崟宸茬粡鎶ュ伐,涓嶈兘鎾ら攢");
- }
+ // todo 鍒ゆ柇鏄惁浜х敓鎶ュ伐淇℃伅
// 鏌ヨ鍚堝苟鐨勭敓浜ц鍒�
+ List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
+ if (productOrderPlans.isEmpty()) {
+ throw new RuntimeException("鍚堝苟鐨勭敓浜ц鍒掍笉瀛樺湪");
+ }
+ for (ProductOrderPlan productOrderPlan : productOrderPlans) {
+ ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId());
+ productionPlan.setAssignedQuantity(productionPlan.getAssignedQuantity().subtract(productOrderPlan.getAssignedQuantity()));
+ productionPlanMapper.updateById(productionPlan);
+ }
+ // 鍒犻櫎鍏宠仈鍏崇郴
+ productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
+ // 鍒犻櫎璁㈠崟
+ productOrderMapper.deleteById(productOrder.getId());
+ // todo 鍒犻櫎璁㈠崟涓嬬殑宸ヨ壓璺嚎瀛愯〃
return null;
}
diff --git a/src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java b/src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java
index 9088e42..93053bc 100644
--- a/src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java
+++ b/src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java
@@ -6,7 +6,10 @@
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
+import java.math.BigDecimal;
import java.time.LocalDateTime;
+
+import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
@@ -37,6 +40,10 @@
@ApiModelProperty("鐢熶骇璁″垝id")
private Long productionPlanId;
+ @ApiModelProperty(value = "涓嬪彂鏁伴噺")
+ @Excel(name = "涓嬪彂鏁伴噺")
+ private BigDecimal assignedQuantity;
+
@ApiModelProperty("褰曞叆鏃堕棿")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
diff --git a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
index cb916e9..9cc0047 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -107,6 +107,7 @@
// 鏌ヨ涓荤敓浜ц鍒�
List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds());
+ plans.sort(Comparator.comparingLong(ProductionPlan::getId));
// 鏍¢獙鏄惁瀛樺湪涓嶅悓鐨勪骇鍝佸悕绉�
String firstProductName = plans.get(0).getProductName();
@@ -128,10 +129,14 @@
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鏂规暟
if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) {
-
- log.warn("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庢柟鏁�");
- return false;
+ throw new BaseException("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庢柟鏁�");
}
+
+ // 鍒涘缓鐢熶骇璁㈠崟
+ ProductOrder productOrder = new ProductOrder();
+ productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
+ productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
+ productOrderService.addProductOrder(productOrder);
// 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
BigDecimal assignedVolume = BigDecimal.ZERO;
@@ -141,30 +146,28 @@
continue;
}
+ ProductOrderPlan productOrderPlan = new ProductOrderPlan();
+ productOrderPlan.setProductOrderId(productOrder.getId());
+ productOrderPlan.setProductionPlanId(plan.getId());
+
if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
// 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
- plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume));
+ BigDecimal remainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
+ plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
+ productOrderPlan.setAssignedQuantity(remainingVolume);
productionPlanMapper.updateById(plan);
+ productOrderPlanMapper.insert(productOrderPlan);
break;
}
// 鍒嗛厤褰撳墠璁″垝鏂规暟
- plan.setAssignedQuantity(volume);
+ plan.setAssignedQuantity(plan.getAssignedQuantity().add(volume));
+ productOrderPlan.setAssignedQuantity(volume);
+ // 鏇存柊鐢熶骇璁″垝
productionPlanMapper.updateById(plan);
- assignedVolume = assignedVolume.add(volume);
- }
-
- // 鍒涘缓鐢熶骇璁㈠崟
- ProductOrder productOrder = new ProductOrder();
- productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
- productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
- productOrderService.addProductOrder(productOrder);
-
- for (Long planId : productionPlanDto.getIds()) {
- ProductOrderPlan productOrderPlan = new ProductOrderPlan();
- productOrderPlan.setProductOrderId(productOrder.getId());
- productOrderPlan.setProductionPlanId(planId);
+ // 鍒涘缓鍏宠仈鍏崇郴
productOrderPlanMapper.insert(productOrderPlan);
+ assignedVolume = assignedVolume.add(volume);
}
return true;
}
--
Gitblit v1.9.3