From 24e0bdd24a10449c98013cdb5bcc5e37735f5a91 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期一, 16 六月 2025 09:04:01 +0800
Subject: [PATCH] 对接刀具系统,涉密网封装结构树与文件

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java |  143 ++++++++++++++++++++++++++---------------------
 1 files changed, 78 insertions(+), 65 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java
index 70ab35e..036ac42 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java
@@ -16,11 +16,14 @@
 import org.flowable.task.api.Task;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.dnc.constant.DncPassLogPassType;
+import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
+import org.jeecg.modules.dnc.dto.TransferPackage;
 import org.jeecg.modules.dnc.entity.*;
 import org.jeecg.modules.dnc.exception.ExceptionCast;
-import org.jeecg.modules.dnc.ext.NcTxtFilePathInfo;
 import org.jeecg.modules.dnc.response.*;
 import org.jeecg.modules.dnc.service.*;
+import org.jeecg.modules.dnc.service.impl.FileFerryService;
 import org.jeecg.modules.dnc.utils.ValidateUtil;
 import org.jeecg.modules.dnc.utils.date.DateUtil;
 import org.jeecg.modules.dnc.utils.file.FileUtilS;
@@ -42,7 +45,6 @@
 import org.jeecg.modules.flowable.service.IFlowTaskService;
 import org.jeecg.modules.mdc.entity.MdcEquipment;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
-import org.jeecg.modules.message.enums.DeployEnum;
 import org.jeecg.modules.system.service.IMdcProductionService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,23 +53,17 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service("IAssignFileStreamService")
 public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService , FlowCallBackServiceI {
     private static final String PROCESS_KEY = "assign_nc_to_device";
-    private static final String APPLY_VARIABLE = "apply_user";
-    private static final String APPROVE_VARIABLE = "approve_users";
     private static final String SEND_CODE = "SEND";
-
     @Value("${flowable.enable}")
     private Boolean flowableEnable;
-
+    @Value("${fileHomePath}")
+    private String fileHomePath;
     @Autowired
     private IDocInfoService docInfoService;
     @Autowired
@@ -98,11 +94,10 @@
     private PermissionService permissionService;
     @Autowired
     private IDncPassLogService dncPassLogService;
-    @Value("${deploy.deployType}")
-    private String deployType;    //宸ユ帶缃�/娑夊瘑缃戦儴缃� 0涓哄伐鎺х綉 1涓烘秹瀵嗙綉
     @Value("${deploy.secretFolder}")
     private String secretFolder;    //娑夊瘑缃戜紶杈搉c鏂囦欢澶�
-
+    @Autowired
+    private FileFerryService ferryService;
     @Override
     @Transactional(rollbackFor = {Exception.class})
     public Result applyAssignFile(AssignFileStream stream) {
@@ -253,11 +248,19 @@
             }
 
         }
-        handleFileTransfer(mdcEquipment, docFile);
-        //娉ㄦ剰----鍖哄垎宸ユ帶缃戜笌娑夊瘑缃戯紒锛侊紒  娑夊瘑缃戣繘琛孨C鏂囦欢鐨勬嫹璐濓紝宸ユ帶缃戣礋璐h繘琛岃В鏋怤C鏂囦欢
-        if (deployType.equals(DeployEnum.SMW.getCode())) {
-            handleFileProcessing(docFile, mdcEquipment, secretFolder);
+        List<DocRelative> docRelativeList=docRelativeService.
+                list(new QueryWrapper<DocRelative>()
+                        .eq("attribution_type",stream.getAttributionType())
+                        .eq("attribution_id",stream.getAttributionId())
+                        .eq("doc_id",stream.getDocId()));
+        if (docRelativeList.isEmpty()){
+            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
         }
+        handleFileTransfer(mdcEquipment, docFile);
+        //NC鏂囦欢鐨勬嫹璐�
+        handleFileProcessing(docFile, mdcEquipment, secretFolder);
+        //瀵瑰簲浜у搧缁撴瀯鏍戞嫹璐�
+        handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
         synchronizedFlagService.updateFlag(2);
         return Result.OK("鎿嶄綔鎴愬姛");
     }
