diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/onlyoffice/document/DocumentServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/onlyoffice/document/DocumentServiceImpl.java index 3487a5d..224db61 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/onlyoffice/document/DocumentServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/onlyoffice/document/DocumentServiceImpl.java @@ -23,6 +23,10 @@ import java.io.*; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; + @Slf4j @Service public class DocumentServiceImpl implements DocumentService{ @@ -45,15 +49,18 @@ public class DocumentServiceImpl implements DocumentService{ @Override public String buildDocument(String filePath, String fileName) { if (StringUtils.isBlank(filePath)) { +// throw exception(DOC_FILE_NOT_EXISTS); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS); } filePath = FilenameUtils.normalize(filePath); String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(filePath)); if (StringUtils.isBlank(fileType)) { +// throw exception(DOC_FILE_NO_EXTENSION); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_NO_EXTENSION); } // 如果指定了文件名,则需要校验和实体文件格式是否一致 if (StringUtils.isNotBlank(fileName) && !fileType.equalsIgnoreCase(FilenameUtils.getExtension(fileName))) { +// throw exception(DOC_FILE_EXTENSION_NOT_MATCH); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_EXTENSION_NOT_MATCH); } File docFile = new File(filePath); @@ -73,6 +80,7 @@ public class DocumentServiceImpl implements DocumentService{ // log.error("$$$ 缓存失败~~", e); // } // if (!cached) { +// throw exception(DOC_CACHE_ERROR); // throw new DocumentException(ErrorCodeEnum.DOC_CACHE_ERROR); // } document.setKey(fileKey); @@ -122,6 +130,7 @@ public class DocumentServiceImpl implements DocumentService{ log.error("$$$ 获取缓存失败~~", e); } if (doc == null) { +// throw exception(DOC_CACHE_NOT_EXISTS); // throw new DocumentException(ErrorCodeEnum.DOC_CACHE_NOT_EXISTS); } // 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小) @@ -142,6 +151,7 @@ public class DocumentServiceImpl implements DocumentService{ log.error("$$$ 获取缓存失败~~", e); } if (doc == null) { +// throw exception(DOC_CACHE_NOT_EXISTS); // throw new DocumentException(ErrorCodeEnum.DOC_CACHE_NOT_EXISTS); } // 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小) @@ -163,6 +173,7 @@ public class DocumentServiceImpl implements DocumentService{ String docFileMd5 = Md5Utils.getFileMd5(docFile); if (StringUtils.isBlank(docFileMd5)) { log.error("$$$ 构建文件信息失败!计算文件 md5 失败!"); +// throw exception(DOC_FILE_MD5_ERROR); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_MD5_ERROR); } String pathShortMd5 = Md5Utils.md5(docFile.getAbsolutePath()); @@ -171,6 +182,7 @@ public class DocumentServiceImpl implements DocumentService{ // (将路径字符串短md5值 + 名称字符串短md5值) ==> 再转成短id形式 ==> 作为文档的key(暂且认为是不会重复的) String key = hashids.encodeHex(String.format("%s%s%s", docFileMd5,pathShortMd5, nameShortMd5)); if (StringUtils.isBlank(key)) { +// throw exception(DOC_FILE_KEY_ERROR); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_KEY_ERROR); } return key; @@ -342,24 +354,29 @@ public class DocumentServiceImpl implements DocumentService{ } if (docFile == null || !docFile.exists()) { log.error("$$$ 目标文档不存在,无法打开!"); +// throw exception(DOC_FILE_NOT_EXISTS); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS); } if (docFile.isDirectory() || docFile.length() <= 0) { log.error("$$$ 目标文档[{}]是目录或空文件,无法打开!", docFile.getAbsolutePath()); +// throw exception(DOC_FILE_EMPTY); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_EMPTY); } if (!docFile.canRead()) { log.error("$$$ 目标文档[{}]不可读,无法打开!", docFile.getAbsolutePath()); +// throw exception(DOC_FILE_UNREADABLE); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_UNREADABLE); } if (docFile.length() > docFileSizeLimit) { log.error("$$$ 目标文档大小超过限制({}B > {}B),无法打开!", docFile.length(), docFileSizeLimit); +// throw exception(DOC_FILE_OVERSIZE); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_OVERSIZE); } String ext = StringUtils.lowerCase(FilenameUtils.getExtension(docFile.getName())); if (!ArrayUtils.contains(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ext)) { log.error("$$$ 目标文档格式[{}]不正确,无法打开!(只支持:{})", ext, StringUtils.join(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ",")); +// throw exception(DOC_FILE_TYPE_UNSUPPORTED); // throw new DocumentException(ErrorCodeEnum.DOC_FILE_TYPE_UNSUPPORTED); } }