|
@@ -446,14 +446,10 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
|
- filePath = SystemConstant.getLocalFilePath(hostUrl, filePath);
|
|
|
|
- if (filePath.startsWith(SystemConstant.ORG_SPLIT)) {
|
|
|
|
- url = hostUrl + filePath;
|
|
|
|
- } else {
|
|
|
|
- url = hostUrl + File.separator + filePath;
|
|
|
|
- }
|
|
|
|
|
|
+ if (filePath.contains(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
+ url = filePath.substring(filePath.indexOf(dictionaryConfig.fssLocalFileDomain().getServer()), filePath.length());
|
|
|
|
+ } else if (filePath.contains(dictionaryConfig.fssLocalPdfDomain().getServer())) {
|
|
|
|
+ url = filePath.substring(filePath.indexOf(dictionaryConfig.fssLocalPdfDomain().getServer()), filePath.length());
|
|
} else {
|
|
} else {
|
|
UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
@@ -481,23 +477,15 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
}
|
|
}
|
|
String pathUrl;
|
|
String pathUrl;
|
|
if (Objects.equals(type, SystemConstant.LOCAL)) {
|
|
if (Objects.equals(type, SystemConstant.LOCAL)) {
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
|
- path = SystemConstant.getLocalFilePath(hostUrl, path);
|
|
|
|
- if (path.startsWith(SystemConstant.ORG_SPLIT)) {
|
|
|
|
- pathUrl = hostUrl + path;
|
|
|
|
- } else {
|
|
|
|
- pathUrl = hostUrl + File.separator + path;
|
|
|
|
- }
|
|
|
|
|
|
+ if (path.contains(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
+ pathUrl = path.substring(path.indexOf(dictionaryConfig.fssLocalFileDomain().getServer()), path.length());
|
|
|
|
+ } else if (path.contains(dictionaryConfig.fssLocalPdfDomain().getServer())) {
|
|
|
|
+ pathUrl = path.substring(path.indexOf(dictionaryConfig.fssLocalPdfDomain().getServer()), path.length());
|
|
} else {
|
|
} else {
|
|
pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (isExpire) {
|
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
|
- } else {
|
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
|
- }
|
|
|
|
|
|
+ pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
}
|
|
}
|
|
return pathUrl;
|
|
return pathUrl;
|
|
}
|
|
}
|
|
@@ -525,14 +513,10 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
UploadFileEnum uploadFileEnum = jsonObject.get(SystemConstant.UPLOAD_TYPE).toString().contains(UploadFileEnum.HTML.name()) ? UploadFileEnum.HTML : UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
UploadFileEnum uploadFileEnum = jsonObject.get(SystemConstant.UPLOAD_TYPE).toString().contains(UploadFileEnum.HTML.name()) ? UploadFileEnum.HTML : UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
|
|
if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
|
- filePath = SystemConstant.getLocalFilePath(hostUrl, filePath);
|
|
|
|
- if (filePath.startsWith(SystemConstant.ORG_SPLIT)) {
|
|
|
|
- pathUrl = hostUrl + filePath;
|
|
|
|
- } else {
|
|
|
|
- pathUrl = hostUrl + File.separator + filePath;
|
|
|
|
- }
|
|
|
|
|
|
+ if (filePath.contains(dictionaryConfig.fssLocalFileDomain().getServer())) {
|
|
|
|
+ pathUrl = filePath.substring(filePath.indexOf(dictionaryConfig.fssLocalFileDomain().getServer()), filePath.length());
|
|
|
|
+ } else if (filePath.contains(dictionaryConfig.fssLocalPdfDomain().getServer())) {
|
|
|
|
+ pathUrl = filePath.substring(filePath.indexOf(dictionaryConfig.fssLocalPdfDomain().getServer()), filePath.length());
|
|
} else {
|
|
} else {
|
|
pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
}
|
|
}
|
|
@@ -605,7 +589,6 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
Optional.ofNullable(filePath).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_IS_NULL.exception("附件路径不存在"));
|
|
Optional.ofNullable(filePath).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_IS_NULL.exception("附件路径不存在"));
|
|
|
|
|
|
UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
- StringJoiner localPath = new StringJoiner("");
|
|
|
|
if (Objects.equals(attachmentType, SystemConstant.OSS)) {
|
|
if (Objects.equals(attachmentType, SystemConstant.OSS)) {
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
|
|
File fileTemp = SystemConstant.getFileTempVar(suffix);
|
|
File fileTemp = SystemConstant.getFileTempVar(suffix);
|
|
@@ -634,7 +617,6 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
File localPath = new File(rootPath, fileName);
|
|
File localPath = new File(rootPath, fileName);
|
|
if (type.equals(SystemConstant.OSS)) {
|
|
if (type.equals(SystemConstant.OSS)) {
|
|
try {
|
|
try {
|
|
-// File file = ossUtil.ossDownload(filePath, localPath.getPath());
|
|
|
|
File file = fileStoreUtil.ossDownload(filePath, localPath.getPath(), uploadType.getFssType());
|
|
File file = fileStoreUtil.ossDownload(filePath, localPath.getPath(), uploadType.getFssType());
|
|
return file;
|
|
return file;
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -656,22 +638,9 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, List<File> files) {
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, List<File> files) {
|
|
- String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
|
|
|
|
- long time = System.nanoTime();
|
|
|
|
- File rootFile = new File(rootPath);
|
|
|
|
- // 创建保存目录
|
|
|
|
- if (!rootFile.exists()) {
|
|
|
|
- rootFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- File zipFile = null;
|
|
|
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
|
+ File zipFile = SystemConstant.getFileTempDirVar(System.currentTimeMillis() + SystemConstant.ZIP_PREFIX, null);
|
|
try {
|
|
try {
|
|
- String zipPath = null;
|
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
|
- zipPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + schoolId;
|
|
|
|
- } else {
|
|
|
|
- zipPath = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + schoolId;
|
|
|
|
- }
|
|
|
|
- zipFile = FileUtil.file(zipPath, time + SystemConstant.ZIP_PREFIX);
|
|
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), files, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), files, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -692,22 +661,9 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, String zipRootPath) {
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, String zipRootPath) {
|
|
- String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
|
|
|
|
- long time = System.nanoTime();
|
|
|
|
- File rootFile = new File(rootPath);
|
|
|
|
- // 创建保存目录
|
|
|
|
- if (!rootFile.exists()) {
|
|
|
|
- rootFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- File zipFile = null;
|
|
|
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
|
+ File zipFile = SystemConstant.getFileTempDirVar(time + SystemConstant.ZIP_PREFIX, null);
|
|
try {
|
|
try {
|
|
- String zipPath = null;
|
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
|
- zipPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + schoolId;
|
|
|
|
- } else {
|
|
|
|
- zipPath = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + schoolId;
|
|
|
|
- }
|
|
|
|
- zipFile = FileUtil.file(zipPath, time + SystemConstant.ZIP_PREFIX);
|
|
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -722,18 +678,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, long time) {
|
|
public void downloadFileAndZip(HttpServletResponse response, String rootPath, long time) {
|
|
- File rootFile = new File(rootPath);
|
|
|
|
- // 创建保存目录
|
|
|
|
- if (!rootFile.exists()) {
|
|
|
|
- rootFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- File zipFile = null;
|
|
|
|
|
|
+ File zipFile = SystemConstant.getFileTempDirVar(time + SystemConstant.ZIP_PREFIX, null);
|
|
try {
|
|
try {
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
|
- zipFile = FileUtil.file(dictionaryConfig.fssLocalFileDomain().getConfig(), time + SystemConstant.ZIP_PREFIX);
|
|
|
|
- } else {
|
|
|
|
- zipFile = FileUtil.file(dictionaryConfig.fssPublicDomain().getConfig(), time + SystemConstant.ZIP_PREFIX);
|
|
|
|
- }
|
|
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), rootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
Zip4jUtil.zipEncryptFile(zipFile.getPath(), rootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
outputFile(response, zipFile, String.valueOf(time));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|