From bc8cd378fd72f43e66120c540f57f630580aa093 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 11 九月 2025 10:57:13 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java |   80 ++++++++++++++++++++++------------------
 1 files changed, 44 insertions(+), 36 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java
index 85e3df8..27cce40 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/FileFerryService.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import liquibase.pro.packaged.S;
 import org.apache.commons.lang3.StringUtils;
+import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
 import org.jeecg.modules.dnc.dto.ComponentHierarchy;
 import org.jeecg.modules.dnc.dto.TransferPackage;
 import org.jeecg.modules.dnc.entity.*;
@@ -27,6 +28,7 @@
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
@@ -36,6 +38,7 @@
 import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 @Service
 public class FileFerryService {
@@ -51,7 +54,7 @@
     @Value("${jeecg.path.upload}")
     private String upLoadPath;
 
-    @Autowired
+    @Resource
     private MdcEquipmentMapper mdcEquipmentMapper;
 
     @Autowired
@@ -94,8 +97,6 @@
             throw new RuntimeException("鏂囦欢鍐欏叆澶辫触", e);
         }
     }
-
-
 
     public TransferPackage importData(String filePath) {
         try {
@@ -142,18 +143,28 @@
             long number = Long.parseLong(numericPart);
             number--;  // 鑾峰彇鍓嶄竴涓簭鍒楀彿
 
-            // 淇濇寔鐩稿悓浣嶆暟鏍煎紡
-            String newNumeric = String.format("%0" + numericPart.length() + "d", number);
-            String ncFileName = prefix + newNumeric + "_" + equipmentId+".NC";
-            String ncFilePath = path.getParent().resolve(ncFileName).toString();
-
             // 6. 鑾峰彇鏂囦欢澶嶅埗鐩爣璺緞
+            DocRelative docRelative=pkg.getDocRelative();
             DocFile docFile = pkg.getTraceChain().getDocFile();
             DocInfo docInfo = pkg.getTraceChain().getDocInfo();
             if (docFile == null) {
                 throw new IllegalStateException("浼犺緭鍖呬腑缂哄皯鏂囨。鏂囦欢淇℃伅");
             }
 
+            // 淇濇寔鐩稿悓浣嶆暟鏍煎紡
+            String newNumeric = String.format("%0" + numericPart.length() + "d", number);
+            String ncFileName = "";
+            if (Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode()) ||
+                    Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode())) {
+                //NC鏂囦欢鐨勬嫹璐�
+                ncFileName = prefix + newNumeric + "_" + equipmentId+".NC";
+            }else {
+                //鍏朵粬鏂囨。鐨勬嫹璐�
+                ncFileName = prefix + newNumeric + "_" + equipmentId+"."+docFile.getFileSuffix();
+                docInfo.setDocDispatchStatus(3);
+                pkg.getTraceChain().setDocInfo(docInfo);
+            }
+            String ncFilePath = path.getParent().resolve(ncFileName).toString();
             // 鏋勫缓鐩爣璺緞
             String targetDirectory = fileHomePath + docFile.getFilePath();
             String targetPath = Paths.get(targetDirectory, docFile.getFileEncodeName()).toString();
@@ -183,12 +194,12 @@
                     DocClassification classification = classificationService.getByCode("send");
                     if(classification == null)
                         ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
-                    DocRelative docRelative = new DocRelative();
-                    docRelative.setDocId(docInfo.getDocId());
-                    docRelative.setClassificationId(classification.getClassificationId());
-                    docRelative.setAttributionType(7);
-                    docRelative.setAttributionId(mdcEquipment.getId());
-                    docRelativeService.save(docRelative);
+                    DocRelative newDocRelative = new DocRelative();
+                    newDocRelative.setDocId(docInfo.getDocId());
+                    newDocRelative.setClassificationId(classification.getClassificationId());
+                    newDocRelative.setAttributionType(7);
+                    newDocRelative.setAttributionId(mdcEquipment.getId());
+                    docRelativeService.save(newDocRelative);
                 }
                 String sendPath = StringUtils.join(strings.toArray(), "/");
                 boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(), sendPath + "/" + mdcEquipment.getEquipmentId(),
