ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
package jnpf.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.StrPool;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import feign.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jnpf.base.ActionResult;
import jnpf.base.Page;
import jnpf.base.UserInfo;
import jnpf.base.controller.SuperController;
import jnpf.base.entity.SuperBaseEntity;
import jnpf.base.vo.DownloadVO;
import jnpf.base.vo.ListVO;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.FileTypeConstant;
import jnpf.constant.MsgCode;
import jnpf.entity.DocumentEntity;
import jnpf.entity.DocumentLogEntity;
import jnpf.entity.DocumentShareEntity;
import jnpf.exception.DataException;
import jnpf.file.DocumentApi;
import jnpf.file.FileApi;
import jnpf.file.FileUploadApi;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import jnpf.flowable.model.task.FileModel;
import jnpf.model.MergeChunkDto;
import jnpf.model.UploaderVO;
import jnpf.model.document.*;
import jnpf.model.upload.UploadFileModel;
import jnpf.permission.UserApi;
import jnpf.permission.entity.UserEntity;
import jnpf.service.DocumentLogService;
import jnpf.service.DocumentService;
import jnpf.service.FileService;
import jnpf.util.*;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 文档管理
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2019年9月26日 上午9:18
 */
@Slf4j
@Tag(name = "知识管理", description = "Document")
@RestController
@RequestMapping("/Document")
public class DocumentController extends SuperController<DocumentService, DocumentEntity> implements DocumentApi {
 
    @Autowired
    private DocumentService documentService;
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private UserApi userService;
 
    @Autowired
    private DocumentLogService documentLogService;
    @Autowired
    private WorkFlowApi workFlowApi;
    @Autowired
    private FileApi fileApi;
    @Autowired
    private FileUploadApi fileUploadApi;
    @Autowired
    private FileService fileService;
 
