From 831163b8a651e5b4e752581d48762f4f7db4ed80 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 11 三月 2026 17:43:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_宁夏_中盛建材' into dev_宁夏_中盛建材

---
 src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java                  |    7 ++
 src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java                    |   18 ++++++
 src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java |   70 +++++++++++++----------
 src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java       |   32 +++++++++-
 src/main/java/com/ruoyi/productionPlan/dto/ProductionPlanDto.java                  |    8 +-
 doc/宁夏-中盛建材.sql                                                                    |    3 
 src/main/resources/mapper/productionPlan/ProductionPlanMapper.xml                  |    6 ++
 src/main/java/com/ruoyi/production/pojo/ProductOrder.java                          |   13 +---
 8 files changed, 107 insertions(+), 50 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 7c58d7a..6823bce 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"
@@ -92,7 +92,7 @@
     add assigned_quantity DECIMAL(10, 4) default 0 not null COMMENT '涓嬪彂鏁伴噺';
 
 alter table product_order
-    add plan_complete_time datetime(0) NULL DEFAULT NULL COMMENT '璁″垝瀹屾垚鏃堕棿';
+    add plan_complete_time date NULL DEFAULT NULL COMMENT '璁″垝瀹屾垚鏃堕棿';
 
 # 鐢熶骇璁㈠崟涓庣敓浜ц鍒掑叧鑱旇〃
 drop table if exists product_order_plan;
@@ -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/pojo/ProductOrder.java b/src/main/java/com/ruoyi/production/pojo/ProductOrder.java
index 0e06718..4f5a92e 100644
--- a/src/main/java/com/ruoyi/production/pojo/ProductOrder.java
+++ b/src/main/java/com/ruoyi/production/pojo/ProductOrder.java
@@ -10,6 +10,7 @@
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -36,18 +37,12 @@
     private String npsNo;
 
     /**
-     * 鍚堝苟鐢熶骇璁″垝ids
-     */
-    @ApiModelProperty(value = "鍚堝苟鐢熶骇璁″垝ids")
-    private String combineProductionPlanIds;
-
-    /**
      * 璁″垝瀹屾垚鏃堕棿
      */
     @ApiModelProperty(value = "璁″垝瀹屾垚鏃堕棿")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime planCompleteTime;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private LocalDate planCompleteTime;
 
     /**
      * 绉熸埛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/dto/ProductionPlanDto.java b/src/main/java/com/ruoyi/productionPlan/dto/ProductionPlanDto.java
index e416d5b..69e2556 100644
--- a/src/main/java/com/ruoyi/productionPlan/dto/ProductionPlanDto.java
+++ b/src/main/java/com/ruoyi/productionPlan/dto/ProductionPlanDto.java
@@ -8,7 +8,7 @@
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
+import java.time.LocalDate;
 import java.util.List;
 
 @Data
@@ -20,7 +20,7 @@
     private BigDecimal totalAssignedQuantity;
 
     @ApiModelProperty(value = "璁″垝瀹屾垚鏃堕棿")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime planCompleteTime;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private LocalDate planCompleteTime;
 }
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/pojo/ProductionPlan.java b/src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java
index 8839bd6..2273b1f 100644
--- a/src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java
+++ b/src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java
@@ -7,6 +7,7 @@
 import com.ruoyi.framework.aspectj.lang.annotation.Excel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -126,6 +127,7 @@
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     @ApiModelProperty("寮�濮嬫棩鏈�")
     @Excel(name = "寮�濮嬫棩鏈�", width = 20, dateFormat = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
     private Date startDate;
 
     /**
@@ -134,6 +136,7 @@
     @ApiModelProperty("缁撴潫鏃ユ湡")
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     @Excel(name = "缁撴潫鏃ユ湡", width = 20, dateFormat = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
     private Date endDate;
 
     /**
@@ -227,4 +230,19 @@
     @ApiModelProperty(value = "涓嬪彂鏁伴噺")
     @Excel(name = "涓嬪彂鏁伴噺")
     private BigDecimal assignedQuantity;
+
+    /**
+     * 璁$畻鍓╀綑鏂规暟
+     * @return 鍓╀綑鏂规暟
+     */
+    @ApiModelProperty(value = "鍓╀綑鏂规暟")
+    public BigDecimal getRemainingVolume() {
+        if (volume == null) {
+            return BigDecimal.ZERO;
+        }
+        if (assignedQuantity == null) {
+            return volume;
+        }
+        return volume.subtract(assignedQuantity);
+    }
 }
