云文件系统初始化
This commit is contained in:
@@ -19,6 +19,9 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -242,8 +245,12 @@ public class FileController {
|
||||
public ResponseEntity<?> moveFile(
|
||||
@AuthenticationPrincipal UserPrincipal principal,
|
||||
@PathVariable Long id,
|
||||
@RequestBody Map<String, Long> request) {
|
||||
Long folderId = request.get("folderId");
|
||||
@RequestBody Map<String, Object> request) {
|
||||
Object folderIdObj = request.get("folderId");
|
||||
Long folderId = null;
|
||||
if (folderIdObj != null && !folderIdObj.toString().isEmpty() && !"null".equals(folderIdObj.toString()) && !"undefined".equals(folderIdObj.toString())) {
|
||||
folderId = Long.parseLong(folderIdObj.toString());
|
||||
}
|
||||
try {
|
||||
fileService.moveFile(id, principal.getUserId(), folderId);
|
||||
return ResponseEntity.ok(Map.of("message", "移动成功"));
|
||||
@@ -255,10 +262,25 @@ public class FileController {
|
||||
@PostMapping("/batchDownload")
|
||||
public ResponseEntity<?> batchDownload(
|
||||
@AuthenticationPrincipal UserPrincipal principal,
|
||||
@RequestBody Map<String, List<Long>> request,
|
||||
@RequestBody Map<String, Object> request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<Long> ids = request.get("ids");
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
Object idsObj = request.get("ids");
|
||||
if (idsObj == null) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "请选择要下载的文件"));
|
||||
}
|
||||
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if (idsObj instanceof List) {
|
||||
for (Object id : (List<?>) idsObj) {
|
||||
if (id instanceof Number) {
|
||||
ids.add(((Number) id).longValue());
|
||||
} else if (id instanceof String) {
|
||||
ids.add(Long.parseLong((String) id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "请选择要下载的文件"));
|
||||
}
|
||||
|
||||
@@ -280,8 +302,9 @@ public class FileController {
|
||||
@GetMapping("/movableFolders")
|
||||
public ResponseEntity<?> getMovableFolders(
|
||||
@AuthenticationPrincipal UserPrincipal principal,
|
||||
@RequestParam(required = false) List<Long> excludeIds) {
|
||||
List<FileEntity> folders = fileService.getMovableFolders(principal.getUserId(), excludeIds);
|
||||
@RequestParam(required = false) List<Long> excludeIds,
|
||||
@RequestParam(required = false) Long currentFolderId) {
|
||||
List<FileEntity> folders = fileService.getMovableFolders(principal.getUserId(), excludeIds, currentFolderId);
|
||||
return ResponseEntity.ok(Map.of("data", folders));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +497,12 @@ public class FileService {
|
||||
}
|
||||
|
||||
file.setFolderId(targetFolderId);
|
||||
fileMapper.updateById(file);
|
||||
// 使用直接更新确保 null 值也能被设置
|
||||
fileMapper.update(null,
|
||||
new LambdaUpdateWrapper<FileEntity>()
|
||||
.eq(FileEntity::getId, fileId)
|
||||
.set(FileEntity::getFolderId, targetFolderId)
|
||||
);
|
||||
}
|
||||
|
||||
public byte[] createZipArchive(List<Long> fileIds, Long userId) throws IOException {
|
||||
@@ -558,12 +563,19 @@ public class FileService {
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
public List<FileEntity> getMovableFolders(Long userId, List<Long> excludeIds) {
|
||||
public List<FileEntity> getMovableFolders(Long userId, List<Long> excludeIds, Long currentFolderId) {
|
||||
LambdaQueryWrapper<FileEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(FileEntity::getUserId, userId)
|
||||
.eq(FileEntity::getIsDeleted, 0)
|
||||
.eq(FileEntity::getIsFolder, 1);
|
||||
|
||||
// 只查询当前目录下的文件夹(同级)
|
||||
if (currentFolderId == null) {
|
||||
wrapper.isNull(FileEntity::getFolderId);
|
||||
} else {
|
||||
wrapper.eq(FileEntity::getFolderId, currentFolderId);
|
||||
}
|
||||
|
||||
if (excludeIds != null && !excludeIds.isEmpty()) {
|
||||
wrapper.notIn(FileEntity::getId, excludeIds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user