!114 代码合并

Merge pull request !114 from MAC/develop
This commit is contained in:
MAC 2022-04-14 14:41:35 +00:00 committed by Gitee
commit ee48f1d594
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 39 additions and 33 deletions

View File

@ -168,15 +168,15 @@ public class FiletransferController {
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/")
.eq(UserFile::getUserId, userFile.getUserId())
.eq(UserFile::getIsDir, 0)
.eq(UserFile::getDeleteFlag, 0);
List<UserFile> userFileList = userFileService.list(lambdaQueryWrapper);
List<Long> userFileIds1 = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
userFileIds.add(userFile.getUserFileId());
userFileIds.addAll(userFileIds1);
}
}
UserFile userFile = userFileService.getById(userFileIds.get(0));
UserFile userFile = userFileService.getById(Integer.parseInt(userFileIdStrs[0]));
httpServletResponse.setContentType("application/force-download");// 设置强制下载不打开
Date date = new Date();
String fileName = String.valueOf(date.getTime());

View File

@ -42,6 +42,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
@ -97,6 +98,7 @@ public class OfficeController {
templateFilePath = "template/PowerPoint.pptx";
}
String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
url2 = URLDecoder.decode(url2, "UTF-8");
FileInputStream fileInputStream = new FileInputStream(url2);
Copier copier = ufopFactory.getCopier();
CopyFile copyFile = new CopyFile();

View File

@ -32,6 +32,7 @@ import com.qiwenshare.ufop.operation.upload.domain.UploadFile;
import com.qiwenshare.ufop.operation.upload.domain.UploadFileResult;
import com.qiwenshare.ufop.util.UFOPUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -287,7 +288,6 @@ public class FiletransferService implements IFiletransferService {
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/")
.eq(UserFile::getUserId, userFile.getUserId())
.eq(UserFile::getIsDir, 0)
.eq(UserFile::getDeleteFlag, 0);
List<UserFile> userFileList = userFileMapper.selectList(lambdaQueryWrapper);
List<Long> userFileIds = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
@ -318,42 +318,46 @@ public class FiletransferService implements IFiletransferService {
try {
for (Long userFileId : userFileIds) {
UserFile userFile1 = userFileMapper.selectById(userFileId);
FileBean fileBean = fileMapper.selectById(userFile1.getFileId());
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
if (downloader == null) {
log.error("下载失败文件存储类型不支持下载storageType:{}", fileBean.getStorageType());
throw new UploadException("下载失败");
}
DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileUrl(fileBean.getFileUrl());
downloadFile.setFileSize(fileBean.getFileSize());
InputStream inputStream = downloader.getInputStream(downloadFile);
BufferedInputStream bis = new BufferedInputStream(inputStream);
try {
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(filePath, "/") + userFile1.getFileName() + "." + userFile1.getExtendName()));
if (userFile1.getIsDir() == 0) {
FileBean fileBean = fileMapper.selectById(userFile1.getFileId());
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
if (downloader == null) {
log.error("下载失败文件存储类型不支持下载storageType:{}", fileBean.getStorageType());
throw new UploadException("下载失败");
}
DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileUrl(fileBean.getFileUrl());
downloadFile.setFileSize(fileBean.getFileSize());
InputStream inputStream = downloader.getInputStream(downloadFile);
BufferedInputStream bis = new BufferedInputStream(inputStream);
try {
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(filePath, "/") + userFile1.getFileName() + "." + userFile1.getExtendName()));
byte[] buffer = new byte[1024];
int i = bis.read(buffer);
while (i != -1) {
out.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (IOException e) {
log.error("" + e);
e.printStackTrace();
} finally {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
out.flush();
byte[] buffer = new byte[1024];
int i = bis.read(buffer);
while (i != -1) {
out.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (IOException e) {
log.error("" + e);
e.printStackTrace();
} finally {
IOUtils.closeQuietly(bis);
try {
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
// 空文件夹的处理
zos.putNextEntry(new ZipEntry(userFile1.getFilePath() + userFile1.getFileName() + "/"));
// 没有文件不需要文件的copy
zos.closeEntry();
}
}
} catch (Exception e) {
log.error("压缩过程中出现异常:"+ e);
} finally {