@@ -383,10 +386,20 @@
                     }
                 }
             }
-            //娉ㄦ剰----鍖哄垎宸ユ帶缃戜笌娑夊瘑缃戯紒锛侊紒  娑夊瘑缃戣繘琛孨C鏂囦欢鐨勬嫹璐濓紝宸ユ帶缃戣礋璐h繘琛岃В鏋怤C鏂囦欢
-            if (deployType.equals(DeployEnum.SMW.getCode())) {
-                handleFileProcessing(docFile, mdcEquipment, secretFolder);
+            List<DocRelative> docRelativeList=docRelativeService.
+                    list(new QueryWrapper<DocRelative>()
+                            .eq("attribution_type",en.getAttributionType())
+                            .eq("attribution_id",en.getAttributionId())
+                            .eq("doc_id",en.getDocId()));
+            if (docRelativeList.isEmpty()){
+                ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
             }
+            //娑夊瘑缃戣繘琛孨C鏂囦欢鐨勬嫹璐�
+            handleFileTransfer(mdcEquipment, docFile);
+            //NC鏂囦欢鐨勬嫹璐�
+            handleFileProcessing(docFile, mdcEquipment, secretFolder);
+            //瀵瑰簲浜у搧缁撴瀯鏍戞嫹璐�
+            handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
             return synchronizedFlagService.updateFlag(1);
         }else if(up.getStatus() == 3) {
             //鎷掔粷鎿嶄綔 浠�涔堜篃涓嶅仛
@@ -579,7 +592,8 @@
     }
 
     //鎻掑叆鏂囦欢浼犺緭浠诲姟琛�
-    private void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) {
+    @Override
+    public void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) {
         List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
         if (strings != null && !strings.isEmpty()) {
             String path = StringUtils.join(strings.toArray(), "/");
@@ -600,7 +614,6 @@
     //灏佽澶勭悊鏂囦欢
     private void handleFileProcessing(DocFile docFile, MdcEquipment mdcEquipment, String secretFolder) {
         if (!docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) {
-            String size = FileUtilS.fileSizeNC(docFile.getFilePath(), docFile.getFileEncodeName());
             List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
             if (strings != null && !strings.isEmpty()) {
                 DncPassLog passInfoTxt = new DncPassLog();
@@ -611,23 +624,14 @@
                 /*鏌ヨ鏈�鍚庝竴鏉¤褰�*/
                 //浼戠湢 500姣
                 DncPassLog dncPassLog  = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
-                int fileTxt = 0, fileNc =0;
+                int fileNc =0;
                 if (dncPassLog !=null) {
-                    fileTxt = dncPassLog.getSequenceNumber() + 1;
+                    fileNc = dncPassLog.getSequenceNumber() + 1;
                 } else {
-                    fileTxt =  1;
+                    fileNc =  1;
                 }
-                fileNc = fileTxt + 1;
                 //澶勭悊鏂囦欢鍚嶇О  鏂囦欢璺緞
-                String sequence = String.format("%06d",fileTxt);
                 String sequenceNc = String.format("%06d",fileNc);
-                passInfoTxt.setSequenceNumber(fileTxt);
-                passInfoTxt.setSequenceOrder(sequence);
-                passInfoTxt.setCreateTime(dateFirst);
-                System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME));
-                passInfoTxt.setPassType("02");
-                dncPassLogService.save(passInfoTxt);
-
                 DncPassLog passInfoNc = new DncPassLog();
                 passInfoNc.setSequenceNumber(fileNc);
                 passInfoNc.setSequenceOrder(sequenceNc);
@@ -642,41 +646,50 @@
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
-
                 dncPassLogService.save(passInfoNc);
-                NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
-                ncTxt.setEquipmentId(mdcEquipment.getEquipmentId());
-                ncTxt.setFileNcName("10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc);
-                ncTxt.setFileTxtName("10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequence);
-                ncTxt.setFilePath(path + "/" + mdcEquipment.getEquipmentId() + "/");
-                ncTxt.setOrigFileName(docFile.getFileName());
-                ncTxt.setOrigFileSuffix(docFile.getFileSuffix());
-                ncTxt.setFileAddOrDelete(1);
-                String loFilePath = secretFolder +"/"+ ncTxt.getFileTxtName() + ".nc";
-                try {
-                    String allList = ncTxt.getFileTxtName() + "\n"
-                            + ncTxt.getFileNcName() + "\n"
-                            + ncTxt.getOrigFileName() + "\n"
-                            + ncTxt.getOrigFileSuffix() + "\n"
-                            + ncTxt.getFilePath() + "\n"
-                            + ncTxt.getEquipmentId() + "\n"
-                            + ncTxt.getFileAddOrDelete().toString() + "\n"
-                            + size + "\n";
-                    FileUtilS.fileWriterSql(loFilePath, allList);
-                    boolean copyFileNc = FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" +
-                                    docFile.getFileName(),
-                            secretFolder +"/"+ncTxt.getFileNcName(),
-                            docFile.getFileSuffix(), "NC");
-                    if (!copyFileNc) {
-                        FileUtilS.deleteNcFile(loFilePath);
-                    }
-                } catch (IOException e) {
-                    throw new RuntimeException("鏂囦欢澶勭悊澶辫触", e);
-                }
+                FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" +
+                                docFile.getFileName(),
+                        secretFolder +"/"+"10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc+"_"+mdcEquipment.getEquipmentId(),
+                        docFile.getFileSuffix(), "NC");
             }
         }
     }
 
