fix(文件下载): 文件打包下载内容为空修复
This commit is contained in:
parent
18d0eaff5c
commit
f2d40a8c31
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,8 +18,9 @@ public interface IUserFileService extends IService<UserFile> {
|
||||
|
||||
IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId);
|
||||
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
||||
List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId);
|
||||
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||
void deleteUserFile(String userFileId, Long sessionUserId);
|
||||
|
||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId);
|
||||
|
||||
}
|
||||
|
@ -166,10 +166,11 @@ public class FileController {
|
||||
.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||
userFileService.update(lambdaUpdateWrapper);
|
||||
if (1 == userFile.getIsDir()) {
|
||||
List<UserFile> list = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
|
||||
List<UserFile> list = userFileService.selectUserFileByLikeRightFilePath(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath(), sessionUserBean.getUserId());
|
||||
|
||||
for (UserFile newUserFile : list) {
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(userFile.getFilePath() + userFile.getFileName() + "/", userFile.getFilePath() + renameFileDto.getFileName() + "/"));
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), userFile.getIsDir() == 1).getPath(),
|
||||
new QiwenFile(userFile.getFilePath(), renameFileDto.getFileName(), userFile.getIsDir() == 1).getPath()));
|
||||
userFileService.updateById(newUserFile);
|
||||
}
|
||||
}
|
||||
|
@ -155,11 +155,8 @@ public class FiletransferController {
|
||||
if (userFile.getIsDir() == 0) {
|
||||
userFileIds.add(userFileId);
|
||||
} else {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + QiwenFile.separator + userFile.getFileName())
|
||||
.eq(UserFile::getUserId, userFile.getUserId())
|
||||
.eq(UserFile::getDeleteFlag, 0);
|
||||
List<UserFile> userFileList = userFileService.list(lambdaQueryWrapper);
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
||||
List<UserFile> userFileList = userFileService.selectUserFileByLikeRightFilePath(qiwenFile.getPath(), userFile.getUserId());
|
||||
List<String> userFileIds1 = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
||||
userFileIds.add(userFile.getUserFileId());
|
||||
userFileIds.addAll(userFileIds1);
|
||||
|
@ -81,7 +81,7 @@ public class ShareController {
|
||||
}
|
||||
if (userFile.getIsDir() == 1) {
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
||||
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(qiwenFile.getPath(), sessionUserBean.getUserId());
|
||||
List<UserFile> userfileList = userFileService.selectUserFileByLikeRightFilePath(qiwenFile.getPath(), sessionUserBean.getUserId());
|
||||
for (UserFile userFile1 : userfileList) {
|
||||
ShareFile shareFile1 = new ShareFile();
|
||||
shareFile1.setUserFileId(userFile1.getUserFileId());
|
||||
@ -121,7 +121,7 @@ public class ShareController {
|
||||
String savefileName = fileDealComp.getRepeatFileName(userFile, savefilePath);
|
||||
|
||||
if (userFile.getIsDir() == 1) {
|
||||
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId());
|
||||
List<UserFile> userfileList = userFileService.selectUserFileByLikeRightFilePath(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath(), userFile.getUserId());
|
||||
log.info("查询文件列表:" + JSON.toJSONString(userfileList));
|
||||
String filePath = userFile.getFilePath();
|
||||
userfileList.forEach(p->{
|
||||
|
@ -7,6 +7,8 @@ import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
|
||||
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
||||
@ -22,6 +24,8 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
@Param("newFilePath") String newfilePath,
|
||||
@Param("userId") long userId);
|
||||
|
||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId);
|
||||
|
||||
IPage<FileListVo> selectPageVo(Page<?> page, @Param("userFile") UserFile userFile, @Param("fileTypeId") Integer fileTypeId);
|
||||
Long selectStorageSizeByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
@ -411,7 +411,8 @@ public class FiletransferService implements IFiletransferService {
|
||||
InputStream inputStream = downloader.getInputStream(downloadFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
||||
try {
|
||||
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replaceFirst(filePath, "") + "/" + userFile1.getFileName() + "." + userFile1.getExtendName()));
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile1.getFilePath().replaceFirst(filePath, ""), userFile1.getFileName() + "." + userFile1.getExtendName(), false);
|
||||
zos.putNextEntry(new ZipEntry(qiwenFile.getPath()));
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int i = bis.read(buffer);
|
||||
@ -431,8 +432,9 @@ public class FiletransferService implements IFiletransferService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile1.getFilePath(), userFile1.getFileName(), true);
|
||||
// 空文件夹的处理
|
||||
zos.putNextEntry(new ZipEntry(userFile1.getFilePath() + userFile1.getFileName() + "/"));
|
||||
zos.putNextEntry(new ZipEntry(qiwenFile.getPath() + QiwenFile.separator));
|
||||
// 没有文件,不需要文件的copy
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import com.qiwenshare.common.util.security.SessionUtil;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.domain.RecoveryFile;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.io.QiwenFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.FileTypeMapper;
|
||||
import com.qiwenshare.file.mapper.RecoveryFileMapper;
|
||||
@ -100,11 +101,11 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
|
||||
|
||||
//移动子目录
|
||||
oldfilePath = oldfilePath + "/" + fileName;
|
||||
newfilePath = newfilePath + "/" + fileName;
|
||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||
|
||||
if (StringUtils.isEmpty(extendName)) { //为空说明是目录,则需要移动子目录
|
||||
List<UserFile> list = selectFileListLikeRightFilePath(oldfilePath, userId);
|
||||
List<UserFile> list = selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
||||
|
||||
for (UserFile newUserFile : list) {
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(oldfilePath, newfilePath));
|
||||
@ -127,8 +128,8 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
|
||||
//移动子目录
|
||||
oldfilePath = oldfilePath + "/" + fileName;
|
||||
newfilePath = newfilePath + "/" + fileName;
|
||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||
|
||||
oldfilePath = oldfilePath.replace("\\", "\\\\\\\\");
|
||||
oldfilePath = oldfilePath.replace("'", "\\'");
|
||||
@ -161,23 +162,6 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId) {
|
||||
filePath = filePath.replace("\\", "\\\\\\\\");
|
||||
filePath = filePath.replace("'", "\\'");
|
||||
filePath = filePath.replace("%", "\\%");
|
||||
filePath = filePath.replace("_", "\\_");
|
||||
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
log.info("查询文件路径:" + filePath);
|
||||
|
||||
lambdaQueryWrapper.eq(UserFile::getUserId, userId)
|
||||
.likeRight(UserFile::getFilePath, filePath)
|
||||
.eq(UserFile::getDeleteFlag, 0);
|
||||
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectFilePathTreeByUserId(Long userId) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -200,7 +184,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
.eq(UserFile::getUserFileId, userFileId);
|
||||
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||
|
||||
String filePath = userFile.getFilePath() + "/" + userFile.getFileName();
|
||||
String filePath = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath();
|
||||
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
|
||||
|
||||
}else{
|
||||
@ -222,9 +206,14 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectUserFileByLikeRightFilePath(String filePath, long userId) {
|
||||
return userFileMapper.selectUserFileByLikeRightFilePath(filePath, userId);
|
||||
}
|
||||
|
||||
private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) {
|
||||
executor.execute(() -> {
|
||||
List<UserFile> fileList = selectFileListLikeRightFilePath(filePath, userId);
|
||||
List<UserFile> fileList = selectUserFileByLikeRightFilePath(filePath, userId);
|
||||
for (int i = 0; i < fileList.size(); i++){
|
||||
UserFile userFileTemp = fileList.get(i);
|
||||
//标记删除标志
|
||||
|
@ -42,6 +42,11 @@
|
||||
ORDER BY isDir desc
|
||||
</select>
|
||||
|
||||
<select id="selectUserFileByLikeRightFilePath" resultType="com.qiwenshare.file.domain.UserFile">
|
||||
select * from userfile
|
||||
where (filePath = #{filePath} or filePath like concat(#{filePath},'/%')) and userId = #{userId} and deleteFlag = 0
|
||||
</select>
|
||||
|
||||
|
||||
<update id="updateFilepathByFilepath">
|
||||
UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||
|
Loading…
Reference in New Issue
Block a user