From d6b101e56d9f2311c33aaf5a3ba34e9b5427684a Mon Sep 17 00:00:00 2001 From: MAC <1162714483@qq.com> Date: Sun, 8 May 2022 13:53:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=96=87=E4=BB=B6=E6=9F=A5=E8=AF=A2):=20li?= =?UTF-8?q?ke=E6=9F=A5=E8=AF=A2=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/component/FileDealComp.java | 2 +- .../com/qiwenshare/file/io/QiwenFile.java | 1 + .../file/mapper/UserFileMapper.java | 10 ---- .../file/service/FiletransferService.java | 5 +- .../file/service/UserFileService.java | 8 +-- .../qiwenshare/file/util/QiwenFileUtil.java | 7 +++ src/main/resources/mapper/UserFileMapper.xml | 59 ------------------- 7 files changed, 15 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/qiwenshare/file/component/FileDealComp.java b/src/main/java/com/qiwenshare/file/component/FileDealComp.java index 5af0f25..ec2743a 100644 --- a/src/main/java/com/qiwenshare/file/component/FileDealComp.java +++ b/src/main/java/com/qiwenshare/file/component/FileDealComp.java @@ -170,7 +170,7 @@ public class FileDealComp { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.select(UserFile::getFileName, UserFile::getFilePath) - .likeRight(UserFile::getFilePath, filePath) + .likeRight(UserFile::getFilePath, QiwenFileUtil.formatLikePath(filePath)) .eq(UserFile::getIsDir, 1) .eq(UserFile::getDeleteFlag, 0) .eq(UserFile::getUserId, sessionUserId) diff --git a/src/main/java/com/qiwenshare/file/io/QiwenFile.java b/src/main/java/com/qiwenshare/file/io/QiwenFile.java index 1ef17b0..53719da 100644 --- a/src/main/java/com/qiwenshare/file/io/QiwenFile.java +++ b/src/main/java/com/qiwenshare/file/io/QiwenFile.java @@ -51,6 +51,7 @@ public class QiwenFile { int length = path.length(); return path.substring(0, length - 1); } + return path; } diff --git a/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java b/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java index 16d39ff..780ed7c 100644 --- a/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java +++ b/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java @@ -11,18 +11,8 @@ import java.util.List; public interface UserFileMapper extends BaseMapper { - void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId); - void updateFilepathByFilepath(String oldfilePath, String newfilePath, long userId); - void batchInsertByPathAndName(@Param("oldFilePath") String oldFilePath, - @Param("newFilePath") String newfilePath, - @Param("fileName") String fileName, - @Param("extendName") String extendName, - @Param("userId") long userId); - void batchInsertByFilepath(@Param("oldFilePath") String oldFilePath, - @Param("newFilePath") String newfilePath, - @Param("userId") long userId); List selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId); diff --git a/src/main/java/com/qiwenshare/file/service/FiletransferService.java b/src/main/java/com/qiwenshare/file/service/FiletransferService.java index 58f768f..ef2bc8c 100644 --- a/src/main/java/com/qiwenshare/file/service/FiletransferService.java +++ b/src/main/java/com/qiwenshare/file/service/FiletransferService.java @@ -248,7 +248,7 @@ public class FiletransferService implements IFiletransferService { if (mp3file.hasId3v1Tag()) { ID3v1 id3v1Tag = mp3file.getId3v1Tag(); music.setTrack(formatChatset(id3v1Tag.getTrack())); - music.setArtist(formatChatset(id3v1Tag.getTrack())); + music.setArtist(formatChatset(id3v1Tag.getArtist())); music.setTitle(formatChatset(id3v1Tag.getTitle())); music.setAlbum(formatChatset(id3v1Tag.getAlbum())); music.setYear(formatChatset(id3v1Tag.getYear())); @@ -364,8 +364,9 @@ public class FiletransferService implements IFiletransferService { httpServletResponse.setContentLengthLong(fileBean.getFileSize()); downloader.download(httpServletResponse, downloadFile); } else { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + "/" + userFile.getFileName()) + lambdaQueryWrapper.likeRight(UserFile::getFilePath, QiwenFileUtil.formatLikePath(userFile.getFilePath() + "/" + userFile.getFileName())) .eq(UserFile::getUserId, userFile.getUserId()) .eq(UserFile::getDeleteFlag, 0); List userFileList = userFileMapper.selectList(lambdaQueryWrapper); diff --git a/src/main/java/com/qiwenshare/file/service/UserFileService.java b/src/main/java/com/qiwenshare/file/service/UserFileService.java index a86862c..b7258ad 100644 --- a/src/main/java/com/qiwenshare/file/service/UserFileService.java +++ b/src/main/java/com/qiwenshare/file/service/UserFileService.java @@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qiwenshare.common.constant.FileConstant; -import com.qiwenshare.common.exception.QiwenException; import com.qiwenshare.common.util.DateUtil; import com.qiwenshare.common.util.security.JwtUser; import com.qiwenshare.common.util.security.SessionUtil; @@ -23,6 +22,7 @@ import com.qiwenshare.file.mapper.FileMapper; import com.qiwenshare.file.mapper.FileTypeMapper; import com.qiwenshare.file.mapper.RecoveryFileMapper; import com.qiwenshare.file.mapper.UserFileMapper; +import com.qiwenshare.file.util.QiwenFileUtil; import com.qiwenshare.file.vo.file.FileListVo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -31,12 +31,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import java.util.stream.Collectors; @Slf4j @Service @@ -164,7 +162,7 @@ public class UserFileService extends ServiceImpl impl if (extendName == null) { //为null说明是目录,则需要移动子目录 QueryWrapper subQueryWrapper = new QueryWrapper(); - subQueryWrapper.likeRight("filePath", oldfilePath); + subQueryWrapper.likeRight("filePath", QiwenFileUtil.formatLikePath(oldfilePath)); subQueryWrapper.eq("userId", userId); List subUserFileList = userFileMapper.selectList(subQueryWrapper); for (UserFile userFile : subUserFileList) { @@ -245,7 +243,7 @@ public class UserFileService extends ServiceImpl impl @Override public List selectUserFileByLikeRightFilePath(String filePath, long userId) { - return userFileMapper.selectUserFileByLikeRightFilePath(filePath, userId); + return userFileMapper.selectUserFileByLikeRightFilePath(QiwenFileUtil.formatLikePath(filePath), userId); } private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) { diff --git a/src/main/java/com/qiwenshare/file/util/QiwenFileUtil.java b/src/main/java/com/qiwenshare/file/util/QiwenFileUtil.java index 73ef5bd..a8d9bff 100644 --- a/src/main/java/com/qiwenshare/file/util/QiwenFileUtil.java +++ b/src/main/java/com/qiwenshare/file/util/QiwenFileUtil.java @@ -49,4 +49,11 @@ public class QiwenFileUtil { return param; } + public static String formatLikePath(String filePath) { + String newFilePath = filePath.replace("'", "\\'"); + newFilePath = newFilePath.replace("%", "\\%"); + newFilePath = newFilePath.replace("_", "\\_"); + return newFilePath; + } + } diff --git a/src/main/resources/mapper/UserFileMapper.xml b/src/main/resources/mapper/UserFileMapper.xml index 02f1f01..62adfeb 100644 --- a/src/main/resources/mapper/UserFileMapper.xml +++ b/src/main/resources/mapper/UserFileMapper.xml @@ -47,65 +47,6 @@ where (filePath = #{filePath} or filePath like concat(#{filePath},'/%')) and userId = #{userId} and deleteFlag = 0 - - - UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2}) - WHERE filePath like N'${param1}%' and userId = #{param3} - - - - update userfile set filePath = #{param2} - where filePath = #{param1} and fileName = #{param3} - - and extendName = #{param4} - - - and extendName is null - - and userId = #{param5} - - - - insert into userfile ( deleteBatchNum, deleteFlag, deleteTime, - extendName, fileId, fileName, filePath, isDir, uploadTime, userId) - (select deleteBatchNum, deleteFlag, deleteTime, extendName, fileId, - fileName, #{newFilePath}, isDir, uploadTime, userId - from userfile - - - and userId = #{userId} - - - and fileName = #{fileName} - - - and filePath = #{oldFilePath} - - - - and extendName = #{extendName} - - - and isDir = 1 - - - - - ) - - - - insert into userfile ( deleteBatchNum, deleteFlag, deleteTime, - extendName, fileId, fileName, filePath, isDir, uploadTime, userId) - (select deleteBatchNum, deleteFlag, deleteTime, extendName, fileId, - fileName, REPLACE(filePath, #{oldFilePath}, #{newFilePath}), isDir, - uploadTime, userId - from userfile - where filePath like N'${oldFilePath}%' and userId = #{userId} - ) - - -