only
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
2929c0c6b8
commit
273b100f4d
@ -23,6 +23,10 @@ import java.io.*;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
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
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class DocumentServiceImpl implements DocumentService{
|
public class DocumentServiceImpl implements DocumentService{
|
||||||
@ -45,15 +49,18 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
@Override
|
@Override
|
||||||
public String buildDocument(String filePath, String fileName) {
|
public String buildDocument(String filePath, String fileName) {
|
||||||
if (StringUtils.isBlank(filePath)) {
|
if (StringUtils.isBlank(filePath)) {
|
||||||
|
// throw exception(DOC_FILE_NOT_EXISTS);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
filePath = FilenameUtils.normalize(filePath);
|
filePath = FilenameUtils.normalize(filePath);
|
||||||
String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(filePath));
|
String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(filePath));
|
||||||
if (StringUtils.isBlank(fileType)) {
|
if (StringUtils.isBlank(fileType)) {
|
||||||
|
// throw exception(DOC_FILE_NO_EXTENSION);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NO_EXTENSION);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NO_EXTENSION);
|
||||||
}
|
}
|
||||||
// 如果指定了文件名,则需要校验和实体文件格式是否一致
|
// 如果指定了文件名,则需要校验和实体文件格式是否一致
|
||||||
if (StringUtils.isNotBlank(fileName) && !fileType.equalsIgnoreCase(FilenameUtils.getExtension(fileName))) {
|
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);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_EXTENSION_NOT_MATCH);
|
||||||
}
|
}
|
||||||
File docFile = new File(filePath);
|
File docFile = new File(filePath);
|
||||||
@ -73,6 +80,7 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
// log.error("$$$ 缓存失败~~", e);
|
// log.error("$$$ 缓存失败~~", e);
|
||||||
// }
|
// }
|
||||||
// if (!cached) {
|
// if (!cached) {
|
||||||
|
// throw exception(DOC_CACHE_ERROR);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_CACHE_ERROR);
|
// throw new DocumentException(ErrorCodeEnum.DOC_CACHE_ERROR);
|
||||||
// }
|
// }
|
||||||
document.setKey(fileKey);
|
document.setKey(fileKey);
|
||||||
@ -122,6 +130,7 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
log.error("$$$ 获取缓存失败~~", e);
|
log.error("$$$ 获取缓存失败~~", e);
|
||||||
}
|
}
|
||||||
if (doc == null) {
|
if (doc == null) {
|
||||||
|
// throw exception(DOC_CACHE_NOT_EXISTS);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_CACHE_NOT_EXISTS);
|
// throw new DocumentException(ErrorCodeEnum.DOC_CACHE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
// 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小)
|
// 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小)
|
||||||
@ -142,6 +151,7 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
log.error("$$$ 获取缓存失败~~", e);
|
log.error("$$$ 获取缓存失败~~", e);
|
||||||
}
|
}
|
||||||
if (doc == null) {
|
if (doc == null) {
|
||||||
|
// throw exception(DOC_CACHE_NOT_EXISTS);
|
||||||
// throw new DocumentException(ErrorCodeEnum.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);
|
String docFileMd5 = Md5Utils.getFileMd5(docFile);
|
||||||
if (StringUtils.isBlank(docFileMd5)) {
|
if (StringUtils.isBlank(docFileMd5)) {
|
||||||
log.error("$$$ 构建文件信息失败!计算文件 md5 失败!");
|
log.error("$$$ 构建文件信息失败!计算文件 md5 失败!");
|
||||||
|
// throw exception(DOC_FILE_MD5_ERROR);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_MD5_ERROR);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_MD5_ERROR);
|
||||||
}
|
}
|
||||||
String pathShortMd5 = Md5Utils.md5(docFile.getAbsolutePath());
|
String pathShortMd5 = Md5Utils.md5(docFile.getAbsolutePath());
|
||||||
@ -171,6 +182,7 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
// (将路径字符串短md5值 + 名称字符串短md5值) ==> 再转成短id形式 ==> 作为文档的key(暂且认为是不会重复的)
|
// (将路径字符串短md5值 + 名称字符串短md5值) ==> 再转成短id形式 ==> 作为文档的key(暂且认为是不会重复的)
|
||||||
String key = hashids.encodeHex(String.format("%s%s%s", docFileMd5,pathShortMd5, nameShortMd5));
|
String key = hashids.encodeHex(String.format("%s%s%s", docFileMd5,pathShortMd5, nameShortMd5));
|
||||||
if (StringUtils.isBlank(key)) {
|
if (StringUtils.isBlank(key)) {
|
||||||
|
// throw exception(DOC_FILE_KEY_ERROR);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_KEY_ERROR);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_KEY_ERROR);
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
@ -342,24 +354,29 @@ public class DocumentServiceImpl implements DocumentService{
|
|||||||
}
|
}
|
||||||
if (docFile == null || !docFile.exists()) {
|
if (docFile == null || !docFile.exists()) {
|
||||||
log.error("$$$ 目标文档不存在,无法打开!");
|
log.error("$$$ 目标文档不存在,无法打开!");
|
||||||
|
// throw exception(DOC_FILE_NOT_EXISTS);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
if (docFile.isDirectory() || docFile.length() <= 0) {
|
if (docFile.isDirectory() || docFile.length() <= 0) {
|
||||||
log.error("$$$ 目标文档[{}]是目录或空文件,无法打开!", docFile.getAbsolutePath());
|
log.error("$$$ 目标文档[{}]是目录或空文件,无法打开!", docFile.getAbsolutePath());
|
||||||
|
// throw exception(DOC_FILE_EMPTY);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_EMPTY);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_EMPTY);
|
||||||
}
|
}
|
||||||
if (!docFile.canRead()) {
|
if (!docFile.canRead()) {
|
||||||
log.error("$$$ 目标文档[{}]不可读,无法打开!", docFile.getAbsolutePath());
|
log.error("$$$ 目标文档[{}]不可读,无法打开!", docFile.getAbsolutePath());
|
||||||
|
// throw exception(DOC_FILE_UNREADABLE);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_UNREADABLE);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_UNREADABLE);
|
||||||
}
|
}
|
||||||
if (docFile.length() > docFileSizeLimit) {
|
if (docFile.length() > docFileSizeLimit) {
|
||||||
log.error("$$$ 目标文档大小超过限制({}B > {}B),无法打开!", docFile.length(), docFileSizeLimit);
|
log.error("$$$ 目标文档大小超过限制({}B > {}B),无法打开!", docFile.length(), docFileSizeLimit);
|
||||||
|
// throw exception(DOC_FILE_OVERSIZE);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_OVERSIZE);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_OVERSIZE);
|
||||||
}
|
}
|
||||||
String ext = StringUtils.lowerCase(FilenameUtils.getExtension(docFile.getName()));
|
String ext = StringUtils.lowerCase(FilenameUtils.getExtension(docFile.getName()));
|
||||||
if (!ArrayUtils.contains(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ext)) {
|
if (!ArrayUtils.contains(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ext)) {
|
||||||
log.error("$$$ 目标文档格式[{}]不正确,无法打开!(只支持:{})",
|
log.error("$$$ 目标文档格式[{}]不正确,无法打开!(只支持:{})",
|
||||||
ext, StringUtils.join(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ","));
|
ext, StringUtils.join(DocumentConstants.FILE_TYPE_SUPPORT_VIEW, ","));
|
||||||
|
// throw exception(DOC_FILE_TYPE_UNSUPPORTED);
|
||||||
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_TYPE_UNSUPPORTED);
|
// throw new DocumentException(ErrorCodeEnum.DOC_FILE_TYPE_UNSUPPORTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user