\ No newline at end of file
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 f0584d7..1b21552 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();
@@ -121,37 +122,14 @@
         }
 
 
-        // 鍙犲姞鏂规暟
-        BigDecimal totalVolume = plans.stream()
-                .map(ProductionPlan::getVolume)
+        // 鍙犲姞鍓╀綑鏂规暟
+        BigDecimal totalRemainingVolume = plans.stream()
+                .map(ProductionPlan::getRemainingVolume)
                 .filter(v -> v != null)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
-        // 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鏂规暟
-        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) {
-
-            log.warn("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庢柟鏁�");
-            return false;
-        }
-
-        // 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
-        BigDecimal assignedVolume = BigDecimal.ZERO;
-        for (ProductionPlan plan : plans) {
-            BigDecimal volume = plan.getVolume();
-            if (volume == null) {
-                continue;
-            }
-
-            if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
-                // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
-                plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume));
-                productionPlanMapper.updateById(plan);
-                break;
-            }
-
-            // 鍒嗛厤褰撳墠璁″垝鏂规暟
-            plan.setAssignedQuantity(volume);
-            productionPlanMapper.updateById(plan);
-            assignedVolume = assignedVolume.add(volume);
+        // 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鍓╀綑鏂规暟
+        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) {
+            throw new BaseException("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庡墿浣欐柟鏁�");
         }
 
         // 鍒涘缓鐢熶骇璁㈠崟
@@ -160,11 +138,41 @@
         productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
         productOrderService.addProductOrder(productOrder);
 
-        for (Long planId : productionPlanDto.getIds()) {
+        // 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
+        BigDecimal assignedVolume = BigDecimal.ZERO;
+        for (ProductionPlan plan : plans) {
+            BigDecimal volume = plan.getVolume();
+            if (volume == null) {
+                continue;
+            }
+            // 璁$畻鍓╀綑鏂规暟
+            BigDecimal remainingVolume = plan.getRemainingVolume();
+            if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) {
+                continue;
+            }
+
             ProductOrderPlan productOrderPlan = new ProductOrderPlan();
             productOrderPlan.setProductOrderId(productOrder.getId());
-            productOrderPlan.setProductionPlanId(planId);
+            productOrderPlan.setProductionPlanId(plan.getId());
+
+            if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
+                // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
+                BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
+                plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
+                productOrderPlan.setAssignedQuantity(lastRemainingVolume);
+                productionPlanMapper.updateById(plan);
+                productOrderPlanMapper.insert(productOrderPlan);
+                break;
+            }
+
+            // 鍒嗛厤褰撳墠璁″垝鏂规暟
+            plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
+            productOrderPlan.setAssignedQuantity(remainingVolume);
+            // 鏇存柊鐢熶骇璁″垝
+            productionPlanMapper.updateById(plan);
+            // 鍒涘缓鍏宠仈鍏崇郴
             productOrderPlanMapper.insert(productOrderPlan);
+            assignedVolume = assignedVolume.add(remainingVolume);
         }
         return true;
     }
diff --git a/src/main/resources/mapper/productionPlan/ProductionPlanMapper.xml b/src/main/resources/mapper/productionPlan/ProductionPlanMapper.xml
index 4bf0e0d..b4bea0a 100644
--- a/src/main/resources/mapper/productionPlan/ProductionPlanMapper.xml
+++ b/src/main/resources/mapper/productionPlan/ProductionPlanMapper.xml
@@ -54,6 +54,12 @@
         <if test="c.materialCode != null and c.materialCode != '' ">
             AND pp.material_code LIKE CONCAT('%',#{c.materialCode},'%')
         </if>
+        <if test="c.startDate != null">
+            AND pp.start_date &gt;= DATE_FORMAT(#{c.startDate},'%Y-%m-%d')
+        </if>
+        <if test="c.endDate != null">
+            AND pp.end_date &lt;= DATE_FORMAT(#{c.endDate},'%Y-%m-%d')
+        </if>
     </select>
 
     <select id="selectSummaryByProductType" resultType="com.ruoyi.productionPlan.dto.ProductionPlanSummaryDto">

--
Gitblit v1.9.3