From 270c132a66a26b29a540cf696e9078015fb58de4 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 24 四月 2026 09:50:37 +0800
Subject: [PATCH] fix:1.生产计划部分

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java   |    5 
 src/main/java/com/ruoyi/production/bean/dto/ProductionPlanDto.java              |   30 ----
 src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java  |  234 +++++++++++++++++---------------------
 src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java |   27 ++--
 src/main/resources/mapper/production/ProductionPlanMapper.xml                   |   37 ++---
 src/main/java/com/ruoyi/production/bean/vo/ProductionPlanVo.java                |    4 
 6 files changed, 137 insertions(+), 200 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/bean/dto/ProductionPlanDto.java b/src/main/java/com/ruoyi/production/bean/dto/ProductionPlanDto.java
index 3f6ef76..4e0913e 100644
--- a/src/main/java/com/ruoyi/production/bean/dto/ProductionPlanDto.java
+++ b/src/main/java/com/ruoyi/production/bean/dto/ProductionPlanDto.java
@@ -16,30 +16,14 @@
 @Data
 public class ProductionPlanDto extends ProductionPlan {
 
-    /**
-     * 鐗╂枡缂栫爜
-     */
-    @Schema(description = "鐗╂枡缂栫爜")
-    @Excel(name = "鐗╂枡缂栫爜")
-    private String materialCode;
-
-    /**
-     * 浜у搧鍚嶇О
-     */
     @Schema(description = "浜у搧鍚嶇О")
     @Excel(name = "浜у搧鍚嶇О")
     private String productName;
 
-    /**
-     * 瀹㈡埛鍚嶇О
-     */
     @Schema(description = "瀹㈡埛鍚嶇О")
     @Excel(name = "瀹㈡埛鍚嶇О")
     private String customerName;
 
-    /**
-     * 浜у搧瑙勬牸
-     */
     @Schema(description = "浜у搧瑙勬牸")
     @Excel(name = "浜у搧瑙勬牸")
     private String model;
@@ -59,17 +43,7 @@
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private LocalDate planCompleteTime;
 
-    /**
-     * 鍏宠仈鐗╂枡淇℃伅琛�
-     */
-    @Schema(description = "鍏宠仈鐗╂枡淇℃伅琛↖D")
-    private Long productMaterialId;
-
-    /**
-     * 寮哄害
-     */
-    @Schema(description = "寮哄害")
-    @Excel(name = "寮哄害")
-    private String strength;
+    @Schema(description = "浜у搧ID")
+    private Long productId;
 
 }
diff --git a/src/main/java/com/ruoyi/production/bean/vo/ProductionPlanVo.java b/src/main/java/com/ruoyi/production/bean/vo/ProductionPlanVo.java
index 4c0dbe3..ff32fd1 100644
--- a/src/main/java/com/ruoyi/production/bean/vo/ProductionPlanVo.java
+++ b/src/main/java/com/ruoyi/production/bean/vo/ProductionPlanVo.java
@@ -21,6 +21,6 @@
     @Schema(description = "鍗曚綅")
     private String unit;
 
-    @Schema(description = "鍏宠仈浜у搧鐗╂枡ID")
-    private Long productMaterialId;
+    @Schema(description = "浜у搧ID")
+    private Long productId;
 }
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
index c6d90cf..5ec666b 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -62,7 +63,7 @@
     private final FileUtil fileUtil;
 
     @Override
