From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/DocumentController.java |  778 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 778 insertions(+), 0 deletions(-)

diff --git a/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/DocumentController.java b/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/DocumentController.java
new file mode 100644
index 0000000..f3d88f0
--- /dev/null
+++ b/jnpf-file/jnpf-file-storage/src/main/java/jnpf/controller/DocumentController.java
@@ -0,0 +1,778 @@
+package jnpf.controller;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.text.StrPool;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+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.tags.Tag;
+import jakarta.validation.Valid;
+import jnpf.base.ActionResult;
+import jnpf.base.Page;
+import jnpf.base.controller.SuperController;
+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.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.dromara.x.file.storage.core.FileInfo;
+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")
+@RequiredArgsConstructor
+public class DocumentController extends SuperController<DocumentService, DocumentEntity> implements DocumentApi {
+
+
+    private final DocumentService documentService;
+
+    private final ConfigValueUtil configValueUtil;
+
+    private final UserApi userService;
+
+
+    private final DocumentLogService documentLogService;
+
+    private final WorkFlowApi workFlowApi;
+
+    private final FileApi fileApi;
+
+    private final FileUploadApi fileUploadApi;
+
+    private final FileService fileService;
+
+    /**
+     * 鍒楄〃
+     *
+     * @param id 涓婚敭
+     * @return
+     */
+    @Operation(summary = "鍒楄〃")
+    @GetMapping("/{id}")
+    @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
+    @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}")
+    @Parameter(name = "id", description = "涓婚敭", required = true)
+    @Parameter(name = "documentUpForm", description = "鐭ヨ瘑妯″瀷", required = true)
+    public ActionResult<Object> 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) {
+            return ActionResult.fail(MsgCode.FA002.get());
+        }
+        return ActionResult.success(MsgCode.SU004.get());
+    }
+
+    /**
+     * 鍒犻櫎
+     *
+     * @param id 涓婚敭
+     * @return
+     */
+    @Operation(summary = "鍒犻櫎")
+    @DeleteMapping("/{id}")
+    @Parameter(name = "id", description = "涓婚敭", required = true)
+    public ActionResult<Object> delete(@PathVariable("id") String id) {
+        DocumentEntity entity = documentService.getInfo(id);
+        if (entity != null) {
+            List<DocumentEntity> allList = documentService.getAllList(entity.getId());
+            if (!allList.isEmpty()) {
+                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")
+    @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<DocumentFolderTreeVO> vo = new ListVO<>();
+        vo.setList(listVO);
+        return ActionResult.success(vo);
+    }
+
+    /**
+     * 鍒楄〃锛堝叏閮ㄦ枃妗o級
+     *
+     * @param page 鍒嗛〉妯″瀷
+     * @return
+     */
+    @Operation(summary = "鑾峰彇鐭ヨ瘑绠$悊鍒楄〃锛堝叏閮ㄦ枃妗o級")
+    @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.stream(fileType).filter(type -> type.equals(documentListVO.getFileExtension())).findFirst().orElse(null);
+            documentListVO.setIsPreview(s);
+        }
+
+        ListVO<DocumentListVO> 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<DocumentListVO> 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(DocumentEntity::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 && 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<DocumentListVO> 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<DocumentTrashListVO> vo = new ListVO<>();
+        vo.setList(data);
+        return ActionResult.success(vo);
+    }
+
+    /**
+     * 鍒楄〃锛堝叡浜汉鍛橈級
+     *
+     * @param documentId 鏂囨。涓婚敭
+     * @return
+     */
+    @Operation(summary = "鑾峰彇鐭ヨ瘑绠$悊鍒楄〃锛堝叡浜汉鍛橈級")
+    @GetMapping("/ShareUser/{documentId}")
+    @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<DocumentSuserListVO> vo = new ListVO<>();
+        vo.setList(list);
+        return ActionResult.success(vo);
+    }
+
+    /**
+     * app涓婁紶鏂囦欢
+     *
+     * @param documentUploader 涓婁紶妯″瀷
+     * @return
+     */
+    @Operation(summary = "鐭ヨ瘑绠$悊涓婁紶鏂囦欢")
+    @PostMapping("/Uploader")
+    public ActionResult<Object> 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<Object> 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(FileOutputStream destTempfos = new FileOutputStream(partFile, true)) {
+            List<File> mergeFileList = FileUtil.getFile(new File(filePath));
+            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<Object> 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}")
+    @Parameter(name = "id", description = "涓婚敭", required = true)
+    public ActionResult<Object> download(@PathVariable("id") String id) {
+        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<Object> 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 + File.separator + 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 + File.separator + 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 + File.separator + fileName), StandardCopyOption.REPLACE_EXISTING);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 鎵归噺鍒犻櫎
+     */
+    @Operation(summary = "鎵归噺鍒犻櫎")
+    @PostMapping("/BatchDelete")
+    @Parameter(name = "ids", description = "涓婚敭", required = true)
+    public ActionResult<Object> 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(String.join(",", collect));
+                documentLogService.save(logent);
+                for (DocumentEntity item : allList) {
+                    documentService.delete(item);
+                }
+            }
+        }
+        return ActionResult.success(MsgCode.SU003.get());
+    }
+
+    /**
+     * 鍥炴敹绔欙紙褰诲簳鍒犻櫎锛�
+     *
+     * @return
+     */
+    @Operation(summary = "鍥炴敹绔欙紙褰诲簳鍒犻櫎锛�")
+    @PostMapping("/Trash")
+    @Parameter(name = "ids", description = "涓婚敭鏁扮粍", required = true)
+    public ActionResult<Object> trashdelete(@RequestBody DocumentShareForm obj) {
+        documentService.trashdelete(obj.getIds());
+        return ActionResult.success(MsgCode.SU003.get());
+    }
+
+    /**
+     * 鍥炴敹绔欙紙杩樺師鏂囦欢锛�
+     *
+     * @return
+     */
+    @Operation(summary = "鍥炴敹绔欙紙杩樺師鏂囦欢锛�")
+    @PostMapping("/Trash/Actions/Recovery")
+    @Parameter(name = "ids", description = "涓婚敭鏁扮粍", required = true)
+    @DSTransactional
+    public ActionResult<Object> trashRecovery(@RequestBody DocumentShareForm obj) {
+        documentService.trashRecoveryConstainSrc(obj.getIds());
+        return ActionResult.success(MsgCode.SU010.get());
+    }
+
+    /**
+     * 鍏变韩鏂囦欢锛堝垱寤猴級
+     *
+     * @param documentShareForm 鍒嗕韩妯″瀷
+     * @return
+     */
+    @Operation(summary = "鍒嗕韩鏂囦欢/鏂囦欢澶�")
+    @PostMapping("/Actions/Share")
+    @Parameter(name = "documentShareForm", description = "鍒嗕韩妯″瀷", required = true)
+    public ActionResult<Object> shareCreate(@RequestBody DocumentShareForm documentShareForm) {
+        documentService.sharecreate(documentShareForm);
+        return ActionResult.success(MsgCode.SU005.get());
+    }
+
+    /**
+     * 鍙栨秷鍏变韩
+     *
+     * @param obj 涓婚敭鍊�
+     * @return
+     */
+    @Operation(summary = "鍙栨秷鍒嗕韩鏂囦欢/鏂囦欢澶�")
+    @PostMapping("/Actions/CancelShare")
+    @Parameter(name = "ids", description = "涓婚敭", required = true)
+    public ActionResult<Object> shareCancel(@RequestBody DocumentShareForm obj) {
+        documentService.shareCancel(obj.getIds());
+        return ActionResult.success(MsgCode.SU005.get());
+    }
+
+
+    @Operation(summary = "鍏变韩鐢ㄦ埛璋冩暣")
+    @PostMapping("/Actions/ShareAdjustment/{id}")
+    @Parameter(name = "id", description = "鏂囨。涓婚敭", required = true)
+    @Parameter(name = "userIds", description = "鍏变韩鐢ㄦ埛缁�", required = true)
+    public ActionResult<Object> shareAdjustment(@PathVariable("id") String id, @RequestBody DocumentShareForm obj) {
+        if (!obj.getUserIds().isEmpty()) {
+            documentService.shareAdjustment(id, obj.getUserIds());
+        }
+        return ActionResult.success(MsgCode.SU005.get());
+    }
+
+    @Operation(summary = "绉诲姩鏂囦欢/鏂囦欢澶�")
+    @PutMapping("/Actions/MoveTo/{toId}")
+    @Parameter(name = "ids", description = "涓婚敭", required = true)
+    @Parameter(name = "toId", description = "灏嗚绉诲姩鍒癐d", required = true)
+    @DSTransactional
+    public ActionResult<Object> moveTo(@RequestBody DocumentShareForm obj, @PathVariable("toId") String toId) {
+        List<String> allIds = new ArrayList<>(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) {
+                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 s = StringUtil.isNotEmpty(documentUploader.getFileName()) ? documentUploader.getFileName() : file.getOriginalFilename();
+        String fileName = StringUtil.isNotEmpty(documentUploader.getTaskId()) ? documentUploader.getTaskId() :s;
+        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.isEmpty()) {
+            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);
+            List<String> objects = new ArrayList<>();
+            objects.add(entity.getId());
+            documentShareForm.setIds(objects);
+            documentShareForm.setCreatorUserId(creatorUserId);
+            documentService.sharecreate(documentShareForm);
+        }
+    }
+
+    /**
+     * 鍒ゆ柇鏄惁瀛樺湪褰掓。鏂囦欢
+     *
+     * @param taskId 娴佺▼浠诲姟涓婚敭
+     */
+    @Operation(summary = "鍒ゆ柇鏄惁瀛樺湪褰掓。鏂囦欢")
+    @GetMapping("/checkFlowFile/{taskId}")
+    @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);
+    }
+}

--
Gitblit v1.8.0