From f64ce002aac67c5b7068654ed6229ea02f87520d Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期三, 25 六月 2025 14:17:53 +0800
Subject: [PATCH] 同步工控网

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/DispatchFileServiceImpl.java |  447 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 356 insertions(+), 91 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 b768b7e..6709cea 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
@@ -1,13 +1,21 @@
 package org.jeecg.modules.dncFlow.service.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.google.common.collect.Lists;
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.shiro.SecurityUtils;
+import org.flowable.common.engine.api.FlowableException;
 import org.flowable.engine.TaskService;
+import org.flowable.identitylink.api.IdentityLink;
+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.mapper.DocInfoMapper;
@@ -16,7 +24,10 @@
 import org.jeecg.modules.dnc.response.CommonCode;
 import org.jeecg.modules.dnc.response.UcenterCode;
 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;
@@ -25,17 +36,28 @@
 import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
 import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
 import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
+import org.jeecg.modules.flowable.domain.vo.FlowHistoricalVo;
 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.util.HashMap;
-import java.util.List;
-import java.util.Map;
+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.*;
 
 /**
  * @Description: nc绋嬪簭涓庣數瀛愬浘鐗堢娲�
@@ -49,12 +71,6 @@
     @Autowired
     @Lazy
     private IDocInfoService docInfoService;
-    @Autowired
-    private IProcessStreamService processStreamService;
-    @Autowired
-    private IWorkStepService workStepService;
-    @Autowired
-    private IPermissionStreamNewService permissionStreamNewService;
     @Resource
     private FlowCommonService flowCommonService;
     @Resource
@@ -62,13 +78,33 @@
     @Autowired
     private IFlowTaskService flowTaskService;
     @Autowired
-    private IDeviceTypeService deviceTypeService;
-    @Autowired
     private TaskService taskService;
     @Autowired
     private IFlowMyBusinessService flowMyBusinessService;
     @Autowired
-    private DocInfoMapper docInfoMapper;
+    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
@@ -95,6 +131,7 @@
         Map<String, Object> variables = new HashMap<>();
         variables.put("dataId", dispatchFile.getId());
         variables.put("organization", "瀵煎叆鏂囨。榛樿鍚姩娴佺▼");
+        variables.put("comment", "瀵煎叆鏂囨。榛樿鍚姩娴佺▼");
         variables.put("proofreading",true);
         Result result= flowDefinitionService.startProcessInstanceByKey("nc_dispatch_file", variables);
         if (!result.isSuccess()) {
@@ -107,27 +144,140 @@
     }
 
     /**
+     * 鏂囦欢鏌ヨ瀹$娴佺▼
+     * @param attributionId,attributionType,docId
+     * @return
+     */
+    @Override
+    public Result<?> queryDispatchDocFile(String attributionId, String attributionType, String docId){
+        DispatchFile dispatchFile=super.getOne(new LambdaQueryWrapper<DispatchFile>()
+                .eq(DispatchFile::getAttributionId, attributionId).eq(DispatchFile::getAttributionType, attributionType)
+                .eq(DispatchFile::getDocId, docId));
+        if (dispatchFile==null){
+            return Result.error("鏈壘鍒板搴斿绛炬枃浠�");
+        }else {
+            FlowMyBusiness flowMyBusiness=flowMyBusinessService.selectByDataId(dispatchFile.getId());
+            if (flowMyBusiness==null){
+                return Result.error("鏈壘鍒板搴斿绛炬祦绋�");
+            }else {
+                List<FlowHistoricalVo> queryHisTaskByProcInstId=hisWorkTaskService.queryHisTaskByProcInstId(flowMyBusiness.getProcessInstanceId());
+                return Result.ok(queryHisTaskByProcInstId);
+            }
+        }
+    }
+
+    /**
      * 閲嶆柊鍚姩
-     * @param id
+     * @param dispatchFileFlowTaskVo
      */
     @Override
     @Transactional(rollbackFor = {Exception.class})
