From 4bac61c3fb3420caf48397d741f7f02c22f0fe08 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期一, 23 六月 2025 13:23:54 +0800
Subject: [PATCH] 工控网 新增设备结构树指派产品结构树功能 新增定型后续操作 增加解析涉密网传输解析,增加封装定型后nc文件与程序加工确认表

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java |  134 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 127 insertions(+), 7 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java
index 90326a7..a771833 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java
@@ -13,16 +13,21 @@
 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.entity.DocInfo;
-import org.jeecg.modules.dnc.entity.PermissionStreamNew;
+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.mapper.DocInfoMapper;
 import org.jeecg.modules.dnc.request.DocInfoQueryRequest;
 import org.jeecg.modules.dnc.response.ActivitiCode;
 import org.jeecg.modules.dnc.response.CommonCode;
 import org.jeecg.modules.dnc.response.UcenterCode;
-import org.jeecg.modules.dnc.service.IDocInfoService;
+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;
 import org.jeecg.modules.dncFlow.entity.DispatchFile;
 import org.jeecg.modules.dncFlow.mapper.DispatchFileMapper;
 import org.jeecg.modules.dncFlow.service.IDispatchFileService;
@@ -35,14 +40,23 @@
 import org.jeecg.modules.flowable.service.IFlowDefinitionService;
 import org.jeecg.modules.flowable.service.IFlowTaskService;
 import org.jeecg.modules.flowable.service.IHisWorkTaskService;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.jeecg.modules.system.service.ISysUserRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.*;
 
 /**
@@ -68,13 +82,29 @@
     @Autowired
     private IFlowMyBusinessService flowMyBusinessService;
     @Autowired
-    private DocInfoMapper docInfoMapper;
-    @Autowired
     private ISysUserRoleService sysUserRoleService;
     @Autowired
     private PermissionService permissionService;
     @Autowired
     private IHisWorkTaskService hisWorkTaskService;
+    @Autowired
+    private IDeviceTypeService deviceTypeService;
+    @Autowired
+    private IDeviceManagementService deviceManagementService;
+    @Autowired
+    private IDncPassLogService dncPassLogService;
+    @Autowired
+    private IDocFileService docFileService;
+    @Autowired
+    private IDocRelativeService docRelativeService;
+    @Autowired
+    @Lazy
+    private FileFerryService ferryService;
+    @Value("${deploy.secretFolder}")
+    private String secretFolder;    //宸ユ帶缃戜紶杈搉c鏂囦欢澶�
+    @Value("${fileHomePath}")
+    private String fileHomePath;
+
     /**
      * 娴佺▼鍚姩,淇濆瓨瀵瑰簲鐨勬暟鎹�
      * @param dispatchFile
@@ -380,9 +410,13 @@
     @Override
     public Result<?> submitProccess(DispatchFile dispatchFile) {
         checkParam(dispatchFile);
-        super.save(dispatchFile);
         //鑾峰彇鏂囦欢淇℃伅
         DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
+        PermissionStreamNew permissionStreams = getPermissionStreams(dispatchFile);
+        if (permissionStreams==null){
+            return Result.error("鐢ㄦ埛娌℃湁鏉冮檺");
+        }
+        super.save(dispatchFile);
         flowCommonService.initActBusiness(docInfo.getDocName()+"."+docInfo.getDocSuffix()+"鏂囦欢杩涜瀹氬瀷",
                 dispatchFile.getId(), "IDispatchFileService", "process_rf27duhy", null);
         Map<String, Object> variables = new HashMap<>();
@@ -417,7 +451,7 @@
         return values;
     }
 
-    private void updateStatus(DispatchFile dispatchFile, DocInfo docInfo, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
+    private void updateStatus(DispatchFile dispatchFile, DocInfo docInfo, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) throws IOException {
         if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
             switch (dispatchFileFlowTaskVo.getProofreadStatus()) {
                 case "1":
@@ -448,9 +482,95 @@
         if (dispatchFileFlowTaskVo.getStereotype() != null && dispatchFileFlowTaskVo.getStereotype()) {
             dispatchFile.setCurrentNode("5");
             docInfo.setDocDispatchStatus(5);
+            //瀹氬瀷閫氳繃
+            DeviceType deviceType=deviceTypeService.getById(dispatchFile.getDeviceTypeId());
+            DeviceManagement deviceManagement=deviceManagementService.getById(deviceType.getDeviceManagementId());
+            DocFile docFile=docFileService.getById(dispatchFile.getFileId());
+            DocRelative docRelative=docRelativeService.getOne(new QueryWrapper<DocRelative>().eq("doc_id",docInfo.getDocId())
+                    .eq("attribution_id",dispatchFile.getAttributionId()).eq("attribution_type",dispatchFile.getAttributionType()));
+            handleFileProcessing(docFile,deviceManagement,secretFolder);
+            handleProductTree(docInfo,docRelative,deviceManagement);
         }
     }
 
+
+    //灏佽澶勭悊鏂囦欢
+    private void handleFileProcessing(DocFile docFile, DeviceManagement deviceManagement, String secretFolder) throws IOException {
+        if (!docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) {
+            DncPassLog passInfoTxt = new DncPassLog();
+            Date dateFirst = DateUtil.getNow();
+            passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
+            /*鏌ヨ鏈�鍚庝竴鏉¤褰�*/
+            //浼戠湢 500姣
+            DncPassLog dncPassLog  = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
+            int fileNc =0;
+            if (dncPassLog !=null) {
+                fileNc = dncPassLog.getSequenceNumber() + 1;
+            } else {
+                fileNc =  1;
+            }
+            //澶勭悊鏂囦欢鍚嶇О  鏂囦欢璺緞
+            String sequenceNc = String.format("%06d",fileNc);
+            DncPassLog passInfoNc = new DncPassLog();
+            passInfoNc.setSequenceNumber(fileNc);
+            passInfoNc.setSequenceOrder(sequenceNc);
+            passInfoNc.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
+            passInfoNc.setPassType(DncPassLogPassType.NCFILE.getCode());
+            passInfoNc.setPassName(docFile.getFileName());
+            try {
+                Thread.sleep(1000);
+                Date date = new Date();
+                passInfoNc.setCreateTime(date);
+                System.out.println(DateUtil.format(date,DateUtil.STR_DATE_TIME));
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            dncPassLogService.save(passInfoNc);
+            // 4. 鎵ц鏂囦欢鎿嶄綔,鍚庣紑涓篘C
+            Path source = Paths.get(fileHomePath+docFile.getFilePath(), docFile.getFileEncodeName());
+            String destFileName = "10A" + DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc + "_" + deviceManagement.getDeviceManagementCode()+".NC";
+            Path destination = Paths.get(secretFolder, destFileName);
+            Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
+        }
+    }
+
+    /**
+     * 澶勭悊瀵瑰簲浜у搧缁撴瀯鏍戙�乶c鏂囦欢銆佸垁鍏峰垪琛ㄣ�佺▼搴忓姞宸ョ‘璁よ〃灏佽
+     * @param docInfo
+     */
+    private void handleProductTree(DocInfo docInfo, DocRelative docRelative, DeviceManagement deviceManagement) {
+        /*鏌ヨ鏈�鍚庝竴鏉¤褰�*/
+        //浼戠湢 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+"_"+deviceManagement.getDeviceManagementCode()+".ferry");
+            System.out.println("宸ュ簭鏁版嵁宸插鍑�: " + filePath);
+        }else {
+            //宸ユ瀵瑰簲璁惧绫�
+            String filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+deviceManagement.getDeviceManagementCode()+".ferry");
+            System.out.println("宸ユ鏁版嵁宸插鍑�: " + filePath);
+        }
+    }
+
+
     //浼犲弬楠岃瘉
     public boolean checkParam(DispatchFile dispatchFile) {
         if (dispatchFile == null) {

--
Gitblit v1.9.3