+    /**
+     * 澶勭悊瀵瑰簲浜у搧缁撴瀯鏍戙�乶c鏂囦欢銆佸垁鍏峰垪琛ㄣ�佺▼搴忓姞宸ョ‘璁よ〃灏佽
+     * @param docInfo
+     */
+    private void handleProductTree(DocInfo docInfo,DocRelative docRelative,String equipmentId) {
+        /*鏌ヨ鏈�鍚庝竴鏉¤褰�*/
+        //浼戠湢 500姣
+        DncPassLog passInfoTxt = new DncPassLog();
+        Date dateFirst = DateUtil.getNow();
+        passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
+        DncPassLog dncPassLog  = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
+        int fileTxt = 0, fileNc =0;
+        if (dncPassLog !=null) {
+            fileTxt = dncPassLog.getSequenceNumber() + 1;
+        } else {
+            fileTxt =  1;
+        }
+        String sequence = String.format("%06d",fileTxt);
+        passInfoTxt.setSequenceNumber(fileTxt);
+        passInfoTxt.setCreateTime(dateFirst);
+        passInfoTxt.setSequenceOrder(sequence);
+        System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME));
+        passInfoTxt.setPassType(DncPassLogPassType.PRODUCTSTRUCTURE.getCode());
+        dncPassLogService.save(passInfoTxt);
+        String fileName="10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY);
+        if (Objects.equals(docInfo.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode())){
+            //宸ュ簭瀵瑰簲璁惧绫�
+            String filePath = ferryService.exportData(TransferPackage.DataType.PROCESS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
+            System.out.println("宸ュ簭鏁版嵁宸插鍑�: " + filePath);
+        }else {
+            //宸ユ瀵瑰簲璁惧绫�
+            String filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
+            System.out.println("宸ユ鏁版嵁宸插鍑�: " + filePath);
+        }
+    }
     @Override
     public void afterFlowHandle(FlowMyBusiness business) {
         business.getTaskNameId();//鎺ヤ笅鏉ュ鎵圭殑鑺傜偣

--
Gitblit v1.9.3