From 3777b6430fe0ed70186cbbcdcf38c464e3adf47f Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 27 三月 2026 17:57:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_长治_健齿齿科器材' into dev_长治_健齿齿科器材

---
 src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java |  250 +++++++++++++++++++++++++++++++------------------
 1 files changed, 159 insertions(+), 91 deletions(-)

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 33a80c8..0ed4db6 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -1,30 +1,38 @@
 package com.ruoyi.production.service.impl;
 
+import cn.hutool.core.util.BooleanUtil;
+import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockUnQualifiedRecordTypeEnum;
+import com.ruoyi.basic.dto.SelectOptionDTO;
+import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.procurementrecord.utils.StockUtils;
-import com.ruoyi.production.dto.ProductBomDto;
+import com.ruoyi.production.dto.DrawMaterialDto;
 import com.ruoyi.production.dto.ProductOrderDto;
 import com.ruoyi.production.dto.ProductStructureDto;
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.production.pojo.*;
-import com.ruoyi.production.service.ProcessRouteService;
 import com.ruoyi.production.service.ProductOrderService;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
-import com.ruoyi.quality.pojo.QualityInspect;
+import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
 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;
 import java.time.format.DateTimeFormatter;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -66,9 +74,26 @@
     @Autowired
     private StockUtils stockUtils;
 
+    @Autowired
+    private ProductStructureMapper productStructureMapper;
+
+    @Autowired
+    private StockInventoryMapper stockInventoryMapper;
+
+
     @Override
     public IPage<ProductOrderDto> pageProductOrder(Page page, ProductOrderDto productOrder) {
-        return productOrderMapper.pageProductOrder(page, productOrder);
+        IPage<ProductOrderDto> productOrderDtoIPage = productOrderMapper.pageProductOrder(page, productOrder);
+        List<ProductOrderDto> productOrderDtos = productOrderDtoIPage.getRecords();
+        for (int i = 0; i < productOrderDtos.size(); i++) {
+            ProductOrderDto productOrderDto = productOrderDtos.get(i);
+            if (BooleanUtil.isTrue(productOrderDto.getIsEnd())) {
+                // 濡傛灉鐢熶骇璁㈠崟琚粨鏉燂紝鍒欏皢瀹屾垚杩涘害璁剧疆涓�100%
+                productOrderDto.setCompletionStatus(BigDecimal.valueOf(100));
+            }
+        }
+
+        return productOrderDtoIPage;
     }
 
     @Override