-    public Result<?> reStartDispatchFile(String id){
-        DispatchFile dispatchFile = this.getById(id);
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        if (!dispatchFile.getCreateBy().equals(user.getUsername())){
-            return Result.error("鎮ㄦ病鏈夋潈闄愰噸鏂板惎鍔�");
+    public Result<?> reStartDispatchFile(DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
+        try {
+            // 1. 鑾峰彇褰撳墠鐢ㄦ埛骞舵牎楠岀櫥褰曠姸鎬�
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            if (user == null) {
+                return Result.error("鐢ㄦ埛鏈櫥褰�");
+            }
+
+            // 2. 鏌ヨ娴佺▼涓氬姟璁板綍锛堝鐞嗙┖缁撴灉锛�
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("process_instance_id", dispatchFileFlowTaskVo.getInstanceId())
+            );
+            if (businessList.isEmpty()) {
+                return Result.error("娴佺▼璁板綍涓嶅瓨鍦�");
+            }
+            FlowMyBusiness flowMyBusiness = businessList.get(0);
+
+            // 3. 鏍¢獙鐢ㄦ埛鏄惁涓哄�欓�夊鐞嗕汉
+            List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
+            if (todoUsers == null || !todoUsers.contains(user.getUsername())) {
+                return Result.error("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�");
+            }
+
+            // 4. 璁ら浠诲姟锛堝鐞嗗凡琚棰嗙殑鎯呭喌锛�
+            String taskId = flowMyBusiness.getTaskId();
+            Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+            if (task == null) {
+                return Result.error("浠诲姟涓嶅瓨鍦ㄦ垨宸插畬鎴�");
+            }
+            if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
+                return Result.error("浠诲姟宸茶浠栦汉璁ら");
+            }
+            taskService.claim(taskId, user.getUsername());
+
+            // 5. 瀹屾垚浠诲姟骞朵紶閫掑彉閲�
+            Map<String, Object> variables = new HashMap<>();
+            variables.put("dataId", flowMyBusiness.getDataId());
+            variables.put("organization", dispatchFileFlowTaskVo.getComment());
+            variables.put("assignee", user.getUsername());
+            variables.put("comment", dispatchFileFlowTaskVo.getComment());
+            taskService.complete(taskId, variables);
+
+            // 6. 鑾峰彇涓嬩竴浠诲姟骞舵洿鏂颁笟鍔¤褰�
+            List<Task> nextTasks = taskService.createTaskQuery()
+                    .processInstanceId(dispatchFileFlowTaskVo.getInstanceId())
+                    .list();
+            if (!nextTasks.isEmpty()) {
+                Task nextTask = nextTasks.get(0); // 鍋囪鍙栫涓�涓换鍔�
+                flowMyBusiness.setTaskId(nextTask.getId());
+                flowMyBusiness.setTaskName(nextTask.getName());
+
+                // 鍔ㄦ�佽幏鍙栦笅涓�鑺傜偣鍊欓�変汉锛堢ず渚嬶級
+                List<String> nextTodoUsers = getNextTaskCandidates(nextTask.getId());
+                flowMyBusiness.setTodoUsers(JSON.toJSONString(nextTodoUsers));
+            } else {
+                // 娴佺▼宸茬粨鏉燂紝娓呯┖浠诲姟淇℃伅
+                flowMyBusiness.setTaskId(null);
+                flowMyBusiness.setTaskName(null);
+                flowMyBusiness.setTodoUsers(null);
+            }
+            flowMyBusinessService.updateById(flowMyBusiness);
+
+            return Result.ok("娴佺▼閲嶅惎鎴愬姛");
+        } catch (FlowableException e) {
+            return Result.error("娴佺▼鎿嶄綔澶辫触: " + e.getMessage());
+        } catch (Exception e) {
+            return Result.error("绯荤粺閿欒: " + e.getMessage());
         }
-        FlowMyBusiness flowMyBusiness=flowMyBusinessService.list(new QueryWrapper<FlowMyBusiness>()
-                .eq("data_id",dispatchFile.getId())).get(0);
-        String processInstanceId = flowMyBusiness.getProcessInstanceId();
-        Map<String, Object> variables = new HashMap<>();
-        variables.put("dataId", dispatchFile.getId());
-        variables.put("organization", "閲嶆柊鍚姩");
-        String TaskId=taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult().getId();
-        taskService.complete(TaskId, variables);
-        return Result.ok("閲嶆柊鍚姩鎴愬姛");
     }
