From ec7d3b867e7b7f5073dda1684a8720424b9da5ad Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 24 三月 2026 15:38:00 +0800
Subject: [PATCH] feat: 生产报工的详情、修改、删除接口

---
 src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java |  402 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 390 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java
index 58126be..0a0d5ff 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java
@@ -7,9 +7,7 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.dto.ProductionProductRouteItemDto;
-import com.ruoyi.production.dto.ProductionProductRouteItemParamDto;
-import com.ruoyi.production.dto.ProductionRecordDto;
+import com.ruoyi.production.dto.*;
 import com.ruoyi.production.enums.ProductOrderStatusEnum;
 import com.ruoyi.production.pojo.*;
 import com.ruoyi.production.service.*;
@@ -197,21 +195,21 @@
             throw new ServiceException("鎶ュ伐澶辫触,鐢熶骇璁㈠崟涓嶅瓨鍦�");
         }
 
-        //  褰撳墠鎶ュ伐鍚堟牸鏁伴噺
+        //  褰撳墠鎶ュ伐鍚堟牸鏁伴噺锛堝墠绔凡淇濊瘉 = 鎶曞叆鏁伴噺 - 涓嶅悎鏍兼暟閲忥紝鐩存帴浣跨敤锛�
         BigDecimal qualifiedQty = dto.getQualifiedQuantity() == null ? BigDecimal.ZERO : dto.getQualifiedQuantity();
-        //  宸插畬鎴愭暟閲�
+        //  璁㈠崟宸插畬鎴愭暟閲忥紙鍘嗗彶绱锛�
         BigDecimal completeQty = productOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
-        //  绱姞(鍙畻鍚堟牸)
-        BigDecimal newCompleteQty = completeQty.add(qualifiedQty);
-        productOrder.setCompleteQuantity(newCompleteQty);
         //  闇�姹傛暟閲�
         BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity();
-        // 鍓╀綑鍙姤宸ユ暟閲�
+        //  鍓╀綑鍙姤宸ユ暟閲�
         BigDecimal remainQty = totalQty.subtract(completeQty);
-        //  鏈鎶ュ伐涓嶈兘瓒呰繃鍓╀綑鏁伴噺
+        //  鏈鎶ュ伐鍚堟牸鏁伴噺涓嶈兘瓒呰繃鍓╀綑鏁伴噺锛堟牎楠屽繀椤诲湪绱姞鍓嶆墽琛岋級
         if (qualifiedQty.compareTo(remainQty) > 0) {
-            throw new ServiceException("鎶ュ伐澶辫触锛屾湰娆℃姤宸ユ暟閲忎笉鑳藉ぇ浜庡墿浣欏彲鎶ュ伐鏁伴噺");
+            throw new ServiceException("鎶ュ伐澶辫触锛屾湰娆℃姤宸ユ暟閲忎笉鑳藉ぇ浜庡墿浣欏彲鎶ュ伐鏁伴噺锛屽墿浣欐姤宸ユ暟閲�:[" + remainQty + "]");
         }
