fix(文件查询): like查询路径处理
This commit is contained in:
parent
bfccdde717
commit
d6b101e56d
@ -170,7 +170,7 @@ public class FileDealComp {
|
||||
LambdaQueryWrapper<UserFile> 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)
|
||||
|
@ -51,6 +51,7 @@ public class QiwenFile {
|
||||
int length = path.length();
|
||||
return path.substring(0, length - 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -11,18 +11,8 @@ import java.util.List;
|
||||
|
||||
public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
|
||||
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<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId);
|
||||
|
||||
|
@ -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<UserFile> 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<UserFile> userFileList = userFileMapper.selectList(lambdaQueryWrapper);
|
||||
|
@ -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<UserFileMapper, UserFile> impl
|
||||
|
||||
if (extendName == null) { //为null说明是目录,则需要移动子目录
|
||||
QueryWrapper<UserFile> subQueryWrapper = new QueryWrapper<UserFile>();
|
||||
subQueryWrapper.likeRight("filePath", oldfilePath);
|
||||
subQueryWrapper.likeRight("filePath", QiwenFileUtil.formatLikePath(oldfilePath));
|
||||
subQueryWrapper.eq("userId", userId);
|
||||
List<UserFile> subUserFileList = userFileMapper.selectList(subQueryWrapper);
|
||||
for (UserFile userFile : subUserFileList) {
|
||||
@ -245,7 +243,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
@Override
|
||||
public List<UserFile> 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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,65 +47,6 @@
|
||||
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})
|
||||
WHERE filePath like N'${param1}%' and userId = #{param3}
|
||||
</update>
|
||||
|
||||
<update id="updateFilepathByPathAndName">
|
||||
update userfile set filePath = #{param2}
|
||||
where filePath = #{param1} and fileName = #{param3}
|
||||
<if test="param4 != null">
|
||||
and extendName = #{param4}
|
||||
</if>
|
||||
<if test="param4 == null">
|
||||
and extendName is null
|
||||
</if>
|
||||
and userId = #{param5}
|
||||
</update>
|
||||
|
||||
<insert id="batchInsertByPathAndName">
|
||||
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
|
||||
<where>
|
||||
<if test="userId != 0">
|
||||
and userId = #{userId}
|
||||
</if>
|
||||
<if test="fileName != null">
|
||||
and fileName = #{fileName}
|
||||
</if>
|
||||
<if test="oldFilePath != null">
|
||||
and filePath = #{oldFilePath}
|
||||
</if>
|
||||
<choose>
|
||||
<when test="extendName != null">
|
||||
and extendName = #{extendName}
|
||||
</when>
|
||||
<otherwise>
|
||||
and isDir = 1
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="batchInsertByFilepath">
|
||||
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}
|
||||
)
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectStorageSizeByUserId" resultType="java.lang.Long" parameterType="java.lang.Long">
|
||||
SELECT SUM(fileSize) FROM userfile
|
||||
LEFT JOIN file ON file.fileId = userfile.fileId
|
||||
|
Loading…
Reference in New Issue
Block a user