+
+    // 杈呭姪鏂规硶锛氳幏鍙栦笅涓�浠诲姟鐨勬墍鏈夊�欓�変俊鎭紙澶勭悊浜恒�佸�欓�夌敤鎴枫�佸�欓�夌粍锛�
+    private List<String> getNextTaskCandidates(String taskId) {
+        List<IdentityLink> links = taskService.getIdentityLinksForTask(taskId);
+        List<String> candidates = new ArrayList<>();
+
+        // 1. 鑾峰彇鐩存帴澶勭悊浜猴紙assignee锛�
+        links.stream()
+                .filter(link -> "assignee".equals(link.getType()))
+                .map(IdentityLink::getUserId)
+                .filter(Objects::nonNull)
+                .forEach(candidates::add);
+
+        // 2. 鑾峰彇鍊欓�夌敤鎴峰拰鍊欓�夌粍
+        links.stream()
+                .filter(link -> "candidate".equals(link.getType()))
+                .forEach(link -> {
+                    if (link.getUserId() != null) {
+                        // 鍊欓�夌敤鎴风洿鎺ユ坊鍔�
+                        candidates.add(link.getUserId());
+                    } else if (link.getGroupId() != null) {
+                        // 鍊欓�夌粍杞崲涓哄疄闄呯敤鎴凤紙绀轰緥閫昏緫锛岄渶鏍规嵁涓氬姟瀹炵幇锛�
+                        List<String> groupUsers = convertGroupToUsers(link.getGroupId());
+                        candidates.addAll(groupUsers);
+                    }
+                });
+
+        return candidates;
+    }
+
+    // 绀轰緥鏂规硶锛氬皢鍊欓�夌粍ID杞崲涓虹敤鎴峰垪琛紙闇�鑷畾涔夊疄鐜帮級
+    private List<String> convertGroupToUsers(String groupId) {
+        // 瀹為檯涓氬姟涓皟鐢ㄦ湇鍔℃帴鍙h幏鍙栫粍鎴愬憳
+        return sysUserRoleService.getUserNameByRoleId(groupId);
+    }
+
 
     /**
      * 瀹℃壒鎿嶄綔
@@ -135,6 +285,7 @@
      * @return
      */
     @Override
+    @Transactional
     public Result<?> auditDispatchFile(DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
         try {
             // 鍙傛暟鏍¢獙
@@ -158,6 +309,33 @@
                 return Result.error(ActivitiCode.ACT_DOC_ERROR.toString());
             }
 
+            // 2. 鏌ヨ娴佺▼涓氬姟璁板綍锛堝鐞嗙┖缁撴灉锛�
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("process_instance_id", dispatchFileFlowTaskVo.getInstanceId())
+            );
+            if (businessList.isEmpty()) {
+                return Result.error("娴佺▼璁板綍涓嶅瓨鍦�");
+            }
+            FlowMyBusiness flowMyBusiness = businessList.get(0);
+
+            // 3. 鏍¢獙鐢ㄦ埛鏄惁涓哄�欓�夊鐞嗕汉
+            List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
+            if (todoUsers == null || !todoUsers.contains(user.getUsername())) {
+                return Result.error("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�");
+            }
+
+            // 4. 璁ら浠诲姟锛堝鐞嗗凡琚棰嗙殑鎯呭喌锛�
+            String taskId = flowMyBusiness.getTaskId();
+            Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+            if (task == null) {
+                return Result.error("浠诲姟涓嶅瓨鍦ㄦ垨宸插畬鎴�");
+            }
+            if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
+                return Result.error("浠诲姟宸茶浠栦汉璁ら");
+            }
+            taskService.claim(taskId, user.getUsername());
+
             // 璁剧疆娴佺▼鍙橀噺
             Map<String, Object> values = setProcessVariables(dispatchFile, userId, dispatchFileFlowTaskVo);
             dispatchFileFlowTaskVo.setValues(values);