+        //  鍘嗗彶宸插畬鎴� + 鏈鍚堟牸鏁伴噺
+        BigDecimal newCompleteQty = completeQty.add(qualifiedQty);
+        productOrder.setCompleteQuantity(newCompleteQty);
         //  璁剧疆寮�濮嬫椂闂达紙绗竴娆℃姤宸ワ級
         if (productOrder.getStartTime() == null) {
             productOrder.setStartTime(LocalDateTime.now());
@@ -230,9 +228,11 @@
 
         //  瀹屾垚鎶ュ伐涓昏〃-鎶曞叆琛�-浜у嚭琛ㄦ暟鎹�
         ProductionProductMain productionProductMain = new ProductionProductMain();
-        productionProductMain.setProductNo("BG" + UUID.randomUUID());
+        productionProductMain.setProductNo(productionProductMainService.generateProductNo());
         productionProductMain.setProductOrderId(dto.getProductOrderId());
         productionProductMain.setSchedule(dto.getSchedule());
+        productionProductMain.setPostName(dto.getPostName());
+        productionProductMain.setReportingTime(LocalDateTime.now());
         boolean result = productionProductMainService.save(productionProductMain);
         if (!result) {
             throw new ServiceException("鎶ュ伐澶辫触,鏁版嵁瀛樺偍澶辫触");
@@ -276,6 +276,7 @@
                     ProductionProductRouteItemParam paramEntity = new ProductionProductRouteItemParam();
                     BeanUtils.copyProperties(productRouteItemParamDto, paramEntity, "id");
                     paramEntity.setProductionProductRouteItemId(productRouteItemEntity.getId());
+                    paramEntity.setOrderItemParamId(productRouteItemParamDto.getId());
                     if (paramEntity.getProductId() == null) {
                         ProductionOrderRouteItemParam productionOrderRouteItemParam = productionOrderRouteItemParamService.getById(productRouteItemParamDto.getId());
                         paramEntity.setParamName(productionOrderRouteItemParam.getParamName());
@@ -344,4 +345,381 @@
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteProductMain(Long productMainId) {
+        if (productMainId == null) {
+            throw new ServiceException("鍒犻櫎澶辫触锛屾姤宸D涓嶈兘涓虹┖");
+        }
+
+        //  鏍¢獙鎶ュ伐涓昏〃鏄惁瀛樺湪
+        ProductionProductMain productMain = productionProductMainService.getById(productMainId);
+        if (productMain == null) {
+            throw new ServiceException("鍒犻櫎澶辫触锛屾姤宸ヨ褰曚笉瀛樺湪");
+        }
+
+        //  鏌ヨ璇ユ姤宸ヤ笅鎵�鏈夊伐搴忚褰�
+        List<ProductionProductRouteItem> routeItemList = productionProductRouteItemService.list(new LambdaQueryWrapper<ProductionProductRouteItem>()
+                .eq(ProductionProductRouteItem::getProductMainId, productMainId));
+
+        if (routeItemList != null && !routeItemList.isEmpty()) {
+            List<Long> routeItemIds = routeItemList.stream()
+                    .map(ProductionProductRouteItem::getId)
+                    .collect(Collectors.toList());
+
+            //  鏌ヨ骞跺垹闄ゆ瘡涓伐搴忎笅鐨勯檮浠�
+            List<ProductionProductRouteItemFile> fileList = productionProductRouteItemFileService.list(new LambdaQueryWrapper<ProductionProductRouteItemFile>()
+                    .in(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItemIds));
+
+            if (fileList != null && !fileList.isEmpty()) {
+                for (ProductionProductRouteItemFile file : fileList) {
+                    if (StringUtils.hasText(file.getFileUrl())) {
+                        try {
+                            Files.deleteIfExists(Paths.get(file.getFileUrl()));
+                        } catch (IOException e) {
+                            log.warn("鍒犻櫎闄勪欢鏂囦欢澶辫触: {}", file.getFileUrl(), e);
+                        }
+                    }
+                }
+                productionProductRouteItemFileService.remove(new LambdaQueryWrapper<ProductionProductRouteItemFile>()
+                        .in(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItemIds));
+            }
+
+            //  鍒犻櫎宸ュ簭鍙傛暟
+            productionProductRouteItemParamService.remove(new LambdaQueryWrapper<ProductionProductRouteItemParam>()
+                    .in(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItemIds));
+
+            //  鍒犻櫎宸ュ簭璁板綍
+            productionProductRouteItemService.remove(new LambdaQueryWrapper<ProductionProductRouteItem>()
+                    .eq(ProductionProductRouteItem::getProductMainId, productMainId));
+        }
+
+        //  鍒犻櫎鎶曞叆琛�
+        productionProductInputService.remove(new LambdaQueryWrapper<ProductionProductInput>()
+                .eq(ProductionProductInput::getProductMainId, productMainId));
+
+        //  鍥炴粴鐢熶骇璁㈠崟瀹屾垚鏁伴噺
+        ProductionProductOutput output = productionProductOutputService.getOne(new LambdaQueryWrapper<ProductionProductOutput>()
+                .eq(ProductionProductOutput::getProductMainId, productMainId)
+                .last("LIMIT 1"));
+
+        ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId());
+        if (productOrder == null) {
+            throw new ServiceException("鍒犻櫎澶辫触锛屽叧鑱旂殑鐢熶骇璁㈠崟涓嶅瓨鍦�");
+        }
+
+        BigDecimal qualifiedQty = (output != null && output.getQuantity() != null)
+                ? output.getQuantity() : BigDecimal.ZERO;
+        BigDecimal currentCompleteQty = productOrder.getCompleteQuantity() == null
+                ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
+        BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity();
+
+        //  鎵e噺鏈潯鎶ュ伐璐$尞鐨勫悎鏍兼暟閲忥紝涓嶅厑璁稿嚭鐜拌礋鏁�
+        BigDecimal updatedCompleteQty = currentCompleteQty.subtract(qualifiedQty).max(BigDecimal.ZERO);
+        productOrder.setCompleteQuantity(updatedCompleteQty);
+
+        //  閲嶆柊鍒ゆ柇璁㈠崟鐘舵��
+        if (updatedCompleteQty.compareTo(totalQty) >= 0 && totalQty.compareTo(BigDecimal.ZERO) > 0) {
+            //  瀹屾垚鏁� >= 闇�姹傛暟 鈫� 宸插畬鎴�
+            productOrder.setStatus(ProductOrderStatusEnum.FINISHED.getCode());
+        } else if (updatedCompleteQty.compareTo(BigDecimal.ZERO) == 0) {
+            //  瀹屾垚鏁板綊闆� 鈫� 鍥炲埌寰呭紑濮嬶紝娓呯┖寮�濮�/缁撴潫鏃堕棿
+            productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
+            productOrder.setStartTime(null);
+            productOrder.setEndTime(null);
+        } else {
+            //  瀹屾垚鏁颁粙浜� 0 ~ 闇�姹傛暟涔嬮棿 鈫� 杩涜涓�
+            productOrder.setStatus(ProductOrderStatusEnum.RUNNING.getCode());
+            productOrder.setEndTime(null);
+        }
+        productOrderService.updateById(productOrder);
+
+        //  鍒犻櫎浜у嚭琛�
+        productionProductOutputService.remove(new LambdaQueryWrapper<ProductionProductOutput>()
+                .eq(ProductionProductOutput::getProductMainId, productMainId));
+
+        //  鍒犻櫎鎶ュ伐涓昏〃
+        productionProductMainService.removeById(productMainId);
+        log.info("鎶ュ伐璁板綍鍒犻櫎鎴愬姛锛宲roductMainId={}", productMainId);
+    }
+
+    @Override
+    public ProductionRecordDto detailProductMain(Long productMainId) {
+        if (productMainId == null) {
+            throw new ServiceException("鏌ヨ澶辫触锛屾姤宸D涓嶈兘涓虹┖");
+        }
+
+        //  鏌ヨ鎶ュ伐涓昏〃
+        ProductionProductMain productMain = productionProductMainService.getById(productMainId);
+        if (productMain == null) {
+            throw new ServiceException("鏌ヨ澶辫触锛屾姤宸ヨ褰曚笉瀛樺湪");
+        }
+
+        ProductionRecordDto dto = new ProductionRecordDto();
+        dto.setProductMainId(productMainId);
+        dto.setProductOrderId(productMain.getProductOrderId());
+        dto.setPostName(productMain.getPostName());
+        dto.setSchedule(productMain.getSchedule());
+        dto.setReportingTime(productMain.getReportingTime());
+        dto.setCreateTime(productMain.getCreateTime());
+        dto.setUpdateTime(productMain.getUpdateTime());
+
+        //  鐢熶骇璁㈠崟淇℃伅
+        ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId());
+        if (productOrder == null) {
+            throw new ServiceException("鏌ヨ澶辫触,鏈煡璇㈠埌鐢熶骇璁㈠崟淇℃伅");
+        }
+        dto.setNpsNo(productOrder.getNpsNo());
+
+        /// 浜у搧淇℃伅
+        ProductMaterialSkuDto productMaterialSkuDto = productMaterialService.selectProductByProductMainId(productOrder.getId());
+        dto.setProductName(productMaterialSkuDto.getProductName());
+        dto.setMaterialCode(productMaterialSkuDto.getMaterialCode());
+        dto.setModel(productMaterialSkuDto.getModel());
+
+        //  鏌ヨ鎶曞叆琛紙鑾峰彇浜у搧ID鍜屾姇鍏ユ暟閲忥級
+        ProductionProductInput input = productionProductInputService.getOne(
+                new LambdaQueryWrapper<ProductionProductInput>()
+                        .eq(ProductionProductInput::getProductMainId, productMainId)
+                        .last("LIMIT 1"));
+        if (input != null) {
+            dto.setProductId(input.getProductModelId());
+            dto.setQuantity(input.getQuantity());
+        }
+
+        //  鏌ヨ浜у嚭琛紙鑾峰彇鍚堟牸/涓嶅悎鏍兼暟閲忥級
+        ProductionProductOutput output = productionProductOutputService.getOne(
+                new LambdaQueryWrapper<ProductionProductOutput>()
+                        .eq(ProductionProductOutput::getProductMainId, productMainId)
+                        .last("LIMIT 1"));
+        if (output != null) {
+            dto.setQualifiedQuantity(output.getQuantity());
+            dto.setUnqualifiedQuantity(output.getScrapQty());
+        }
+
+        //  鏌ヨ宸ュ簭鍒楄〃
+        List<ProductionProductRouteItem> routeItemList = productionProductRouteItemService.list(
+                new LambdaQueryWrapper<ProductionProductRouteItem>()
+                        .eq(ProductionProductRouteItem::getProductMainId, productMainId));
+
+        if (routeItemList != null && !routeItemList.isEmpty()) {
+            List<ProductionProductRouteItemDto> routeItemDtoList = routeItemList.stream().map(routeItem -> {
+                ProductionProductRouteItemDto routeItemDto = new ProductionProductRouteItemDto();
+                BeanUtils.copyProperties(routeItem, routeItemDto);
+
+                //  鏌ヨ宸ュ簭鍙傛暟
+                List<ProductionProductRouteItemParam> paramList = productionProductRouteItemParamService.list(
+                        new LambdaQueryWrapper<ProductionProductRouteItemParam>()
+                                .eq(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItem.getId()));
+                if (paramList != null && !paramList.isEmpty()) {
+                    List<ProductionProductRouteItemParamDto> paramDtoList = paramList.stream().map(param -> {
+                        ProductionProductRouteItemParamDto paramDto = new ProductionProductRouteItemParamDto();
+                        BeanUtils.copyProperties(param, paramDto);
+                        if (paramDto.getProductId() != null) {
+                            ProductMaterialSkuDto materialSkuDto = productMaterialService.selectProductByModelId(paramDto.getProductId());
+                            productMaterialService.selectProductByModelId(paramDto.getProductId());
+                            paramDto.setParamName(materialSkuDto.getProductName());
+                        }
+                        return paramDto;
+                    }).collect(Collectors.toList());
+                    routeItemDto.setProductionProductRouteItemParamDtoList(paramDtoList);
+                }
+
+                //  鏌ヨ宸ュ簭闄勪欢
+                List<ProductionProductRouteItemFile> fileRecordList = productionProductRouteItemFileService.list(
+                        new LambdaQueryWrapper<ProductionProductRouteItemFile>()
+                                .eq(ProductionProductRouteItemFile::getProductionProductRouteItemId, routeItem.getId()));
+                if (fileRecordList != null && !fileRecordList.isEmpty()) {
+                    List<ProductionProductRouteItemFileDto> fileDtoList = fileRecordList.stream().map(file -> {
+                        ProductionProductRouteItemFileDto fileDto = new ProductionProductRouteItemFileDto();
+                        BeanUtils.copyProperties(file, fileDto);
+                        return fileDto;
+                    }).collect(Collectors.toList());
+                    routeItemDto.setFileList(fileDtoList);
+                }
+
+                return routeItemDto;
+            }).collect(Collectors.toList());
+
+            dto.setProductionProductRouteItemDtoList(routeItemDtoList);
+        }
+
+        return dto;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void editProductMain(ProductionRecordDto dto) {
+        if (dto == null || dto.getProductMainId() == null) {
+            throw new ServiceException("缂栬緫澶辫触锛屾姤宸D涓嶈兘涓虹┖");
+        }
+        if (dto.getProductId() == null) {
+            throw new ServiceException("缂栬緫澶辫触锛屼骇鍝佷俊鎭笉鑳戒负绌�");
+        }
+        if (StringUtils.isEmpty(dto.getPostName()) || StringUtils.isEmpty(dto.getSchedule())) {
+            throw new ServiceException("缂栬緫澶辫触锛屽矖浣嶄汉鍛�/鐝淇℃伅涓嶈兘涓虹┖");
+        }
+
+        Long productMainId = dto.getProductMainId();
+
+        //  鏌ヨ鎶ュ伐涓昏〃鏄惁瀛樺湪
+        ProductionProductMain productMain = productionProductMainService.getById(productMainId);
+        if (productMain == null) {
+            throw new ServiceException("缂栬緫澶辫触锛屾姤宸ヨ褰曚笉瀛樺湪");
+        }
+
+        //  鍥炴粴鐢熶骇璁㈠崟鐨勫悎鏍兼暟閲�
+        ProductionProductOutput oldOutput = productionProductOutputService.getOne(new LambdaQueryWrapper<ProductionProductOutput>()
+                .eq(ProductionProductOutput::getProductMainId, productMainId)
+                .last("LIMIT 1"));
+
+        ProductOrder productOrder = productOrderService.getById(productMain.getProductOrderId());
+        if (productOrder == null) {
+            throw new ServiceException("缂栬緫澶辫触锛屽叧鑱旂殑鐢熶骇璁㈠崟涓嶅瓨鍦�");
+        }
+
+        BigDecimal oldQualifiedQty = (oldOutput != null && oldOutput.getQuantity() != null)
+                ? oldOutput.getQuantity() : BigDecimal.ZERO;
+        BigDecimal newQualifiedQty = dto.getQualifiedQuantity() == null ? BigDecimal.ZERO : dto.getQualifiedQuantity();
+        BigDecimal currentCompleteQty = productOrder.getCompleteQuantity() == null
+                ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
+        BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity();
+
+        //  鍥炴粴鏃у�硷紝璁$畻鏈缂栬緫鍚庣殑鏂板畬鎴愭暟閲�
+        BigDecimal baseQty = currentCompleteQty.subtract(oldQualifiedQty);
+        BigDecimal updatedCompleteQty = baseQty.add(newQualifiedQty);
+
+        //  鏂扮殑鍚堟牸鏁伴噺涓嶈兘瓒呰繃锛堥渶姹傛暟閲� - 鎶ュ伐鎬诲畬鎴愭暟閲忥級
+        if (newQualifiedQty.compareTo(totalQty.subtract(baseQty)) > 0) {
+            throw new ServiceException("缂栬緫澶辫触锛屾湰娆℃姤宸ュ悎鏍兼暟閲忎笉鑳藉ぇ浜庡墿浣欏彲鎶ュ伐鏁伴噺");
+        }
+
+        //  閲嶆柊鍒ゆ柇鐢熶骇璁㈠崟鐘舵��
+        productOrder.setCompleteQuantity(updatedCompleteQty);
+        if (updatedCompleteQty.compareTo(totalQty) >= 0 && totalQty.compareTo(BigDecimal.ZERO) > 0) {
+            productOrder.setStatus(ProductOrderStatusEnum.FINISHED.getCode());
+            productOrder.setEndTime(LocalDateTime.now());
+        } else {
+            productOrder.setStatus(ProductOrderStatusEnum.RUNNING.getCode());
+            productOrder.setEndTime(null);
+        }
+        productOrderService.updateById(productOrder);
+
+        //  鏇存柊鎶ュ伐涓昏〃
+        productMain.setPostName(dto.getPostName());
+        productMain.setSchedule(dto.getSchedule());
+        productMain.setReportingTime(dto.getReportingTime());
+        productionProductMainService.updateById(productMain);
+
+        //  鏇存柊鎶曞叆琛�
+        ProductionProductInput input = productionProductInputService.getOne(new LambdaQueryWrapper<ProductionProductInput>()
+                .eq(ProductionProductInput::getProductMainId, productMainId)
+                .last("LIMIT 1"));
+        if (input != null) {
+            input.setProductModelId(dto.getProductId());
+            input.setQuantity(dto.getQuantity());
+            productionProductInputService.updateById(input);
+        }
+
+        //  鏇存柊浜у嚭琛�
+        if (oldOutput != null) {
+            oldOutput.setProductModelId(dto.getProductId());
+            oldOutput.setQuantity(dto.getQualifiedQuantity());
+            oldOutput.setScrapQty(dto.getUnqualifiedQuantity());
+            productionProductOutputService.updateById(oldOutput);
+        }
+
+        //  澶勭悊宸ュ簭鍒楄〃
+        List<ProductionProductRouteItemDto> routeItemDtoList = dto.getProductionProductRouteItemDtoList();
+        if (routeItemDtoList == null || routeItemDtoList.isEmpty()) {
+            throw new ServiceException("缂栬緫澶辫触锛屽伐搴忓弬鏁颁笉鑳戒负绌�");
+        }
+
+        for (ProductionProductRouteItemDto routeItemDto : routeItemDtoList) {
+            //  鏇存柊宸叉湁宸ュ簭
+            ProductionProductRouteItem routeItemEntity = productionProductRouteItemService.getById(routeItemDto.getId());
+            if (routeItemEntity == null) {
+                log.error("缂栬緫澶辫触,宸ュ簭璁板綍涓嶅瓨鍦�,ID={}", routeItemDto.getId());
+                throw new ServiceException("缂栬緫澶辫触锛屽伐搴忚褰曚笉瀛樺湪");
+            }
+            BeanUtils.copyProperties(routeItemDto, routeItemEntity, "id", "productMainId", "createTime", "tenantId");
+            productionProductRouteItemService.updateById(routeItemEntity);
+
+            final Long routeItemId = routeItemEntity.getId();
+
+            //  澶勭悊宸ュ簭鍙傛暟: 鍏堝垹闄よ宸ュ簭涓嬫墍鏈夋棫鍙傛暟锛屽啀閲嶆柊鎻掑叆浼犲叆鐨勫弬鏁�
+            productionProductRouteItemParamService.remove(new LambdaQueryWrapper<ProductionProductRouteItemParam>()
+                    .eq(ProductionProductRouteItemParam::getProductionProductRouteItemId, routeItemId));
+
+            List<ProductionProductRouteItemParamDto> paramDtoList = routeItemDto.getProductionProductRouteItemParamDtoList();
+                if (paramDtoList != null && !paramDtoList.isEmpty()) {
+                for (ProductionProductRouteItemParamDto paramDto : paramDtoList) {
+                    ProductionProductRouteItemParam paramEntity = new ProductionProductRouteItemParam();
+                    BeanUtils.copyProperties(paramDto, paramEntity, "id");
+                    paramEntity.setProductionProductRouteItemId(routeItemId);
+                    if (paramEntity.getProductId() == null && paramDto.getId() != null) {
+                        ProductionOrderRouteItemParam orderParam = productionOrderRouteItemParamService.getById(paramDto.getId());
+                        if (orderParam != null) {
+                            paramEntity.setOrderItemParamId(orderParam.getId());
+                            paramEntity.setParamName(orderParam.getParamName());
+                            paramEntity.setParamType(orderParam.getParamType());
+                            paramEntity.setParamFormat(orderParam.getParamFormat());
+                            paramEntity.setValueMode(orderParam.getValueMode());
+                        }
+                    }
+                    productionProductRouteItemParamService.save(paramEntity);
+                }
+            }
+
+            //  澶勭悊鏂颁笂浼犵殑涓存椂闄勪欢
+            List<String> newFiles = routeItemDto.getFiles();
+            if (newFiles != null && !newFiles.isEmpty()) {
+                for (String tempId : newFiles) {
+                    TempFile tempFile = tempFileMapper.selectById(tempId);
+                    if (tempFile == null) {
+                        log.warn("鏈壘鍒颁复鏃舵枃浠惰褰�: {}", tempId);
+                        continue;
+                    }
+                    try {
+                        String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
+                        Path formalDirPath = Paths.get(formalDir);
+                        if (!Files.exists(formalDirPath)) {
+                            Files.createDirectories(formalDirPath);
+                        }
+                        String originalFilename = tempFile.getOriginalName();
+                        String fileExtension = FilenameUtils.getExtension(originalFilename);
+                        String formalFilename = routeItemId + "_"
+                                + System.currentTimeMillis() + "_"
+                                + UUID.randomUUID().toString().substring(0, 8)
+                                + (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
+                        Path formalFilePath = formalDirPath.resolve(formalFilename);
+
+                        Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+                        Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
+
+                        ProductionProductRouteItemFile fileEntity = new ProductionProductRouteItemFile();
+                        fileEntity.setProductionProductRouteItemId(routeItemId);
+                        fileEntity.setFileName(originalFilename);
+                        fileEntity.setFileUrl(formalFilePath.toString());
+                        fileEntity.setFileSuffix(fileExtension);
+                        fileEntity.setFileSize(Files.size(formalFilePath));
+                        fileEntity.setCreateTime(LocalDateTime.now());
+                        fileEntity.setTenantId(SecurityUtils.getLoginUser().getTenantId());
+                        productionProductRouteItemFileService.save(fileEntity);
+
+                        tempFileMapper.deleteById(tempId);
+                        log.info("缂栬緫-宸ュ簭闄勪欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
+                    } catch (IOException e) {
+                        log.error("缂栬緫-宸ュ簭闄勪欢杩佺Щ澶辫触: {}", tempFile.getTempPath(), e);
+                        throw new ServiceException("宸ュ簭闄勪欢澶勭悊寮傚父: " + e.getMessage());
+                    }
+                }
+            }
+            List<Long> delFileIds = routeItemDto.getDelFileIds();
+            if (delFileIds != null && !delFileIds.isEmpty()) {
+                delFileIds.forEach(productionProductRouteItemFileService::deleteFile);
+            }
+        }
+        log.info("鎶ュ伐璁板綍缂栬緫鎴愬姛锛宲roductMainId={}", productMainId);
+    }
 }

--
Gitblit v1.9.3