@@ -203,37 +214,35 @@
             } else {
                 throw new RuntimeException("鏂囦欢浼犺緭璺緞鑾峰彇澶辫触");
             }
-
-            // 璁$畻鍚庝竴涓枃浠跺悕
-            long nextNumber = Long.parseLong(numericPart);
-            nextNumber++;
-
             //鑾峰彇搴忓垪鍖栫殑绋嬪簭纭琛ㄦ暟鎹�
             GuideCardBatch guideCardBatch=pkg.getTraceChain().getGuideCardBatch();
+            if (guideCardBatch!=null){
+                // 璁$畻鍚庝竴涓枃浠跺悕
+                long nextNumber = Long.parseLong(numericPart);
+                nextNumber++;
+                //鑾峰彇鏂囦欢璺緞
+                String pictureUrl=guideCardBatch.getPicture();
 
-            //鑾峰彇鏂囦欢璺緞
-            String pictureUrl=guideCardBatch.getPicture();
+                // 淇濇寔鐩稿悓浣嶆暟鏍煎紡
+                String nextNumeric = String.format("%0" + numericPart.length() + "d", nextNumber);
+                String nextFileName = prefix + nextNumeric + "_" + equipmentId+"."+pictureUrl.split("\\.")[1];
+                String nextFilePath = path.getParent().resolve(nextFileName).toString();
 
-            // 淇濇寔鐩稿悓浣嶆暟鏍煎紡
-            String nextNumeric = String.format("%0" + numericPart.length() + "d", nextNumber);
-            String nextFileName = prefix + nextNumeric + "_" + equipmentId+"."+pictureUrl.split("\\.")[1];
-            String nextFilePath = path.getParent().resolve(nextFileName).toString();
+                //鎷兼帴鐜版湁璺緞
+                String picturePtah=upLoadPath+"/"+pictureUrl;
 
-            //鎷兼帴鐜版湁璺緞
-            String picturePtah=upLoadPath+"/"+pictureUrl;
-
-            // 9. 澶嶅埗鏂囦欢骞堕噸鍛藉悕
-            logger.info("澶嶅埗鏂囦欢: {} 鈫� {}", nextFilePath,picturePtah);
-            Path PicSource= Paths.get(nextFilePath);
-            Files.copy(PicSource, Paths.get(picturePtah), StandardCopyOption.REPLACE_EXISTING);
+                // 9. 澶嶅埗鏂囦欢骞堕噸鍛藉悕
+                logger.info("澶嶅埗鏂囦欢: {} 鈫� {}", nextFilePath,picturePtah);
+                Path PicSource= Paths.get(nextFilePath);
+                Files.copy(PicSource, Paths.get(picturePtah), StandardCopyOption.REPLACE_EXISTING);
+                Files.delete(PicSource);
+            }
 
             // 鍒犻櫎鏂囦欢
             logger.info("鍒犻櫎涓存椂鏂囦欢: {}", ncFilePath);
             Files.delete(source);
             Files.delete(path);
-            Files.delete(PicSource);
-
-            return JsonUtils.fromJson(json, TransferPackage.class);
+            return pkg;
 
         } catch (NumberFormatException e) {
             throw new RuntimeException("鏂囦欢鍚嶄腑鐨勬暟瀛楁牸寮忔棤鏁�: " + e.getMessage(), e);
@@ -251,7 +260,6 @@
                 pkg.getTraceChain().getComponentHierarchy().getComponents().size() < 4) {
             return;
         }
-
         ComponentHierarchy hierarchy = pkg.getTraceChain().getComponentHierarchy();
         List<ComponentInfo> compressed = new ArrayList<>();
 

--
Gitblit v1.9.3