移动文件区分用户

This commit is contained in:
马超 2021-04-07 18:36:36 +08:00
parent fb01636722
commit e165b3d5cc
5 changed files with 15 additions and 11 deletions

View File

@ -13,7 +13,7 @@ public interface IUserFileService extends IService<UserFile> {
List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId); List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId);
void replaceUserFilePath(String filePath, String oldFilePath, Long userId); void replaceUserFilePath(String filePath, String oldFilePath, Long userId);
List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount); List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount);
void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName); void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
List<FileListVo> selectFileByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId); List<FileListVo> selectFileByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId); Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);

View File

@ -394,12 +394,14 @@ public class FileController {
if (!operationCheck(token).getSuccess()){ if (!operationCheck(token).getSuccess()){
return operationCheck(token); return operationCheck(token);
} }
UserBean sessionUserBean = userService.getUserBeanByToken(token);
String oldfilePath = moveFileDto.getOldFilePath(); String oldfilePath = moveFileDto.getOldFilePath();
String newfilePath = moveFileDto.getFilePath(); String newfilePath = moveFileDto.getFilePath();
String fileName = moveFileDto.getFileName(); String fileName = moveFileDto.getFileName();
String extendName = moveFileDto.getExtendName(); String extendName = moveFileDto.getExtendName();
userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName); userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
return RestResult.success(); return RestResult.success();
} }
@ -413,6 +415,7 @@ public class FileController {
if (!operationCheck(token).getSuccess()) { if (!operationCheck(token).getSuccess()) {
return operationCheck(token); return operationCheck(token);
} }
UserBean sessionUserBean = userService.getUserBeanByToken(token);
String files = batchMoveFileDto.getFiles(); String files = batchMoveFileDto.getFiles();
String newfilePath = batchMoveFileDto.getFilePath(); String newfilePath = batchMoveFileDto.getFilePath();
@ -420,7 +423,7 @@ public class FileController {
List<UserFile> fileList = JSON.parseArray(files, UserFile.class); List<UserFile> fileList = JSON.parseArray(files, UserFile.class);
for (UserFile userFile : fileList) { for (UserFile userFile : fileList) {
userFileService.updateFilepathByFilepath(userFile.getFilePath(), newfilePath, userFile.getFileName(), userFile.getExtendName()); userFileService.updateFilepathByFilepath(userFile.getFilePath(), newfilePath, userFile.getFileName(), userFile.getExtendName(), sessionUserBean.getUserId());
} }
return RestResult.success().data("批量移动文件成功"); return RestResult.success().data("批量移动文件成功");

View File

@ -14,12 +14,12 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("userId") Long userId); void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("userId") Long userId);
List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount); List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount);
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName); void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
void updateFilepathByFilepath(String oldfilePath, String newfilePath); void updateFilepathByFilepath(String oldfilePath, String newfilePath, long userId);
List<FileListVo> selectFileByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId); List<FileListVo> selectFileByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId); Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
List<FileListVo> selectFileNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId); List<FileListVo> selectFileNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
Long selectCountNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId); Long selectCountNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
Long selectStorageSizeByUserId(Long userId); Long selectStorageSizeByUserId(@Param("userId") Long userId);
} }

View File

@ -108,12 +108,12 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
// } // }
@Override @Override
public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName) { public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) {
if ("null".equals(extendName)){ if ("null".equals(extendName)){
extendName = null; extendName = null;
} }
//移动根目录 //移动根目录
userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName); userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
//移动子目录 //移动子目录
oldfilePath = oldfilePath + fileName + "/"; oldfilePath = oldfilePath + fileName + "/";
@ -125,7 +125,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
oldfilePath = oldfilePath.replace("_", "\\_"); oldfilePath = oldfilePath.replace("_", "\\_");
if (extendName == null) { //为null说明是目录则需要移动子目录 if (extendName == null) { //为null说明是目录则需要移动子目录
userFileMapper.updateFilepathByFilepath(oldfilePath, newfilePath); userFileMapper.updateFilepathByFilepath(oldfilePath, newfilePath, userId);
} }
} }

View File

@ -73,7 +73,7 @@
<update id="updateFilepathByFilepath"> <update id="updateFilepathByFilepath">
UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2}) UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2})
WHERE filePath like N'${param1}%' WHERE filePath like N'${param1}%' and userId = #{param3}
</update> </update>
<update id="updateFilepathByPathAndName"> <update id="updateFilepathByPathAndName">
@ -85,12 +85,13 @@
<if test="param4 == null"> <if test="param4 == null">
and extendName is null and extendName is null
</if> </if>
and userId = #{param5}
</update> </update>
<select id="selectStorageSizeByUserId" resultType="java.lang.Long" parameterType="java.lang.Long"> <select id="selectStorageSizeByUserId" resultType="java.lang.Long" parameterType="java.lang.Long">
SELECT SUM(fileSize) FROM userfile SELECT SUM(fileSize) FROM userfile
LEFT JOIN file ON file.fileId = userfile.fileId LEFT JOIN file ON file.fileId = userfile.fileId
WHERE userfile.userId = 2 WHERE userfile.userId = #{userId}
</select> </select>
</mapper> </mapper>