| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796 |
- package jnpf.controller;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.text.StrPool;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- 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.controller.SuperController;
- import jnpf.base.entity.SuperBaseEntity;
- import jnpf.base.util.OptimizeUtil;
- 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.entity.FileParameter;
- import jnpf.exception.DataException;
- import jnpf.extend.service.DocumentApi;
- 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.permission.entity.UserEntity;
- import jnpf.permission.service.UserService;
- 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 jnpf.workflow.service.TaskApi;
- 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.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("/api/file/Document")
- public class DocumentController extends SuperController<DocumentService, DocumentEntity> implements DocumentApi {
- @Autowired
- private DocumentService documentService;
- @Autowired
- private ConfigValueUtil configValueUtil;
- @Autowired
- private UserService userService;
-
- @Autowired
- private DocumentLogService documentLogService;
- @Autowired
- private TaskApi taskApi;
- @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 = FileUploadUtils.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);
- taskApi.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) {
- 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 = FilePathUtil.getFilePath(FileTypeConstant.FILEZIPDOWNTEMPPATH);
- String tempFilePath = FileUploadUtils.getLocalBasePath() + FilePathUtil.getFilePath(FileTypeConstant.FILEZIPDOWNTEMPPATH);
- String zipFileSrc = "Package_" + RandomUtil.uuId();
- String zipFileName = zipFileSrc + ".zip";
- String mainPath = servicePath + zipFileSrc + File.separator;
- String absMainPath = tempFilePath + zipFileSrc;
- new File(absMainPath).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 = FileUploadUtils.uploadFile(new FileParameter(FilePathUtil.getFilePath(FileTypeConstant.FILEZIPDOWNTEMPPATH), zipFileName), multipartFile);
- // 删除压缩包
- 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(FileUploadUtils.getLocalBasePath() + 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 + File.separator);
- } else {
- try {
- //文件
- FileUploadUtils.downloadFileToLocal(new FileParameter(FilePathUtil.getFilePath(FileTypeConstant.DOCUMENT), fileId).setLocaFilelPath(mainPath).setLocalFileName(fileName));
- } 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 = taskApi.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 = taskApi.getInfoSubmit(taskId, TaskEntity::getId, TaskEntity::getTemplateId);
- 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 流程任务主键
- */
- @Override
- public Boolean checkFlowFile(String taskId) {
- QueryWrapper<DocumentEntity> wrapper = new QueryWrapper<>();
- wrapper.lambda().like(DocumentEntity::getDescription, taskId);
- return documentService.count(wrapper) < 1;
- }
- /**
- * 获取归档文件
- *
- * @param model 参数
- */
- @Override
- public List<Map<String, Object>> getFlowFile(FlowFileModel model) {
- return documentService.getFlowFile(model);
- }
- }
|