    /**
     * 列表
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "列表")
    @GetMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<DocumentInfoVO> info(@PathVariable("id") String id) throws DataException {
        DocumentEntity entity = documentService.getInfo(id);
        if (!Objects.equals(entity.getCreatorUserId(), UserProvider.getLoginUserId())) {
            return ActionResult.fail(MsgCode.AD104.get());
        }
        DocumentInfoVO vo = JsonUtil.getJsonToBean(entity, DocumentInfoVO.class);
        //截取后缀
        if (Objects.equals(vo.getType(), 1) && vo.getFullName().contains(".")) {
            vo.setFullName(vo.getFullName().substring(0, vo.getFullName().lastIndexOf(".")));
        }
        return ActionResult.success(vo);
    }
 
    /**
     * 新建
     *
     * @param documentCrForm 新建模型
     * @return
     */
    @Operation(summary = "新建")
    @PostMapping
    @Parameters({
            @Parameter(name = "documentCrForm", description = "知识模型", required = true),
    })
    public ActionResult create(@RequestBody @Valid DocumentCrForm documentCrForm) {
        DocumentEntity entity = JsonUtil.getJsonToBean(documentCrForm, DocumentEntity.class);
        if (documentService.isExistByFullName(documentCrForm.getFullName(), entity.getId(), documentCrForm.getParentId())) {
            return ActionResult.fail(MsgCode.EXIST004.get());
        }
        entity.setEnabledMark(1);
        documentService.create(entity);
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    /**
     * 修改
     *
     * @param id             主键
     * @param documentUpForm 修改模型
     * @return
     */
    @Operation(summary = "修改")
    @PutMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "documentUpForm", description = "知识模型", required = true),
    })
    public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DocumentUpForm documentUpForm) {
        DocumentEntity entity = JsonUtil.getJsonToBean(documentUpForm, DocumentEntity.class);
        if (documentService.isExistByFullName(documentUpForm.getFullName(), id, documentUpForm.getParentId())) {
            return ActionResult.fail(MsgCode.EXIST004.get());
        }
        DocumentEntity info = documentService.getInfo(id);
        //获取后缀名
        if (Objects.equals(info.getType(), 1) && StringUtil.isNotEmpty(info.getFileExtension())) {
            entity.setFullName(entity.getFullName() + StrPool.DOT + info.getFileExtension());
        }
        if (!Objects.equals(info.getCreatorUserId(), UserProvider.getLoginUserId())) {
            return ActionResult.fail(MsgCode.AD104.get());
        }
        boolean flag = documentService.update(id, entity);
        if (flag == false) {
            return ActionResult.fail(MsgCode.FA002.get());
        }
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 删除
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult delete(@PathVariable("id") String id) {
        DocumentEntity entity = documentService.getInfo(id);
        if (entity != null) {
            List<DocumentEntity> allList = documentService.getAllList(entity.getId());
            if (allList.size() > 0) {
                return ActionResult.fail(MsgCode.FA016.get());
            }
            if (!Objects.equals(entity.getCreatorUserId(), UserProvider.getLoginUserId())) {
                return ActionResult.fail(MsgCode.AD104.get());
            }
            documentService.delete(entity);
            return ActionResult.success(MsgCode.SU003.get());
        }
        return ActionResult.fail(MsgCode.FA003.get());
    }
 
    /**
     * 列表
     *
     * @return
     */
    @Operation(summary = "获取知识管理列表(文件夹树)")
    @PostMapping("/FolderTree")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<ListVO<DocumentFolderTreeVO>> folderTree(@RequestBody DocumentShareForm form) {
        List<DocumentEntity> data = documentService.getFolderList();
        if (StringUtil.isNotEmpty(form.getIds())) {
            form.getIds().forEach(t -> data.remove(documentService.getInfo(t)));
        }
        List<DocumentFolderTreeModel> treeList = new ArrayList<>();
        DocumentFolderTreeModel model = new DocumentFolderTreeModel();
        model.setId("-1");
        model.setFullName("全部文档");
        model.setParentId("0");
        model.setIcon("0");
        treeList.add(model);
        for (DocumentEntity entity : data) {
            DocumentFolderTreeModel treeModel = new DocumentFolderTreeModel();
            treeModel.setId(entity.getId());
            treeModel.setFullName(entity.getFullName());
            treeModel.setParentId(entity.getParentId());
            treeModel.setIcon("fa fa-folder");
            treeList.add(treeModel);
        }
        List<SumTree<DocumentFolderTreeModel>> trees = TreeDotUtils.convertListToTreeDotFilter(treeList);
        List<DocumentFolderTreeVO> listVO = JsonUtil.getJsonToList(trees, DocumentFolderTreeVO.class);
        ListVO vo = new ListVO();
        vo.setList(listVO);
        return ActionResult.success(vo);
    }
 
    /**
     * 列表(全部文档)
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取知识管理列表(全部文档)")
    @GetMapping
    public ActionResult<ListVO<DocumentListVO>> allList(PageDocument page) {
        List<DocumentEntity> data = documentService.getAllList(page.getParentId());
        if (StringUtil.isNotEmpty(page.getKeyword())) {
            data = documentService.getSearchAllList(page.getKeyword());
        }
        List<DocumentListVO> list = JsonUtil.getJsonToList(data, DocumentListVO.class);
        //读取允许文件预览类型
        String allowPreviewType = configValueUtil.getAllowPreviewFileType();
        String[] fileType = allowPreviewType.split(",");
        for (DocumentListVO documentListVO : list) {
            //文件预览类型检验
            String s = Arrays.asList(fileType).stream().filter(type -> type.equals(documentListVO.getFileExtension())).findFirst().orElse(null);
            documentListVO.setIsPreview(s);
        }
 
        ListVO vo = new ListVO();
        vo.setList(list);
        return ActionResult.success(vo);
    }
 
    /**
     * 列表(我的分享)
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "知识管理(我的共享列表)")
    @GetMapping("/Share")
    public ActionResult<ListVO<DocumentListVO>> shareOutList(PageDocument page) {
        List<DocumentEntity> data = documentService.getShareOutList();
        if (StringUtil.isNotEmpty(page.getKeyword())) {
            List<DocumentEntity> dataSearch = new ArrayList<>();
            for (DocumentEntity datum : data) {
                if (Objects.equals(datum.getType(), 0)) {
                    List<DocumentEntity> childList = new ArrayList<>();
                    documentService.getChildSrcList(datum.getId(), childList, 1);
                    List<DocumentEntity> collect = childList.stream().filter(t -> !Objects.equals(t.getType(), 0)).collect(Collectors.toList());
                    dataSearch.addAll(collect);
                } else {
                    dataSearch.add(datum);
                }
 
            }
            data = dataSearch.stream().distinct().filter(t -> t.getFullName().contains(page.getKeyword())).collect(Collectors.toList());
        } else if (StringUtil.isNotEmpty(page.getParentId()) && !"0".equals(page.getParentId())) {
            data = documentService.getAllList(page.getParentId());
        }
        List<DocumentListVO> list = JsonUtil.getJsonToList(data, DocumentListVO.class);
        ListVO vo = new ListVO();
        vo.setList(list);
        return ActionResult.success(vo);
    }
 
    /**
     * 列表(共享给我)
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取知识管理列表(共享给我)")
    @GetMapping("/ShareTome")
    public ActionResult shareTomeList(PageDocument page) {
        List<DocumentShareEntity> shareTomeList = documentService.getShareTomeList();
        List<String> ids = shareTomeList.stream().map(DocumentShareEntity::getDocumentId).collect(Collectors.toList());
        List<DocumentEntity> list = documentService.getInfoByIds(ids);
 
        List<String> userIds = list.stream().map(SuperBaseEntity.SuperCBaseEntity::getCreatorUserId).collect(Collectors.toList());
        List<UserEntity> userNames = userService.getUserName(userIds);
        List<DocumentListVO> dataRes = new ArrayList<>();
        if (StringUtil.isNotEmpty(page.getParentId()) && !"0".equals(page.getParentId())) {
            List<DocumentListVO> listVOS = documentService.getChildListUserName(page.getParentId(), true);
            DocumentShareEntity documentShareEntity = documentService.getShareByParentId(page.getParentId());
            for (DocumentListVO item : listVOS) {
                if (documentShareEntity != null) {
                    item.setShareTime(documentShareEntity.getShareTime());
                    UserEntity userEntity = userNames.stream().filter(t -> t.getId().equals(documentShareEntity.getCreatorUserId())).findFirst().orElse(null);
                    item.setCreatorUserId(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
                }
                String creatorUserName = item.getCreatorUserName();
                String creatorUserAccount = item.getCreatorUserAccount();
                item.setCreatorUserId(creatorUserName + "/" + creatorUserAccount);
                dataRes.add(item);
            }
        } else {
            for (DocumentEntity datum : list) {
                if (StringUtil.isNotEmpty(page.getKeyword())) {
                    DocumentShareEntity documentShareEntity = shareTomeList.stream().filter(t -> t.getDocumentId().equals(datum.getId())).findFirst().orElse(null);
                    if (documentShareEntity != null) {
                        if (Objects.equals(datum.getType(), 0)) {
                            List<DocumentEntity> childList = new ArrayList<>();
                            documentService.getChildSrcList(datum.getId(), childList, 1);
                            for (DocumentEntity item : childList) {
                                DocumentListVO documentListVO = BeanUtil.copyProperties(item, DocumentListVO.class);
                                if (item.getFullName().contains(page.getKeyword()) && Objects.equals(item.getEnabledMark(), 1) && !Objects.equals(item.getType(), 0)) {
                                    documentListVO.setShareTime(documentShareEntity.getShareTime());
                                    UserEntity userEntity = userNames.stream().filter(t -> t.getId().equals(documentShareEntity.getCreatorUserId())).findFirst().orElse(null);
                                    documentListVO.setCreatorUserId(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
                                    dataRes.add(documentListVO);
                                }
                            }
                        }
                    }
                } else {
                    DocumentShareEntity documentShareEntity = shareTomeList.stream().filter(t -> t.getDocumentId().equals(datum.getId())).findFirst().orElse(null);
                    if (documentShareEntity != null) {
                        DocumentListVO documentListVO = BeanUtil.copyProperties(datum, DocumentListVO.class);
                        documentListVO.setShareTime(documentShareEntity.getShareTime());
                        UserEntity userEntity = userNames.stream().filter(t -> t.getId().equals(documentShareEntity.getCreatorUserId())).findFirst().orElse(null);
                        documentListVO.setCreatorUserId(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
                        dataRes.add(documentListVO);
                    }
                }
            }
        }
 
        ListVO vo = new ListVO();
        vo.setList(dataRes);
        return ActionResult.success(vo);
    }
 
    /**
     * 列表(回收站)
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取知识管理列表(回收站)")
    @GetMapping("/Trash")
    public ActionResult<ListVO<DocumentTrashListVO>> trashList(Page page) {
        List<DocumentTrashListVO> data = documentService.getTrashList(page.getKeyword());
        ListVO vo = new ListVO();
        vo.setList(data);
        return ActionResult.success(vo);
    }
 
    /**
     * 列表(共享人员)
     *
     * @param documentId 文档主键
     * @return
     */
    @Operation(summary = "获取知识管理列表(共享人员)")
    @GetMapping("/ShareUser/{documentId}")
    @Parameters({
            @Parameter(name = "documentId", description = "文档主键", required = true),
    })
    public ActionResult<ListVO<DocumentSuserListVO>> shareUserList(@PathVariable("documentId") String documentId) {
        List<DocumentShareEntity> data = documentService.getShareUserList(documentId);
        List<DocumentSuserListVO> list = JsonUtil.getJsonToList(data, DocumentSuserListVO.class);
        ListVO vo = new ListVO();
        vo.setList(list);
        return ActionResult.success(vo);
    }
 
    /**
     * app上传文件
     *
     * @param documentUploader 上传模型
     * @return
     */
    @Operation(summary = "知识管理上传文件")
    @PostMapping("/Uploader")
    public ActionResult uploader(DocumentUploader documentUploader) throws DataException {
        String fileType = UpUtil.getFileType(documentUploader.getFile());
        //验证类型
        if (!OptimizeUtil.fileType(configValueUtil.getAllowUploadFileType(), fileType)) {
            return ActionResult.fail(MsgCode.FA017.get());
        }
 
        //上传
        uploaderVO(documentUploader);
        return ActionResult.success(MsgCode.SU015.get());
    }
 
    /**
     * 分片组装
     *
     * @param mergeChunkDto 合并模型
     * @return
     */
    @Operation(summary = "分片组装")
    @PostMapping("/merge")
    public ActionResult merge(MergeChunkDto mergeChunkDto) {
        String identifier = XSSEscape.escapePath(mergeChunkDto.getIdentifier());
        String path = fileApi.getLocalBasePath() + configValueUtil.getTemporaryFilePath();
        String filePath = XSSEscape.escapePath(path + identifier);
        String partFile = XSSEscape.escapePath(path + mergeChunkDto.getFileName());
        try {
            List<File> mergeFileList = FileUtil.getFile(new File(filePath));
            @Cleanup FileOutputStream destTempfos = new FileOutputStream(partFile, true);
            for (int i = 0; i < mergeFileList.size(); i++) {
                String chunkName = identifier.concat("-") + (i + 1);
                File files = new File(filePath, chunkName);
                if (files.exists()) {
                    FileUtils.copyFile(files, destTempfos);
                }
            }
            File partFiles = new File(partFile);
            if (partFiles.exists()) {
                MultipartFile multipartFile = FileUtil.createFileItem(partFiles);
                uploaderVO(new DocumentUploader(multipartFile, mergeChunkDto.getParentId()));
                FileUtil.deleteTmp(multipartFile);
            }
        } catch (Exception e) {
            log.error("合并分片失败: {}", e.getMessage());
            throw new DataException(MsgCode.FA033.get());
        } finally {
            FileUtils.deleteQuietly(new File(filePath));
            FileUtils.deleteQuietly(new File(partFile));
        }
        return ActionResult.success(MsgCode.SU015.get());
    }
 
    @Operation(summary = "流程归档文件上传接口")
    @PostMapping("/UploadBlob")
    public ActionResult UploadBlob(DocumentUploader dub) throws DataException {
        uploaderVO(dub);
        workFlowApi.updateIsFile(dub.getTaskId());
        return ActionResult.success(MsgCode.SU015.get());
    }
 
    /**
     * 获取下载文件链接
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "获取下载文件链接")
    @PostMapping("/Download/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult download(@PathVariable("id") String id) {
        UserInfo userInfo = UserProvider.getUser();
        DocumentEntity entity = documentService.getInfo(id);
        if (entity != null) {
            String name = entity.getFilePath();
            String fileName = name + "#" + FileTypeConstant.DOCUMENT + "#" + entity.getFullName() + "." + entity.getFileExtension();
            DownloadVO vo = DownloadVO.builder().name(entity.getFullName()).url(UploaderUtil.uploaderFile(fileName)).build();
            return ActionResult.success(vo);
        }
        return ActionResult.fail(MsgCode.FA018.get());
    }
 
    /**
     * 获取全部下载文件链接(打包下载)
     *
     * @return
     */
    @Operation(summary = "打包下载")
    @PostMapping("/PackDownload")
    public ActionResult packDownloadUrl(@RequestBody DocumentShareForm obj) {
        //单个文件直接下载
        if (obj.getIds().size() == 1) {
            DocumentEntity entity = documentService.getInfo(obj.getIds().get(0));
            if (entity != null && !Objects.equals(entity.getType(), 0)) {
                String name = entity.getFilePath();
                String fileName = name + "#" + FileTypeConstant.DOCUMENT + "#" + entity.getFullName() + "." + entity.getFileExtension();
                DownloadVO vo = DownloadVO.builder().name(entity.getFullName()).url(UploaderUtil.uploaderFile(fileName)).build();
                return ActionResult.success(vo);
            }
        }
        String servicePath = fileApi.getPath(FileTypeConstant.FILEZIPDOWNTEMPPATH);
        String tempFilePath = fileApi.getLocalBasePath() + servicePath;
        String zipFileSrc = "Package_" + RandomUtil.uuId();
        String zipFileName = zipFileSrc + ".zip";
        String mainPath = tempFilePath + zipFileSrc;
        new File(mainPath).mkdirs();
        //递归生成文件夹下的文件
        createdFiles(obj.getIds(), mainPath);
 
        String filePath = tempFilePath + zipFileName;
        //打包
        FileUtil.toZip(filePath, true, tempFilePath + zipFileSrc);
        //删除源文件
        FileUtil.deleteFileAll(new File(tempFilePath + zipFileSrc));
 
        //上传压缩包到服务器
        MultipartFile multipartFile = FileUtil.createFileItem(new File(XSSEscape.escapePath(filePath)));
 
        FileInfo fileInfo = fileUploadApi.uploadFile(multipartFile, servicePath, zipFileName);
        // 删除压缩包
        FileUtil.deleteFileAll(new File(tempFilePath + zipFileName));
 
        //获取服务器下载路径
        DownloadVO vo = DownloadVO.builder()
                .name(zipFileName)
                .url(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + FileTypeConstant.FILEZIPDOWNTEMPPATH))
                .build();
        return ActionResult.success(vo);
    }
 
    /**
     * 递归获取文件夹下的文件
     *
     * @param fileIdList
     * @param mainPath
     */
    private void createdFiles(List<String> fileIdList, String mainPath) {
        for (String id : fileIdList) {
            DocumentEntity info = documentService.getInfo(id);
            if (info != null) {
                String fileId = StringUtil.isNotEmpty(info.getFilePath()) ? XSSEscape.escape(info.getFilePath()).trim() : "";
                String fileName = XSSEscape.escapePath(info.getFullName()).trim();
                if (Objects.equals(info.getType(), 0)) {
                    //文件夹
                    File file = new File(mainPath + "/" + fileName);
                    if (!file.exists()) {
                        file.mkdir();
                    }
                    List<DocumentEntity> allList = documentService.getChildList(id, true);
                    List<String> collect = allList.stream().map(DocumentEntity::getId).collect(Collectors.toList());
                    createdFiles(collect, mainPath + "/" + fileName);
                } else {
                    try {
                        //文件
                        @Cleanup Response response = fileUploadApi.downFile(new UploadFileModel(mainPath, FileTypeConstant.DOCUMENT, fileId));
                        @Cleanup InputStream inputStream = response.body().asInputStream();
                        cn.hutool.core.io.FileUtil.copyFile(inputStream, new File(mainPath + "/" + fileName), StandardCopyOption.REPLACE_EXISTING);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
 
 
    /**
     * 批量删除
     */
    @Operation(summary = "批量删除")
    @PostMapping("/BatchDelete")
    @Parameters({
            @Parameter(name = "ids", description = "主键", required = true),
    })
    public ActionResult BatchDelete(@RequestBody DocumentShareForm obj) {
        for (String id : obj.getIds()) {
            DocumentEntity entity = documentService.getInfo(id);
            if (entity != null) {
                if (!Objects.equals(entity.getCreatorUserId(), UserProvider.getLoginUserId())) {
                    return ActionResult.fail(MsgCode.AD104.get());
                }
                List<DocumentEntity> allList = new ArrayList<>();
                documentService.getChildSrcList(entity.getId(), allList, 1);
                allList.add(entity);
                //添加删除记录
                DocumentLogEntity logent = new DocumentLogEntity();
                logent.setDocumentId(id);
                List<String> collect = allList.stream().map(DocumentEntity::getId).collect(Collectors.toList());
                logent.setChildDocument(collect.stream().collect(Collectors.joining(",")));
                documentLogService.save(logent);
                for (DocumentEntity item : allList) {
                    documentService.delete(item);
                }
            }
        }
        return ActionResult.success(MsgCode.SU003.get());
    }
 
    /**
     * 回收站(彻底删除)
     *
     * @return
     */
    @Operation(summary = "回收站(彻底删除)")
    @PostMapping("/Trash")
    @Parameters({
            @Parameter(name = "ids", description = "主键数组", required = true),
    })
    public ActionResult trashdelete(@RequestBody DocumentShareForm obj) {
        documentService.trashdelete(obj.getIds());
        return ActionResult.success(MsgCode.SU003.get());
    }
 
    /**
     * 回收站(还原文件)
     *
     * @return
     */
    @Operation(summary = "回收站(还原文件)")
    @PostMapping("/Trash/Actions/Recovery")
    @Parameters({
            @Parameter(name = "ids", description = "主键数组", required = true),
    })
    @Transactional
    public ActionResult trashRecovery(@RequestBody DocumentShareForm obj) {
        documentService.trashRecoveryConstainSrc(obj.getIds());
        return ActionResult.success(MsgCode.SU010.get());
    }
 
    /**
     * 共享文件(创建)
     *
     * @param documentShareForm 分享模型
     * @return
     */
    @Operation(summary = "分享文件/文件夹")
    @PostMapping("/Actions/Share")
    @Parameters({
            @Parameter(name = "documentShareForm", description = "分享模型", required = true),
    })
    public ActionResult shareCreate(@RequestBody DocumentShareForm documentShareForm) {
        documentService.sharecreate(documentShareForm);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    /**
     * 取消共享
     *
     * @param obj 主键值
     * @return
     */
    @Operation(summary = "取消分享文件/文件夹")
    @PostMapping("/Actions/CancelShare")
    @Parameters({
            @Parameter(name = "ids", description = "主键", required = true),
    })
    public ActionResult shareCancel(@RequestBody DocumentShareForm obj) {
        documentService.shareCancel(obj.getIds());
        return ActionResult.success(MsgCode.SU005.get());
    }
 
 
    @Operation(summary = "共享用户调整")
    @PostMapping("/Actions/ShareAdjustment/{id}")
    @Parameters({
            @Parameter(name = "id", description = "文档主键", required = true),
            @Parameter(name = "userIds", description = "共享用户组", required = true),
    })
    public ActionResult shareAdjustment(@PathVariable("id") String id, @RequestBody DocumentShareForm obj) {
        if (obj.getUserIds().size() > 0) {
            documentService.shareAdjustment(id, obj.getUserIds());
        }
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    @Operation(summary = "移动文件/文件夹")
    @PutMapping("/Actions/MoveTo/{toId}")
    @Parameters({
            @Parameter(name = "ids", description = "主键", required = true),
            @Parameter(name = "toId", description = "将要移动到Id", required = true),
    })
    @Transactional
    public ActionResult moveTo(@RequestBody DocumentShareForm obj, @PathVariable("toId") String toId) {
        List<String> allIds = new ArrayList<>();
        allIds.addAll(obj.getIds());
        List<DocumentEntity> childList = new ArrayList<>();
        for (String oneId : obj.getIds()) {
            documentService.getChildSrcList(oneId, childList, 1);
        }
        allIds.addAll(childList.stream().map(DocumentEntity::getId).collect(Collectors.toList()));
        if (allIds.contains(toId)) {
            return ActionResult.fail(MsgCode.ETD103.get());
        }
 
        for (String id : obj.getIds()) {
            boolean flag = documentService.moveTo(id, toId);
            if (flag == false) {
                return ActionResult.fail(MsgCode.FA002.get());
            }
        }
 
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 封装上传附件
     * 流程归档-文件上传
     *
     * @return
     */
    private void uploaderVO(DocumentUploader documentUploader) {
        MultipartFile file = documentUploader.getFile();
        String parentId = documentUploader.getParentId();
        String taskId = documentUploader.getTaskId();
        String fileName = StringUtil.isNotEmpty(documentUploader.getTaskId()) ? documentUploader.getTaskId() :
                StringUtil.isNotEmpty(documentUploader.getFileName()) ? documentUploader.getFileName() : file.getOriginalFilename();
        String fileType = UpUtil.getFileType(file);
        String creatorUserId = "";
        List<String> userList = new ArrayList<>();
        if (StringUtil.isNotEmpty(taskId)) {
            try { //获取流程信息
                FileModel fileModel = workFlowApi.getFileModel(taskId);
                fileName = fileModel.getFilename();
                creatorUserId = fileModel.getUserId();
                userList.addAll(fileModel.getUserList());
                fileType = "pdf";
 
                List<DocumentEntity> allList = documentService.getAllList("0", creatorUserId);
                DocumentEntity documentEntity = allList.stream().filter(t -> Objects.equals(t.getType(), 0) && FileModel.FOLDER_NAME.equals(t.getFullName())).findFirst().orElse(null);
                if (Objects.isNull(documentEntity)) {
                    documentEntity = new DocumentEntity();
                    documentEntity.setFullName(FileModel.FOLDER_NAME);
                    documentEntity.setType(0);
                    documentEntity.setParentId("0");
                    documentEntity.setCreatorUserId(creatorUserId);
                    documentService.create(documentEntity);
                }
                parentId = documentEntity.getId();
            } catch (Exception e) {
                throw new DataException(MsgCode.FA001.get());
            }
        }
 
        List<DocumentEntity> data = documentService.getAllList(parentId);
        String finalFileName = fileName;
        data = data.stream().filter(t -> finalFileName.equals(t.getFullName())).collect(Collectors.toList());
        if (data.size() > 0) {
            fileName = fileName.substring(0, fileName.lastIndexOf(".")) + "副本" + UUID.randomUUID().toString().substring(0, 5) + fileName.substring(fileName.lastIndexOf("."));
        }
        //上传
        //上传
        MergeChunkDto mergeChunkDto = new MergeChunkDto();
        mergeChunkDto.setType(FileTypeConstant.DOCUMENT);
        mergeChunkDto.setFileType(fileType);
        UploaderVO uploaderVO = fileService.uploadFile(mergeChunkDto, file);
        DocumentEntity entity = new DocumentEntity();
        entity.setType(1);
        entity.setFullName(fileName);
        entity.setParentId(parentId);
        entity.setFileExtension(fileType);
        entity.setFilePath(uploaderVO.getName());
        entity.setFileSize(String.valueOf(file.getSize()));
        entity.setCreatorUserId(creatorUserId);
        entity.setEnabledMark(1);
        String desc = null;
        TaskEntity taskEntity = workFlowApi.getInfoSubmit(taskId);
        if (null != taskEntity) {
            desc = taskId + "-" + taskEntity.getTemplateId();
        }
        entity.setDescription(desc);
        entity.setUploaderUrl(UploaderUtil.uploaderImg("/api/file/Image/document/", uploaderVO.getName()));
        documentService.create(entity);
        if (StringUtil.isNotEmpty(taskId)) {
            DocumentShareForm documentShareForm = new DocumentShareForm();
            documentShareForm.setUserIds(userList);
            documentShareForm.setIds(new ArrayList() {{
                add(entity.getId());
            }});
            documentShareForm.setCreatorUserId(creatorUserId);
            documentService.sharecreate(documentShareForm);
        }
    }
 
    /**
     * 判断是否存在归档文件
     *
     * @param taskId 流程任务主键
     */
    @Operation(summary = "判断是否存在归档文件")
    @GetMapping("/checkFlowFile/{taskId}")
    @Parameters({
            @Parameter(name = "taskId", description = "流程任务ID", required = true),
    })
    @Override
    public Boolean checkFlowFile(@PathVariable("taskId") String taskId) {
        QueryWrapper<DocumentEntity> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(DocumentEntity::getDescription, taskId);
        return documentService.count(wrapper) < 1;
    }
 
    /**
     * 获取归档文件
     *
     * @param model 参数
     */
    @PostMapping("/getFlowFile")
    @Override
    public List<Map<String, Object>> getFlowFile(@RequestBody FlowFileModel model) {
        return documentService.getFlowFile(model);
    }
}