From 8e4456bfa6dc84a1c37c13ee515fa9d6347cc480 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 23 四月 2026 16:27:45 +0800
Subject: [PATCH] fix:1.生产计划 2.生产订单

---
 src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java |   94 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 84 insertions(+), 10 deletions(-)

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 2f9d675..f9e4008 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
@@ -13,7 +13,6 @@
 import com.ruoyi.production.bean.dto.ProductionPlanDto;
 import com.ruoyi.production.bean.dto.ProductionPlanImportDto;
 import com.ruoyi.production.bean.vo.ProductionPlanVo;
-import com.ruoyi.production.enums.ProductOrderStatusEnum;
 import com.ruoyi.production.mapper.ProductionOrderMapper;
 import com.ruoyi.production.mapper.ProductionPlanMapper;
 import com.ruoyi.production.pojo.ProductionOrder;
@@ -42,14 +41,7 @@
 
     @Override
     public IPage<ProductionPlanVo> listPage(Page<ProductionPlanDto> page, ProductionPlanDto productionPlanDto) {
-
-        IPage<ProductionPlanVo> planVoIPage = productionPlanMapper.listPage(page, productionPlanDto)
-                .convert(dto -> {
-                    ProductionPlanVo vo = new ProductionPlanVo();
-                    BeanUtils.copyProperties(dto, vo);
-                    return vo;
-                });
-        return planVoIPage;
+        return productionPlanMapper.listPage(page, productionPlanDto);
     }
 
     /**
@@ -85,7 +77,89 @@
         ProductionOrder productionOrder = new ProductionOrder();
         productionOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
         productionOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
-        productionOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
+//        // 鍙犲姞鍓╀綑鏂规暟
+//        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);
+//        }
         return true;
     }
 

--
Gitblit v1.9.3