-    public com.baomidou.mybatisplus.core.metadata.IPage<ProductionOrderVo> pageProductionOrder(Page<ProductionOrderDto> page, ProductionOrderDto dto) {
+    public IPage<ProductionOrderVo> pageProductionOrder(Page<ProductionOrderDto> page, ProductionOrderDto dto) {
         Page<ProductionOrderVo> result = (Page<ProductionOrderVo>) baseMapper.pageProductionOrder(page, dto);
         fillProductImages(result.getRecords());
         return result;
@@ -359,18 +360,18 @@
         if (defaultDecimal(productionOrder.getQuantity()).compareTo(BigDecimal.ZERO) <= 0) {
             throw new ServiceException("quantity must be greater than 0");
         }
-        if (productionOrder.getTechnologyRoutingId() == null) {
-            // 鏈樉寮忔寚瀹氬伐鑹鸿矾绾挎椂锛屾寜浜у搧瑙勬牸閫夋渶鏂颁竴鏉″伐鑹轰綔涓洪粯璁よ矾绾裤��
-            TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne(
-                    Wrappers.<TechnologyRouting>lambdaQuery()
-                            .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId())
-                            .orderByDesc(TechnologyRouting::getId)
-                            .last("limit 1"));
-            if (technologyRouting == null) {
-                throw new ServiceException("No technology routing found for the product model");
-            }
-            productionOrder.setTechnologyRoutingId(technologyRouting.getId());
-        }
+//        if (productionOrder.getTechnologyRoutingId() == null) {
+//            // 鏈樉寮忔寚瀹氬伐鑹鸿矾绾挎椂锛屾寜浜у搧瑙勬牸閫夋渶鏂颁竴鏉″伐鑹轰綔涓洪粯璁よ矾绾裤��
+//            TechnologyRouting technologyRouting = technologyRoutingMapper.selectOne(
+//                    Wrappers.<TechnologyRouting>lambdaQuery()
+//                            .eq(TechnologyRouting::getProductModelId, productionOrder.getProductModelId())
+//                            .orderByDesc(TechnologyRouting::getId)
+//                            .last("limit 1"));
+//            if (technologyRouting == null) {
+//                throw new ServiceException("No technology routing found for the product model");
+//            }
+//            productionOrder.setTechnologyRoutingId(technologyRouting.getId());
+//        }
         if (oldOrder != null && ProductOrderStatusEnum.isStarted(oldOrder.getStatus())) {
             // 寮�宸ュ悗鍙厑璁镐慨姝i潪鏍稿績瀛楁锛屾牳蹇冪敓浜т緷鎹攣瀹氥��
             if (!Objects.equals(oldOrder.getProductModelId(), productionOrder.getProductModelId())
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
index f9e4008..1b09c74 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
@@ -17,6 +17,7 @@
 import com.ruoyi.production.mapper.ProductionPlanMapper;
 import com.ruoyi.production.pojo.ProductionOrder;
 import com.ruoyi.production.pojo.ProductionPlan;
+import com.ruoyi.production.service.ProductionOrderService;
 import com.ruoyi.production.service.ProductionPlanService;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
@@ -24,20 +25,22 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
 @RequiredArgsConstructor
 public class ProductionPlanServiceImpl extends ServiceImpl<ProductionPlanMapper, ProductionPlan> implements ProductionPlanService {
 
-    private final ProductionPlanMapper productionPlanMapper;
+    private static final int PLAN_STATUS_WAIT = 0;
+    private static final int PLAN_STATUS_PARTIAL = 1;
+    private static final int PLAN_STATUS_ISSUED = 2;
 
+    private final ProductionPlanMapper productionPlanMapper;
     private final ProductionOrderMapper productionOrderMapper;
+    private final ProductionOrderService productionOrderService;
 
     @Override
     public IPage<ProductionPlanVo> listPage(Page<ProductionPlanDto> page, ProductionPlanDto productionPlanDto) {
@@ -45,121 +48,87 @@
     }
 
     /**
-     * 鍚堝苟鐢熶骇璁″垝
+     * 鍚堝苟鐢熶骇璁″垝骞朵笅鍙戠敓浜ц鍗曘��
+     * 涓氬姟绾︽潫锛�
+     * 1. 浠呭厑璁稿悓涓�浜у搧鍨嬪彿鐨勮鍒掑悎骞讹紱
+     * 2. 宸蹭笅鍙戞垨閮ㄥ垎涓嬪彂鐨勮鍒掔姝㈠啀娆″悎骞讹紱
+     * 3. 涓嬪彂鏁伴噺涓嶈兘澶т簬鎵�閫夎鍒掗渶姹傛�婚噺锛�
+     * 4. 璁㈠崟鍒涘缓缁熶竴澶嶇敤 ProductionOrderService.saveProductionOrder锛岀‘淇濆伐鑹�/BOM/棰嗘枡涓诲崟绛夊悗缁�昏緫涓�鑷淬��
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean combine(ProductionPlanDto productionPlanDto) {
-        if (productionPlanDto.getIds() == null || productionPlanDto.getIds().isEmpty()) {
+        if (productionPlanDto == null || productionPlanDto.getIds() == null || productionPlanDto.getIds().isEmpty()) {
             return false;
         }
 
-        //  鏌ヨ涓荤敓浜ц鍒�
-        List<ProductionPlanDto> plans = productionPlanMapper.selectWithMaterialByIds(productionPlanDto.getIds());
-
-        if (plans == null || plans.isEmpty()) {
-            throw new ServiceException("涓嬪彂澶辫触,鐢熶骇璁″垝涓嶅瓨鍦�");
+        List<Long> planIds = productionPlanDto.getIds().stream()
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        if (planIds.isEmpty()) {
+            throw new ServiceException("涓嬪彂澶辫触锛屾湭閫夋嫨鐢熶骇璁″垝");
         }
 
-        //  鏍¢獙鏄惁瀛樺湪涓嶅悓鐨勪骇鍝佸悕绉�
-        String firstProductName = plans.get(0).getProductName();
-        if (plans.stream().anyMatch(p -> p.getProductName() == null || !p.getProductName().equals(firstProductName))) {
-            throw new BaseException("鍚堝苟澶辫触锛屽瓨鍦ㄤ笉鍚岀殑浜у搧鍚嶇О");
+        List<ProductionPlanDto> plans = productionPlanMapper.selectWithMaterialByIds(planIds);
+        if (plans == null || plans.isEmpty() || plans.size() != planIds.size()) {
+            throw new ServiceException("涓嬪彂澶辫触锛岀敓浜ц鍒掍笉瀛樺湪鎴栧凡琚垹闄�");
         }
 
-        // 鏍¢獙鏄惁瀛樺湪涓嶅悓鐨勪骇鍝佽鏍�
-        String firstProductSpec = plans.get(0).getModel();
-        if (plans.stream().anyMatch(p -> p.getModel() == null || !p.getModel().equals(firstProductSpec))) {
-            throw new BaseException("鍚堝苟澶辫触锛屽瓨鍦ㄤ笉鍚岀殑浜у搧瑙勬牸");
+        ProductionPlanDto firstPlan = plans.getFirst();
+        if (firstPlan.getProductModelId() == null) {
+            throw new ServiceException("涓嬪彂澶辫触锛岀敓浜ц鍒掔己灏戜骇鍝佸瀷鍙�");
         }
 
-        // 鍒涘缓鐢熶骇璁㈠崟
+        boolean hasDifferentModel = plans.stream()
+                .anyMatch(item -> !Objects.equals(item.getProductModelId(), firstPlan.getProductModelId()));
+        if (hasDifferentModel) {
+            throw new BaseException("鍚堝苟澶辫触锛屾墍閫夌敓浜ц鍒掔殑浜у搧鍨嬪彿涓嶄竴鑷�");
+        }
+
+        boolean hasIssuedPlan = plans.stream()
+                .anyMatch(item -> item.getStatus() != null && item.getStatus() != PLAN_STATUS_WAIT);
+        if (hasIssuedPlan) {
+            throw new BaseException("鍚堝苟澶辫触锛屾墍閫夌敓浜ц鍒掑瓨鍦ㄥ凡涓嬪彂鎴栭儴鍒嗕笅鍙戞暟鎹�");
+        }
+
+        BigDecimal totalRequiredQuantity = plans.stream()
+                .map(ProductionPlan::getQtyRequired)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        if (totalRequiredQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            throw new ServiceException("涓嬪彂澶辫触锛屾墍閫夌敓浜ц鍒掗渶姹傛�婚噺蹇呴』澶т簬0");
+        }
+
+        BigDecimal assignedQuantity = productionPlanDto.getTotalAssignedQuantity();
+        if (assignedQuantity == null || assignedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            throw new ServiceException("涓嬪彂澶辫触锛屼笅鍙戞暟閲忓繀椤诲ぇ浜�0");
+        }
+        if (assignedQuantity.compareTo(totalRequiredQuantity) > 0) {
+            throw new ServiceException("涓嬪彂澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庤鍒掗渶姹傛�婚噺");
+        }
+
         ProductionOrder productionOrder = new ProductionOrder();
-        productionOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
+        productionOrder.setProductionPlanIds(formatPlanIds(planIds));
+        productionOrder.setProductModelId(firstPlan.getProductModelId());
+        productionOrder.setQuantity(assignedQuantity);
         productionOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
-//        // 鍙犲姞鍓╀綑鏂规暟
-//        BigDecimal totalRemainingVolume = plans.stream()
-//                .map(ProductionPlan::getRemainingVolume)
-//                .filter(Objects::nonNull)
-//                .reduce(BigDecimal.ZERO, BigDecimal::add);
-//        // 鍒ゆ柇涓嬪彂鏁伴噺鏄惁澶т簬绛変簬鍓╀綑鏂规暟
-//        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) {
-//            throw new BaseException("鎿嶄綔澶辫触锛屼笅鍙戞暟閲忎笉鑳藉ぇ浜庡墿浣欐柟鏁�");
-//        }
-//
-//        // 鍒涘缓鐢熶骇璁㈠崟
-//        ProductOrder productOrder = new ProductOrder();
-//        productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
-//        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
-//        productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
-//        productOrder.setStrength(productionPlanDto.getStrength());
-//        productOrder.setProductMaterialSkuId(plans.get(0).getProductMaterialSkuId());
-//
-//        Long orderId = productOrderService.insertProductOrder(productOrder);
-//
-//        //  褰撲笅鍙戠殑浜у搧涓虹爩鍧楁垨鏉挎潗锛屽氨鎷夊彇BOM瀛愰泦涓庡伐鑹鸿矾绾垮瓙闆嗘暟鎹瓨鍏ュ埌闄勮〃涓�
-//        if ("鐮屽潡".equals(productionPlanDto.getProductName())) {
-//            productOrder.setRouteId(productionOrderAppendixService.populateBlocks(orderId, productionPlanDto));
-//        }
-//        if ("鏉挎潗".equals(productionPlanDto.getProductName())) {
-//            productOrder.setRouteId(productionOrderAppendixService.populatePlates(orderId, productionPlanDto));
-//        }
-//        //  鏇存柊缁戝畾鐨勫伐鑹鸿矾绾�
-//        productOrderService.updateById(productOrder);
-//
-//        // 鏍规嵁涓嬪彂鏁伴噺锛屼粠绗竴涓敓浜ц鍒掑紑濮嬪垎閰嶆柟鏁�
-//        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(plan.getId());
-//
-//            if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
-//                // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
-//                BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
-//                BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(lastRemainingVolume);
-//                plan.setAssignedQuantity(assignedQuantity);
-//                plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
-//                productOrderPlan.setAssignedQuantity(lastRemainingVolume);
-//                productionPlanMapper.updateById(plan);
-//                productOrderPlanMapper.insert(productOrderPlan);
-//                break;
-//            }
-//
-//            // 鍒嗛厤褰撳墠璁″垝鏂规暟
-//            BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(remainingVolume);
-//            plan.setAssignedQuantity(assignedQuantity);
-//            plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
-//            productOrderPlan.setAssignedQuantity(remainingVolume);
-//            // 鏇存柊鐢熶骇璁″垝
-//            productionPlanMapper.updateById(plan);
-//            // 鍒涘缓鍏宠仈鍏崇郴
-//            productOrderPlanMapper.insert(productOrderPlan);
-//            assignedVolume = assignedVolume.add(remainingVolume);
-//        }
-//
-//        for (ProductionPlan plan : plans) {
-//            BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO);
-//            BigDecimal volume = Optional.ofNullable(plan.getVolume()).orElse(BigDecimal.ZERO);
-//            if (assignedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
-//                plan.setStatus(0);
-//            } else if (assignedQuantity.compareTo(volume) >= 0) {
-//                plan.setStatus(2);
-//            } else {
-//                plan.setStatus(1);
-//            }
-//            productionPlanMapper.updateById(plan);
-//        }
+
+        boolean saved = productionOrderService.saveProductionOrder(productionOrder);
+        if (!saved) {
+            throw new ServiceException("涓嬪彂澶辫触锛岀敓浜ц鍗曚繚瀛樺け璐�");
+        }
+
+        int targetStatus = assignedQuantity.compareTo(totalRequiredQuantity) < 0 ? PLAN_STATUS_PARTIAL : PLAN_STATUS_ISSUED;
+        List<ProductionPlan> updates = planIds.stream().map(id -> {
+            ProductionPlan update = new ProductionPlan();
+            update.setId(id);
+            update.setStatus(targetStatus);
+            return update;
+        }).collect(Collectors.toList());
+        if (!updates.isEmpty()) {
+            this.updateBatchById(updates);
+        }
         return true;
     }
 
@@ -171,7 +140,7 @@
         }
         checkApplyNoUnique(dto.getApplyNo(), null);
 
-        dto.setStatus(0);
+        dto.setStatus(PLAN_STATUS_WAIT);
         return productionPlanMapper.insert(dto) > 0;
     }
 
@@ -179,22 +148,19 @@
     @Transactional(rollbackFor = Exception.class)
     public boolean update(ProductionPlanDto dto) {
         if (dto == null || dto.getId() == null) {
-            throw new ServiceException("缂栬緫澶辫触,鏁版嵁涓嶈兘涓虹┖");
+            throw new ServiceException("缂栬緫澶辫触锛屾暟鎹笉鑳戒负绌�");
         }
 
         ProductionPlan old = getById(dto.getId());
         if (old == null) {
-            throw new ServiceException("缂栬緫澶辫触,涓荤敓浜ц鍒掍笉瀛樺湪");
+            throw new ServiceException("缂栬緫澶辫触锛岀敓浜ц鍒掍笉瀛樺湪");
         }
 
-        // 鐘舵�佹牎楠�
-        if (old.getStatus() != 0) {
-            throw new BaseException("缂栬緫澶辫触,璇ョ敓浜ц鍒掑凡涓嬪彂鎴栭儴鍒嗕笅鍙戠姸鎬�,绂佹缂栬緫");
+        if (old.getStatus() != PLAN_STATUS_WAIT) {
+            throw new BaseException("缂栬緫澶辫触锛岃鐢熶骇璁″垝宸蹭笅鍙戞垨閮ㄥ垎涓嬪彂锛岀姝㈢紪杈�");
         }
 
-        // applyNo鍙樻洿鎵嶆牎楠�
-        if (StringUtils.isNotBlank(dto.getApplyNo())
-                && !dto.getApplyNo().equals(old.getApplyNo())) {
+        if (StringUtils.isNotBlank(dto.getApplyNo()) && !dto.getApplyNo().equals(old.getApplyNo())) {
             checkApplyNoUnique(dto.getApplyNo(), dto.getId());
         }
 
@@ -204,11 +170,9 @@
     private void checkApplyNoUnique(String applyNo, Long excludeId) {
         LambdaQueryWrapper<ProductionPlan> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(ProductionPlan::getApplyNo, applyNo);
-
         if (excludeId != null) {
             wrapper.ne(ProductionPlan::getId, excludeId);
         }
-
         if (productionPlanMapper.selectCount(wrapper) > 0) {
             throw new ServiceException("鐢宠鍗曠紪鍙� " + applyNo + " 宸插瓨鍦�");
         }
@@ -217,13 +181,16 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean delete(List<Long> ids) {
-        // 濡傛灉瀛樺湪宸蹭笅鍙戠殑璁″垝锛屽垯涓嶈兘鍒犻櫎
-        if (productionPlanMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery().in(ProductionPlan::getId, ids)).stream().anyMatch(p -> p.getStatus() == 1 || p.getStatus() == 2)) {
+        if (productionPlanMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery().in(ProductionPlan::getId, ids))
+                .stream()
+                .anyMatch(p -> p.getStatus() == PLAN_STATUS_PARTIAL || p.getStatus() == PLAN_STATUS_ISSUED)) {
             throw new BaseException("鍒犻櫎澶辫触锛屽瓨鍦ㄥ凡涓嬪彂鎴栭儴鍒嗕笅鍙戠殑璁″垝");
         }
-        // 濡傛灉鏈夊叧鑱旇鍗曪紝鍒欎笉鑳藉垹闄�
-        if (productionOrderMapper.selectList(Wrappers.<ProductionOrder>lambdaQuery().in(ProductionOrder::getProductionPlanIds, ids)).stream().anyMatch(p -> p.getId() != null)) {
-            throw new BaseException("鍒犻櫎澶辫触锛屽瓨鍦ㄥ叧鑱旇鍗�");
+
+        if (productionOrderMapper.selectList(Wrappers.<ProductionOrder>lambdaQuery().in(ProductionOrder::getProductionPlanIds, ids))
+                .stream()
+                .anyMatch(p -> p.getId() != null)) {
+            throw new BaseException("鍒犻櫎澶辫触锛屽瓨鍦ㄥ叧鑱旂敓浜ц鍗�");
         }
 
         return productionPlanMapper.deleteBatchIds(ids) > 0;
@@ -235,12 +202,12 @@
         if (file == null || file.isEmpty()) {
             throw new ServiceException("瀵煎叆鏁版嵁涓嶈兘涓虹┖");
         }
+
         ExcelUtil<ProductionPlanImportDto> excelUtil = new ExcelUtil<>(ProductionPlanImportDto.class);
         List<ProductionPlanImportDto> list;
         try {
             list = excelUtil.importExcel(file.getInputStream());
         } catch (Exception e) {
-            log.error("鐢熶骇闇�姹侲xcel瀵煎叆澶辫触", e);
             throw new ServiceException("Excel瑙f瀽澶辫触");
         }
 
@@ -259,29 +226,28 @@
                 throw new ServiceException("瀵煎叆澶辫触锛氱 " + (i + 2) + " 琛岀敵璇峰崟缂栧彿涓嶈兘涓虹┖");
             }
             if (!applyNos.add(applyNo)) {
-                throw new ServiceException("瀵煎叆澶辫触锛欵xcel 涓瓨鍦ㄩ噸澶嶇殑鐢宠鍗曠紪鍙�: " + applyNo);
+                throw new ServiceException("瀵煎叆澶辫触锛欵xcel 涓瓨鍦ㄩ噸澶嶇殑鐢宠鍗曠紪鍙� " + applyNo);
             }
             if (StringUtils.isEmpty(materialCode)) {
                 throw new ServiceException("瀵煎叆澶辫触锛氱 " + (i + 2) + " 琛岀墿鏂欑紪鐮佷笉鑳戒负绌�");
             }
 
             String strength = dto.getStrength();
-            if (StringUtils.isNotEmpty(strength)) {
-                if (!"A3.5".equals(strength) && !"A5.0".equals(strength)) {
-                    throw new ServiceException("瀵煎叆澶辫触锛氱 " + (i + 2) + " 琛屽己搴﹀彧鑳芥槸 A3.5 鎴� A5.0");
-                }
+            if (StringUtils.isNotEmpty(strength) && !"A3.5".equals(strength) && !"A5.0".equals(strength)) {
+                throw new ServiceException("瀵煎叆澶辫触锛氱 " + (i + 2) + " 琛屽己搴﹀彧鑳芥槸 A3.5 鎴� A5.0");
             }
 
             materialCodes.add(materialCode);
         }
 
-        //  鐢宠鍗曠紪鍙锋槸鍚﹀凡瀛樺湪
         Long existApplyNoCount = baseMapper.selectCount(Wrappers.<ProductionPlan>lambdaQuery()
                 .in(ProductionPlan::getApplyNo, applyNos));
         if (existApplyNoCount > 0) {
             List<String> existApplyNos = baseMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery()
                             .in(ProductionPlan::getApplyNo, applyNos))
-                    .stream().map(ProductionPlan::getApplyNo).collect(Collectors.toList());
+                    .stream()
+                    .map(ProductionPlan::getApplyNo)
+                    .collect(Collectors.toList());
             throw new ServiceException("瀵煎叆澶辫触锛岀敵璇峰崟缂栧彿宸插瓨鍦�: " + String.join(", ", existApplyNos));
         }
 
@@ -289,7 +255,7 @@
         List<ProductionPlan> entityList = list.stream().map(dto -> {
             ProductionPlan entity = new ProductionPlan();
             BeanUtils.copyProperties(dto, entity);
-            entity.setStatus(0);
+            entity.setStatus(PLAN_STATUS_WAIT);
             entity.setCreateTime(now);
             entity.setUpdateTime(now);
             return entity;
@@ -316,4 +282,12 @@
         ExcelUtil<ProductionPlanImportDto> util = new ExcelUtil<>(ProductionPlanImportDto.class);
         util.exportExcel(response, exportList, "閿�鍞敓浜ч渶姹傛暟鎹�");
     }
+
+    private String formatPlanIds(List<Long> planIds) {
+        return planIds.stream()
+                .filter(Objects::nonNull)
+                .distinct()
+                .map(String::valueOf)
+                .collect(Collectors.joining(",", "[", "]"));
+    }
 }
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 56cfbb0..f30cb1d 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -11,10 +11,7 @@
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.mapper.*;
-import com.ruoyi.production.pojo.ProductionAccount;
-import com.ruoyi.production.pojo.ProductionOperationTask;
-import com.ruoyi.production.pojo.ProductionOrder;
-import com.ruoyi.production.pojo.ProductionProductMain;
+import com.ruoyi.production.pojo.*;
 import com.ruoyi.production.service.ProductionOrderService;
 import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
 import com.ruoyi.purchase.pojo.PurchaseLedger;
diff --git a/src/main/resources/mapper/production/ProductionPlanMapper.xml b/src/main/resources/mapper/production/ProductionPlanMapper.xml
index a7ad8f7..da0d293 100644
--- a/src/main/resources/mapper/production/ProductionPlanMapper.xml
+++ b/src/main/resources/mapper/production/ProductionPlanMapper.xml
@@ -23,31 +23,25 @@
     <select id="listPage" resultType="com.ruoyi.production.bean.vo.ProductionPlanVo">
         SELECT
         pp.*,
-        pms.material_code AS materialCode,
-        pmdl.model,
-        pms.product_id AS productMaterialId,
+        pm.model,
+        p.id as productId,
         p.product_name AS productName,
-        pmdl.unit
+        pm.unit
         FROM production_plan pp
-        left join product_material_sku pms on pp.product_material_sku_id = pms.id
-        left join product_model pmdl on pp.product_model_id = pmdl.id
-        left join product p on pmdl.product_id = p.id
-
-        ORDER BY COALESCE(pp.form_modified_time, pp.id) DESC
+        left join product_model pm on pp.product_model_id = pm.id
+        left join product p on pm.product_id = p.id
+        ORDER BY COALESCE(pp.id) DESC
     </select>
 
     <select id="selectWithMaterialByIds" resultType="com.ruoyi.production.bean.dto.ProductionPlanDto">
         SELECT
         pp.*,
-        pms.material_code AS materialCode,
-        pmdl.model,
+        pm.model,
         p.product_name AS productName,
-        pmdl.unit,
-        pms.product_id AS productMaterialId
+        pm.unit
         FROM production_plan pp
-        LEFT JOIN product_material_sku pms ON pp.product_material_sku_id = pms.id
-        LEFT JOIN product_model pmdl ON pp.product_model_id = pmdl.id
-        LEFT JOIN product p ON pmdl.product_id = p.id
+        LEFT JOIN product_model pm ON pp.product_model_id = pm.id
+        LEFT JOIN product p ON pm.product_id = p.id
         WHERE pp.id IN
         <foreach collection="ids" item="id" open="(" separator="," close=")">
             #{id}
@@ -57,15 +51,12 @@
     <select id="selectProductionPlanDtoById" resultType="com.ruoyi.production.bean.dto.ProductionPlanDto">
         SELECT
         pp.*,
-        pms.material_code AS materialCode,
-        pmdl.model,
-        pms.product_id AS productMaterialId,
+        pm.model,
         p.product_name AS productName,
-        pmdl.unit
+        pm.unit
         FROM production_plan pp
-        left join product_material_sku pms on pp.product_material_sku_id = pms.id
-        left join product_model pmdl on pp.product_model_id = pmdl.id
-        left join product p on pmdl.product_id = p.id
+        left join product_model pm on pp.product_model_id = pm.id
+        left join product p on pm.product_id = p.id
         WHERE pp.id = #{productionPlanId}
     </select>
 </mapper>

--
Gitblit v1.9.3