@@ -180,6 +358,36 @@
     }
 
     /**
+     * 鎵归噺瀹℃壒鎿嶄綔
+     * @param dispatchFileFlowTaskVo
+     * @return
+     */
+    @Override
+    @Transactional
+    public Result<?> auditBatchDispatchFile(DispatchFileFlowTaskVo dispatchFileFlowTaskVo) throws InvocationTargetException, IllegalAccessException {
+        if (dispatchFileFlowTaskVo.getTaskIds()==null || dispatchFileFlowTaskVo.getTaskIds().isEmpty()) {
+            return Result.error(CommonCode.INVALID_PARAM.toString());
+        }
+        if (dispatchFileFlowTaskVo.getTaskIds().contains(",")){
+            String[] taskIds = dispatchFileFlowTaskVo.getTaskIds().split(",");
+            for (String taskId : taskIds) {
+                FlowMyBusiness flowMyBusiness=flowMyBusinessService.getOne(new QueryWrapper<FlowMyBusiness>().eq("task_id",taskId));
+                DispatchFileFlowTaskVo dispatchFileFlowTaskVoNew=new DispatchFileFlowTaskVo();
+                BeanUtils.copyProperties(dispatchFileFlowTaskVoNew, dispatchFileFlowTaskVo);
+                dispatchFileFlowTaskVoNew.setTaskId(taskId);
+                dispatchFileFlowTaskVoNew.setDataId(flowMyBusiness.getDataId());
+                dispatchFileFlowTaskVoNew.setInstanceId(flowMyBusiness.getProcessInstanceId());
+                if (dispatchFileFlowTaskVo.getTargetKey().equals("task_prepare")){
+                    reStartDispatchFile(dispatchFileFlowTaskVoNew);
+                }else {
+                    auditDispatchFile(dispatchFileFlowTaskVoNew);
+                }
+            }
+        }
+        return Result.OK("鎿嶄綔鎴愬姛");
+    }
+
+    /**
      * 鏌ヨ瀹$鍩烘湰淇℃伅
      * @param id
      */
@@ -196,6 +404,34 @@
         List<DocInfo> docInfoList = docInfoService.findList(docInfoQueryRequest);
         return Result.OK(docInfoList);
     }
+    /**
+     * 鍙戣捣瀹氬瀷娴佺▼
+     */
+    @Override
+    public Result<?> submitProccess(DispatchFile dispatchFile) {
+        checkParam(dispatchFile);
+        //鑾峰彇鏂囦欢淇℃伅
+        DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
+        if (docInfo.getDocDispatchStatus()==5){
+            return Result.error("瀹氬瀷宸查�氳繃,涓嶈兘閲嶅鎿嶄綔");
+        }
+        PermissionStreamNew permissionStreams = getPermissionStreams(dispatchFile);
+        if (permissionStreams==null){
+            return Result.error("鐢ㄦ埛娌℃湁鏉冮檺");
+        }
+        super.save(dispatchFile);
+        flowCommonService.initActBusiness(docInfo.getDocName()+"."+docInfo.getDocSuffix()+"鏂囦欢杩涜瀹氬瀷",
+                dispatchFile.getId(), "IDispatchFileService", "ncFileSettingProcessApproval", null);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("dataId", dispatchFile.getId());
+        variables.put("organization", "瀵煎叆鏂囨。榛樿鍚姩娴佺▼");
+        variables.put("comment", "瀵煎叆鏂囨。榛樿鍚姩娴佺▼");
+        variables.put("proofreading",true);
+        Result result= flowDefinitionService.startProcessInstanceByKey("ncFileSettingProcessApproval", variables);
+        if (!result.isSuccess())
+            super.removeById(dispatchFile.getId());
+        return result;
+    }
 
     private Map<String, Object> setProcessVariables(DispatchFile dispatchFile, String userId, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
         Map<String, Object> values = new HashMap<>();
@@ -203,7 +439,6 @@
         values.put("organization", dispatchFile.getOrganization());
         values.put("assignee", userId);
         values.put("comment", dispatchFileFlowTaskVo.getComment());
-
         if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
             values.put("proofreadStatus", dispatchFileFlowTaskVo.getProofreadStatus());
         }
