1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
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 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;
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.*;
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;
import org.jeecg.modules.dncFlow.vo.DispatchFileFlowTaskVo;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
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.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程序与电子图版签派
 * @Author: jeecg-boot
 * @Date:   2025-03-19
 * @Version: V1.0
 */
@Service("IDispatchFileService")
public class DispatchFileServiceImpl extends ServiceImpl<DispatchFileMapper, DispatchFile> implements IDispatchFileService, FlowCallBackServiceI {
 
    @Autowired
    @Lazy
    private IDocInfoService docInfoService;
    @Resource
    private FlowCommonService flowCommonService;
    @Resource
    private IFlowDefinitionService flowDefinitionService;
    @Autowired
    private IFlowTaskService flowTaskService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private IFlowMyBusinessService flowMyBusinessService;
    @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;    //工控网传输nc文件夹
    @Value("${fileHomePath}")
    private String fileHomePath;
 
    /**
     * 流程启动,保存对应的数据
     * @param dispatchFile
     * @return
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public Result<?> saveDispatchFile(DispatchFile dispatchFile){
        //校验参数
        checkParam(dispatchFile);
        //获取文件信息
        DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
        PermissionStreamNew permissionStreams = getPermissionStreams(dispatchFile);
        if (permissionStreams==null){
            return Result.error("用户没有权限");
        }
        dispatchFile.setAttributionType(dispatchFile.getAttributionType());
        dispatchFile.setAttributionId(dispatchFile.getAttributionId());
        dispatchFile.setDocClassCode(dispatchFile.getDocClassCode());
        super.save(dispatchFile);
        System.out.println("NC程序和电子样板审签流程:" + dispatchFile.getDocId());
        flowCommonService.initActBusiness(docInfo.getDocName()+"."+docInfo.getDocSuffix()+"文件进行审签",
                dispatchFile.getId(), "IDispatchFileService", "nc_dispatch_file", 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("nc_dispatch_file", variables);
        if (!result.isSuccess()) {
            super.removeById(dispatchFile.getId());
        }else {
            docInfo.setDocDispatchStatus(1);
            docInfoService.updateById(docInfo);
        }
        return result;
    }
 
    /**
     * 文件查询审签流程
     * @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 dispatchFileFlowTaskVo
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    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());
        }
    }
 
    // 辅助方法:获取下一任务的所有候选信息(处理人、候选用户、候选组)
    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) {
        // 实际业务中调用服务接口获取组成员
        return sysUserRoleService.getUserNameByRoleId(groupId);
    }
 
 
    /**
     * 审批操作
     * @param dispatchFileFlowTaskVo
     * @return
     */
    @Override
    @Transactional
    public Result<?> auditDispatchFile(DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
        try {
            // 参数校验
            if (!ValidateUtil.validateString(dispatchFileFlowTaskVo.getTaskId()) || !ValidateUtil.validateString(dispatchFileFlowTaskVo.getDataId())) {
                return Result.error(CommonCode.INVALID_PARAM.toString());
            }
            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            String userId = user.getId();
            dispatchFileFlowTaskVo.setAssignee(user.getUsername());
            if (!ValidateUtil.validateString(userId)) {
                return Result.error(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST.toString());
            }
 
            // 数据查询
            DispatchFile dispatchFile = this.getById(dispatchFileFlowTaskVo.getDataId());
            if (dispatchFile == null) {
                return Result.error(CommonCode.INVALID_PARAM.toString());
            }
            DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
            if (docInfo == null) {
                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);
 
            // 完成流程任务
            Result result = flowTaskService.complete(dispatchFileFlowTaskVo);
            if (result.isSuccess()) {
                // 更新状态
                updateStatus(dispatchFile, docInfo, dispatchFileFlowTaskVo);
                docInfoService.updateById(docInfo);
                this.updateById(dispatchFile);
            } else {
                return result;
            }
 
            return Result.OK("操作成功");
        } catch (Exception e) {
            return Result.error("操作失败:" + e.getMessage());
        }
    }
 