@@ -147,92 +172,27 @@
 
     @Override
     public Boolean delete(Long[] ids) {
-
-        //鎵归噺鏌ヨproductOrder
-        List<ProductOrder> productOrders = productOrderMapper.selectList(
-                new LambdaQueryWrapper<ProductOrder>()
-                        .in(ProductOrder::getId, ids)
-        );
-        if (!org.springframework.util.CollectionUtils.isEmpty(productOrders)) {
-
-
-            // 鎵归噺鏌ヨprocessRouteItems
-            List<ProductProcessRouteItem> allRouteItems = productProcessRouteItemMapper.selectList(
-                    new LambdaQueryWrapper<ProductProcessRouteItem>()
-                            .in(ProductProcessRouteItem::getProductOrderId, ids)
-            );
-
-            if (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(allRouteItems)) {
-                // 鑾峰彇瑕佸垹闄ょ殑宸ュ簭椤笽D
-                List<Long> routeItemIds = allRouteItems.stream()
-                        .map(ProductProcessRouteItem::getId)
-                        .collect(Collectors.toList());
-
-                // 鏌ヨ鍏宠仈鐨勫伐鍗旾D
-                List<ProductWorkOrder> workOrders = productWorkOrderMapper.selectList(
-                        new LambdaQueryWrapper<ProductWorkOrder>()
-                                .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds)
-                );
-                if (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(workOrders)) {
-                    List<Long> workOrderIds = workOrders.stream()
-                            .map(ProductWorkOrder::getId)
-                            .collect(Collectors.toList());
-
-                    // 鏌ヨ鍏宠仈鐨勭敓浜т富琛↖D
-                    List<ProductionProductMain> productMains = productionProductMainMapper.selectList(
-                            new LambdaQueryWrapper<ProductionProductMain>()
-                                    .in(ProductionProductMain::getWorkOrderId, workOrderIds)
-                    );
-                    List<Long> productMainIds = productMains.stream()
-                            .map(ProductionProductMain::getId)
-                            .collect(Collectors.toList());
-
-                    // 鍒犻櫎浜у嚭琛ㄣ�佹姇鍏ヨ〃鏁版嵁
-                    if (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(productMainIds)) {
-                        productionProductOutputMapper.deleteByProductMainIds(productMainIds);
-                        productionProductInputMapper.deleteByProductMainIds(productMainIds);
-                        List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(
-                                new LambdaQueryWrapper<QualityInspect>()
-                                        .in(QualityInspect::getProductMainId, productMainIds)
-                        );
-                        //鍒犻櫎鍑哄簱璁板綍
-                        for (Long productMainId : productMainIds) {
-                            //鍒犻櫎鐢熶骇鍑哄簱璁板綍
-                            stockUtils.deleteStockOutRecord(productMainId, StockQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode());
-                            //鍒犻櫎鎶ュ簾鐨勫叆搴撹褰�
-                            stockUtils.deleteStockInRecord(productMainId, StockUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode());
-                        }
-                        qualityInspects.forEach(qualityInspect -> {
-                            //inspectState=1 宸叉彁浜� 涓嶈兘鍒犻櫎
-                            if (qualityInspect.getInspectState() == 1) {
-                                throw new RuntimeException("宸叉彁浜ょ殑妫�楠屽崟涓嶈兘鍒犻櫎");
-                            }
-                        });
-                        qualityInspectMapper.deleteByProductMainIds(productMainIds);
-                        salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
-                                .in(SalesLedgerProductionAccounting::getProductMainId, productMainIds));
-                    }
-
-                    // 鍒犻櫎鐢熶骇涓昏〃鏁版嵁
-                    productionProductMainMapper.deleteByWorkOrderIds(workOrderIds);
-
-                    // 鍒犻櫎宸ュ崟鏁版嵁
-                    productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>()
-                            .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
-                }
+        //濡傛灉宸茬粡寮�濮嬬敓浜�,涓嶈兘鍒犻櫎
+        //鏌ヨ鐢熶骇璁㈠崟涓嬬殑宸ュ崟
+        List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids));
+        if (productWorkOrders.size() > 0) {
+            //鍒ゆ柇鏄惁鏈夋姤宸ユ暟鎹�
+            List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery()
+                    .in(ProductionProductMain::getWorkOrderId, productWorkOrders.stream().map(ProductWorkOrder::getId).collect(Collectors.toList())));
+            if (productionProductMains.size() > 0) {
+                throw new RuntimeException("鐢熶骇璁㈠崟宸茬粡寮�濮嬬敓浜�,涓嶈兘鍒犻櫎");
             }
-            // 鎵归噺鍒犻櫎processRouteItem
-            productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>()
-                    .in(ProductProcessRouteItem::getProductOrderId, ids));
-
-            // 鎵归噺鍒犻櫎productProcessRoute
-            productProcessRouteMapper.delete(new LambdaQueryWrapper<ProductProcessRoute>()
-                    .in(ProductProcessRoute::getProductOrderId, ids));
-
-            // 鎵归噺鍒犻櫎productOrder
-            productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>()
-                    .in(ProductOrder::getId, ids));
+            //鍒犻櫎宸ュ崟
+            productWorkOrderMapper.delete(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids));
         }
+        //鍒犻櫎宸ヨ壓璺嚎
+        productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>()
+                .in(ProductProcessRouteItem::getProductOrderId, ids));
+        productProcessRouteMapper.delete(new LambdaQueryWrapper<ProductProcessRoute>()
+                .in(ProductProcessRoute::getProductOrderId, ids));
+        //鍒犻櫎鐢熶骇璁㈠崟
+        productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>()
+                .in(ProductOrder::getId, ids));
         return true;
     }
 
@@ -267,4 +227,112 @@
     }
 
 