@@ -219,7 +454,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":
@@ -250,8 +485,94 @@
         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) {
@@ -270,67 +591,12 @@
         return true;
     }
 
-    //鑾峰彇鏂囦欢淇℃伅
-    private DocInfo getDocInfo(DispatchFile dispatchFile) {
-        DocInfo docInfo = docInfoService.getByDocAttrAndDocId(dispatchFile.getDocId(),
-                Integer.parseInt(dispatchFile.getAttributionType()), dispatchFile.getAttributionId());
-        if (docInfo == null || docInfo.getDocStatus() == 3) {
-            ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
-        }
-        return docInfo;
-    }
-
-
     private PermissionStreamNew getPermissionStreams(DispatchFile dispatchFile) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        DeviceType deviceType = deviceTypeService.getById(dispatchFile.getAttributionId());
-        String attributionId = deviceType != null ? deviceType.getAttributionId() : dispatchFile.getAttributionId();
-
-        PermissionStreamNew permissionStreams;
-        if (dispatchFile.getAttributionType().equals("5")) {
-            // 宸ュ簭
-            permissionStreams = handleProcess(dispatchFile, attributionId, user);
-        } else {
-            // 宸ユ
-            permissionStreams = handleWorkStep(dispatchFile, attributionId, user);
-        }
-        if (permissionStreams == null) {
+        PermissionStreamNew permissionStreamNew = permissionService.getPermissionStreams(dispatchFile);
+        if (permissionStreamNew == null) {
             ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
         }
-        return permissionStreams;
-    }
-
-    private PermissionStreamNew handleProcess(DispatchFile dispatchFile, String attributionId, LoginUser user) {
-        ProcessStream processStream = processStreamService.getById(attributionId);
-        if (processStream == null) {
-            ExceptionCast.cast(CommonCode.INVALID_PARAM);
-        }
-        dispatchFile.setProductId(processStream.getProductId());
-        dispatchFile.setComponentId(processStream.getComponentId());
-        dispatchFile.setPartsId(processStream.getPartsId());
-        dispatchFile.setPsvId(processStream.getPsvId());
-        dispatchFile.setProcessId(processStream.getProcessId());
-        if (deviceTypeService.getById(dispatchFile.getAttributionId()) != null) {
-            dispatchFile.setDeviceTypeId(deviceTypeService.getById(dispatchFile.getAttributionId()).getId());
-        }
-        return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(), user.getId(), "5");
-    }
-
-    private PermissionStreamNew handleWorkStep(DispatchFile dispatchFile, String attributionId, LoginUser user) {
-        WorkStep workStep = workStepService.getById(attributionId);
-        if (workStep == null) {
-            ExceptionCast.cast(CommonCode.INVALID_PARAM);
-        }
-        dispatchFile.setProductId(workStep.getProductId());
-        dispatchFile.setComponentId(workStep.getComponentId());
-        dispatchFile.setPartsId(workStep.getPartsId());
-        dispatchFile.setPsvId(workStep.getPsvId());
-        dispatchFile.setProcessId(workStep.getProcessId());
-        dispatchFile.setStepId(workStep.getId());
-        if (deviceTypeService.getById(dispatchFile.getAttributionId()) != null) {
-            dispatchFile.setDeviceTypeId(deviceTypeService.getById(dispatchFile.getAttributionId()).getId());
-        }
-        return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(), user.getId(), "6");
+        return permissionStreamNew;
     }
 
     @Override
@@ -352,8 +618,7 @@
 
     @Override
     public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
-        String dataId = values.get("dataId").toString();
-        FlowMyBusiness flowMyBusiness=flowMyBusinessService.list(new QueryWrapper<FlowMyBusiness>().eq("data_id",dataId)).get(0);
-        return Lists.newArrayList(flowMyBusiness.getCreateBy());
+        //涓氬姟鏄惁骞查娴佺▼锛屼笟鍔″共棰勶紝娴佺▼骞查锛屾寚瀹氫汉鍛樿繘琛屽鐞�
+        return null;
     }
 }

--
Gitblit v1.9.3