    /**
     * 批量审批操作
     * @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
     */
    public Result<?> queryDispatchFile(String id){
        DispatchFile dispatchFile=this.getById(id);
        if (dispatchFile==null){
            return Result.error("审签基本信息不存在");
        }
        DocInfoQueryRequest docInfoQueryRequest=new DocInfoQueryRequest();
        docInfoQueryRequest.setDocId(dispatchFile.getDocId());
        docInfoQueryRequest.setAttributionId(dispatchFile.getAttributionId());
        docInfoQueryRequest.setAttributionType(Integer.valueOf(dispatchFile.getAttributionType()));
        docInfoQueryRequest.setDocClassCode(dispatchFile.getDocClassCode());
        List<DocInfo> docInfoList = docInfoService.findList(docInfoQueryRequest);
        return Result.OK(docInfoList);
    }
    /**
     * 发起定型流程
     */
    @Override
    public Result<?> submitProccess(DispatchFile dispatchFile) {
        checkParam(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<>();
        variables.put("dataId", dispatchFile.getId());
        variables.put("organization", "导入文档默认启动流程");
        variables.put("comment", "导入文档默认启动流程");
        variables.put("proofreading",true);
        Result result= flowDefinitionService.startProcessInstanceByKey("process_rf27duhy", 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<>();
        values.put("dataId", dispatchFile.getId());
        values.put("organization", dispatchFile.getOrganization());
        values.put("assignee", userId);
        values.put("comment", dispatchFileFlowTaskVo.getComment());
        if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
            values.put("proofreadStatus", dispatchFileFlowTaskVo.getProofreadStatus());
        }
        if (dispatchFileFlowTaskVo.getRatify() != null) {
            values.put("ratify", dispatchFileFlowTaskVo.getRatify());
        }
        if (dispatchFileFlowTaskVo.getCut() != null) {
            values.put("cut", dispatchFileFlowTaskVo.getCut());
        }
        if (dispatchFileFlowTaskVo.getStereotype() != null) {
            values.put("stereotype", dispatchFileFlowTaskVo.getStereotype());
        }
        return values;
    }
 
    private void updateStatus(DispatchFile dispatchFile, DocInfo docInfo, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) throws IOException {
        if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
            switch (dispatchFileFlowTaskVo.getProofreadStatus()) {
                case "1":
                    // 直接定型
                    dispatchFile.setCurrentNode("5");
                    docInfo.setDocDispatchStatus(5);
                    break;
                case "2":
                    // 校对通过
                    dispatchFile.setCurrentNode("2");
                    docInfo.setDocDispatchStatus(2);
                    break;
                default:
                    // 校对不通过
                    dispatchFile.setCurrentNode("1");
                    docInfo.setDocDispatchStatus(1);
                    break;
            }
        }
        if (dispatchFileFlowTaskVo.getRatify() != null && dispatchFileFlowTaskVo.getRatify()) {
            dispatchFile.setCurrentNode("3");
            docInfo.setDocDispatchStatus(3);
        }
        if (dispatchFileFlowTaskVo.getCut() != null && dispatchFileFlowTaskVo.getCut()) {
            dispatchFile.setCurrentNode("4");
            docInfo.setDocDispatchStatus(4);
        }
        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. 执行文件操作,后缀为NC
            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);
        }
    }
 
    /**
     * 处理对应产品结构树、nc文件、刀具列表、程序加工确认表封装
     * @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) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
        if (!ValidateUtil.validateString(dispatchFile.getAttributionId()) || !ValidateUtil.validateString(dispatchFile.getDocId())
                || !ValidateUtil.validateString(dispatchFile.getFileId()) || !ValidateUtil.validateString(dispatchFile.getAttributionType())) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if (!ValidateUtil.validateString(userId)) {
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        }
        return true;
    }
 
    private PermissionStreamNew getPermissionStreams(DispatchFile dispatchFile) {
        PermissionStreamNew permissionStreamNew = permissionService.getPermissionStreams(dispatchFile);
        if (permissionStreamNew == null) {
            ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
        }
        return permissionStreamNew;
    }
 
    @Override
    public void afterFlowHandle(FlowMyBusiness business) {
        business.getTaskNameId();//接下来审批的节点
        business.getValues();//前端传进来的参数
        business.getActStatus();
    }
 
    @Override
    public Object getBusinessDataById(String dataId) {
        return this.getById(dataId);
    }
 
    @Override
    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
        return null;
    }
 
    @Override
    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
        //业务是否干预流程,业务干预,流程干预,指定人员进行处理
        return null;
    }
}