+    @Override
+    public int finishOrder(Long orderId) {
+        ProductOrder productOrder = new ProductOrder();
+        productOrder.setId(orderId);
+        productOrder.setIsEnd(true);
+        return productOrderMapper.updateById(productOrder);
+    }
+
+    @Override
+    public int cleanRecord(Long id, Map<String, Object> cleanRecord) {
+        ProductOrder productOrder = productOrderMapper.selectById(id);
+        if (productOrder == null) {
+            throw new BaseException("璁㈠崟涓嶅瓨鍦�");
+        }
+        productOrder.setCleanRecord(JSON.toJSONString(cleanRecord));
+        return productOrderMapper.updateById(productOrder);
+    }
+
+    @Override
+    public List<SelectOptionDTO<String>> getProductOrderBatchNo() {
+        List<ProductOrder> productOrders = productOrderMapper.selectList(null);
+        return productOrders.stream().map(productOrder -> new SelectOptionDTO<>(productOrder.getBatchNo(), productOrder.getBatchNo())).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<StockInventoryDto> getByBomId(Long bomId) {
+        List<ProductStructureDto> structureList = productStructureMapper.listBybomId(bomId);
+
+        if (CollectionUtils.isEmpty(structureList)) {
+            return Collections.emptyList();
+        }
+
+        Set<Long> allNodeIds = structureList.stream()
+                .map(ProductStructureDto::getId)
+                .collect(Collectors.toSet());
+
+        Set<Long> parentIds = structureList.stream()
+                .filter(node -> node.getParentId() != null && node.getParentId() != 0)
+                .map(ProductStructureDto::getParentId)
+                .collect(Collectors.toSet());
+
+        Set<Long> leafNodeIds = new HashSet<>(allNodeIds);
+        leafNodeIds.removeAll(parentIds);
+
+        //  鑾峰彇鍙跺瓙鑺傜偣鐨� productModelId
+        List<Long> productModelIds = structureList.stream()
+                .filter(node -> leafNodeIds.contains(node.getId()))
+                .map(ProductStructureDto::getProductModelId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+
+        if (productModelIds.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        return stockInventoryMapper.getStockInventory(productModelIds);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int drawMaterials(ProductOrderDto productOrderDto) {
+        if (productOrderDto == null || productOrderDto.getId() == null) {
+            throw new RuntimeException("鍙傛暟閿欒");
+        }
+
+        String jsonString = productOrderDto.getDrawMaterials();
+        if (StringUtils.isEmpty(jsonString)) {
+            throw new RuntimeException("棰嗘枡鏄庣粏涓嶈兘涓虹┖");
+        }
+
+        List<DrawMaterialDto> drawMaterialsList;
+        try {
+            drawMaterialsList = JSON.parseArray(jsonString, DrawMaterialDto.class);
+        } catch (Exception e) {
+            throw new RuntimeException("棰嗘枡鏄庣粏鏍煎紡閿欒");
+        }
+
+        if (CollectionUtils.isEmpty(drawMaterialsList)) {
+            throw new RuntimeException("棰嗘枡鏄庣粏涓嶈兘涓虹┖");
+        }
+
+        // 澶勭悊棰嗘枡锛堟墸鍑忓簱瀛橈級
+        try {
+            for (DrawMaterialDto drawMaterialDto : drawMaterialsList) {
+                if (drawMaterialDto.getProductModelId() == null) {
+                    throw new RuntimeException("浜у搧鍨嬪彿ID涓嶈兘涓虹┖");
+                }
+                stockUtils.substractStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), StockOutQualifiedRecordTypeEnum.DRAW_MATERIALS_STOCK_OUT.getCode(), productOrderDto.getId());
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("棰嗘枡澶辫触锛�" + e.getMessage());
+        }
+
+        // JSON瀛楃涓插瓨鍌�
+        String newJsonString = JSON.toJSONString(drawMaterialsList);
+        int update = productOrderMapper.update(null,
+                new LambdaUpdateWrapper<ProductOrder>()
+                        .eq(ProductOrder::getId, productOrderDto.getId())
+                        .set(ProductOrder::getDrawMaterials, newJsonString));
+
+        // 鏍¢獙鏇存柊缁撴灉
+        if (update == 0) {
+            throw new RuntimeException("鏇存柊璁㈠崟澶辫触");
+        }
+
+        return update;
+    }
 }

--
Gitblit v1.9.3