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

View File

@ -42,6 +42,7 @@ import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.UUID; import java.util.UUID;
@ -97,6 +98,7 @@ public class OfficeController {
templateFilePath = "template/PowerPoint.pptx"; templateFilePath = "template/PowerPoint.pptx";
} }
String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath(); String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
url2 = URLDecoder.decode(url2, "UTF-8");
FileInputStream fileInputStream = new FileInputStream(url2); FileInputStream fileInputStream = new FileInputStream(url2);
Copier copier = ufopFactory.getCopier(); Copier copier = ufopFactory.getCopier();
CopyFile copyFile = new CopyFile(); 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.operation.upload.domain.UploadFileResult;
import com.qiwenshare.ufop.util.UFOPUtils; import com.qiwenshare.ufop.util.UFOPUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -287,7 +288,6 @@ public class FiletransferService implements IFiletransferService {
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/") lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/")
.eq(UserFile::getUserId, userFile.getUserId()) .eq(UserFile::getUserId, userFile.getUserId())
.eq(UserFile::getIsDir, 0)
.eq(UserFile::getDeleteFlag, 0); .eq(UserFile::getDeleteFlag, 0);
List<UserFile> userFileList = userFileMapper.selectList(lambdaQueryWrapper); List<UserFile> userFileList = userFileMapper.selectList(lambdaQueryWrapper);
List<Long> userFileIds = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList()); List<Long> userFileIds = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
@ -318,42 +318,46 @@ public class FiletransferService implements IFiletransferService {
try { try {
for (Long userFileId : userFileIds) { for (Long userFileId : userFileIds) {
UserFile userFile1 = userFileMapper.selectById(userFileId); UserFile userFile1 = userFileMapper.selectById(userFileId);
FileBean fileBean = fileMapper.selectById(userFile1.getFileId()); if (userFile1.getIsDir() == 0) {
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType()); FileBean fileBean = fileMapper.selectById(userFile1.getFileId());
if (downloader == null) { Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
log.error("下载失败文件存储类型不支持下载storageType:{}", fileBean.getStorageType()); if (downloader == null) {
throw new UploadException("下载失败"); log.error("下载失败文件存储类型不支持下载storageType:{}", fileBean.getStorageType());
} throw new UploadException("下载失败");
DownloadFile downloadFile = new DownloadFile(); }
downloadFile.setFileUrl(fileBean.getFileUrl()); DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileSize(fileBean.getFileSize()); downloadFile.setFileUrl(fileBean.getFileUrl());
InputStream inputStream = downloader.getInputStream(downloadFile); downloadFile.setFileSize(fileBean.getFileSize());
BufferedInputStream bis = new BufferedInputStream(inputStream); InputStream inputStream = downloader.getInputStream(downloadFile);
try { BufferedInputStream bis = new BufferedInputStream(inputStream);
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(filePath, "/") + userFile1.getFileName() + "." + userFile1.getExtendName())); try {
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(filePath, "/") + userFile1.getFileName() + "." + userFile1.getExtendName()));
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int i = bis.read(buffer); int i = bis.read(buffer);
while (i != -1) { while (i != -1) {
out.write(buffer, 0, i); out.write(buffer, 0, i);
i = bis.read(buffer); i = bis.read(buffer);
} }
} catch (IOException e) {
log.error("" + e);
e.printStackTrace();
} finally {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
out.flush();
} catch (IOException e) { } catch (IOException e) {
log.error("" + e);
e.printStackTrace(); 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) { } catch (Exception e) {
log.error("压缩过程中出现异常:"+ e); log.error("压缩过程中出现异常:"+ e);
} finally { } finally {