diff --git a/src/main/java/com/jmal/clouddisk/controller/rest/FileController.java b/src/main/java/com/jmal/clouddisk/controller/rest/FileController.java index 7dd10b0c..afad9552 100644 --- a/src/main/java/com/jmal/clouddisk/controller/rest/FileController.java +++ b/src/main/java/com/jmal/clouddisk/controller/rest/FileController.java @@ -323,7 +323,7 @@ public ResponseResult unFavorite(@RequestParam String[] fileIds) { public ResponseResult delete(@RequestParam String username, @RequestParam String[] fileIds, @RequestParam String currentDirectory) { if (fileIds != null && fileIds.length > 0) { List list = Arrays.asList(fileIds); - return fileService.delete(username, currentDirectory, list, userLoginHolder.getUsername()); + return fileService.delete(username, currentDirectory, list, userLoginHolder.getUsername(), false); } else { throw new CommonException(ExceptionType.MISSING_PARAMETERS.getCode(), ExceptionType.MISSING_PARAMETERS.getMsg()); } diff --git a/src/main/java/com/jmal/clouddisk/service/IFileService.java b/src/main/java/com/jmal/clouddisk/service/IFileService.java index ba52a0e6..453c30fe 100644 --- a/src/main/java/com/jmal/clouddisk/service/IFileService.java +++ b/src/main/java/com/jmal/clouddisk/service/IFileService.java @@ -171,9 +171,10 @@ public interface IFileService { * @param currentDirectory 当前目录 * @param fileIds 文件id * @param operator 操作者 + * @param sweep 是否彻底删除 * @return ResponseResult */ - ResponseResult delete(String username, String currentDirectory, List fileIds, String operator); + ResponseResult delete(String username, String currentDirectory, List fileIds, String operator, boolean sweep); /** * 显示缩略图 diff --git a/src/main/java/com/jmal/clouddisk/service/impl/FileServiceImpl.java b/src/main/java/com/jmal/clouddisk/service/impl/FileServiceImpl.java index 43c4b8e7..a7c9bf33 100644 --- a/src/main/java/com/jmal/clouddisk/service/impl/FileServiceImpl.java +++ b/src/main/java/com/jmal/clouddisk/service/impl/FileServiceImpl.java @@ -923,7 +923,7 @@ public ResponseResult move(UploadApiParamDTO upload, List froms, getCopyResult(upload, froms, to, true); String currentDirectory = getOssFileCurrentDirectory(upload, froms); // 删除 - delete(upload.getUsername(), currentDirectory, froms, upload.getUsername()); + delete(upload.getUsername(), currentDirectory, froms, upload.getUsername(), true); } catch (CommonException e) { pushMessageOperationFileError(upload.getUsername(), Convert.toStr(e.getMsg(), Constants.UNKNOWN_ERROR), "移动"); } catch (Exception e) { @@ -1855,7 +1855,7 @@ public ResponseResult unFavorite(List fileIds) { } @Override - public ResponseResult delete(String username, String currentDirectory, List fileIds, String operator) { + public ResponseResult delete(String username, String currentDirectory, List fileIds, String operator, boolean sweep) { FileDocument doc = getById(fileIds.get(0)); List operationPermissionList = null; if (doc != null) { @@ -1871,7 +1871,6 @@ public ResponseResult delete(String username, String currentDirectory, L webOssService.delete(ossPath, fileIds); return ResultUtil.success(); } - Query query = new Query(); query.addCriteria(Criteria.where("_id").in(fileIds)); List fileDocuments = mongoTemplate.find(query, FileDocument.class, COLLECTION_NAME); @@ -1883,8 +1882,15 @@ public ResponseResult delete(String username, String currentDirectory, L if (CommonFileService.isLock(fileDocument)) { throw new CommonException(ExceptionType.LOCKED_RESOURCES); } - if (BooleanUtil.isFalse(fileDocument.getIsFolder())) { - isDel = true; + if (sweep) { + String currentDirectory1 = getUserDirectory(fileDocument.getPath()); + String filePath = fileProperties.getRootDir() + File.separator + username + currentDirectory1 + fileDocument.getName(); + File file = new File(filePath); + isDel = FileUtil.del(file); + } else { + if (BooleanUtil.isFalse(fileDocument.getIsFolder())) { + isDel = true; + } } if (Boolean.TRUE.equals(fileDocument.getIsFolder())) { // 删除文件夹及其下的所有文件 @@ -1893,22 +1899,28 @@ public ResponseResult delete(String username, String currentDirectory, L moveToTrash(delFileDocumentList, true); // 提取出delFileDocumentList中文件id List delFileIds = delFileDocumentList.stream().map(FileDocument::getId).collect(Collectors.toList()); - deleteDependencies(username, delFileIds, true); + deleteDependencies(username, delFileIds, !sweep); isDel = true; } pushMessage(username, fileDocument, Constants.DELETE_FILE); } - OperationTips operationTips = OperationTips.builder().operation("移动到回收站").build(); + OperationTips operationTips = OperationTips.builder().operation(sweep ? "删除" : "移动到回收站").build(); if (isDel) { - List delFileDocumentList = mongoTemplate.findAllAndRemove(query, FileDocument.class, COLLECTION_NAME); - // 移动到回收站 - moveToTrash(delFileDocumentList, false); - deleteDependencies(username, fileIds, true); + if (sweep) { + mongoTemplate.remove(query, COLLECTION_NAME); + } else { + List delFileDocumentList = mongoTemplate.findAllAndRemove(query, FileDocument.class, COLLECTION_NAME); + // 移动到回收站 + moveToTrash(delFileDocumentList, false); + } + deleteDependencies(username, fileIds, !sweep); operationTips.setSuccess(true); } else { operationTips.setSuccess(false); } - pushMessage(username, operationTips, Constants.OPERATION_TIPS); + if (!sweep) { + pushMessage(username, operationTips, Constants.OPERATION_TIPS); + } return ResultUtil.success(); } diff --git a/src/main/resources/db/menu.json b/src/main/resources/db/menu.json index d0f09a6d..84f80e04 100644 --- a/src/main/resources/db/menu.json +++ b/src/main/resources/db/menu.json @@ -753,5 +753,19 @@ "path": "/setting/taskProgress", "sortNumber": 16, "updateTime": 1717766722975 + }, + { + "authority": "", + "component": "/trash/index", + "createTime": 1719912060104, + "hide": false, + "icon": "huishouzhan", + "id": "6683c67cf66d83694bc9fe5c", + "menuType": 0, + "name": "回收站", + "parentId": "", + "path": "/trash", + "sortNumber": 8, + "updateTime": 1719912071511 } ] diff --git a/src/main/resources/db/role.json b/src/main/resources/db/role.json index fa66558a..c167920d 100644 --- a/src/main/resources/db/role.json +++ b/src/main/resources/db/role.json @@ -12,6 +12,7 @@ "5ffc37a19a2c787ef115f97f", "5ffc37db9a2c787ef115f980", "63b79129a7b6db0f8c1f2ad9", + "6683c67cf66d83694bc9fe5c", "5ffb1b38eb9cf770a889b7ea", "6020dec9cfb7a66f628397a8", "5ffb1b57eb9cf770a889b7eb", @@ -43,6 +44,7 @@ "5ffd707129d84649e3f02cda", "5ffb1cf6eb9cf770a889b7f3", "5ffd396829d8463da1186735", + "66630732fc290e06878516f0", "600cf2ef194ba43988898423", "5ffd395029d8463da1186734", "5ffd38ed29d8463da1186731", @@ -60,7 +62,7 @@ ], "name": "超级管理员", "remarks": "超级管理员", - "updateTime": 1680744633638 + "updateTime": 1720334128676 }, { "code": "admin", @@ -75,6 +77,7 @@ "5ffc37a19a2c787ef115f97f", "5ffc37db9a2c787ef115f980", "63b79129a7b6db0f8c1f2ad9", + "6683c67cf66d83694bc9fe5c", "5ffb1b38eb9cf770a889b7ea", "6020dec9cfb7a66f628397a8", "5ffb1b57eb9cf770a889b7eb", @@ -107,7 +110,7 @@ ], "name": "管理员", "remarks": "所有菜单(只读)", - "updateTime": 1613718961613 + "updateTime": 1720334138113 }, { "code": "visitor-website", @@ -145,6 +148,7 @@ "5ffc378b9a2c787ef115f97e", "5ffc37a19a2c787ef115f97f", "5ffc37db9a2c787ef115f980", + "6683c67cf66d83694bc9fe5c", "5ffb1b38eb9cf770a889b7ea", "5ffd3ecf29d8463da118673e", "5ffd3f5f29d8463da1186740", @@ -173,7 +177,7 @@ ], "name": "网站编辑者", "remarks": "所有网站菜单可写", - "updateTime": 1611300975061 + "updateTime": 1720334159599 }, { "code": "admin-website", @@ -188,6 +192,7 @@ "5ffc37a19a2c787ef115f97f", "5ffc37db9a2c787ef115f980", "63b79129a7b6db0f8c1f2ad9", + "6683c67cf66d83694bc9fe5c", "5ffb1b38eb9cf770a889b7ea", "5ffd3ecf29d8463da118673e", "5ffd3dc829d8463da118673a", @@ -210,7 +215,7 @@ ], "name": "网站管理员", "remarks": "网站-所有菜单(只读)", - "updateTime": 1613719034018 + "updateTime": 1720334165458 }, { "code": "visitor", @@ -291,6 +296,7 @@ "5ffc37a19a2c787ef115f97f", "5ffc37db9a2c787ef115f980", "63b79129a7b6db0f8c1f2ad9", + "6683c67cf66d83694bc9fe5c", "5ffb1b38eb9cf770a889b7ea", "6020dec9cfb7a66f628397a8", "5ffd3ecf29d8463da118673e", @@ -305,6 +311,6 @@ ], "name": "普通用户", "remarks": "普通网盘用户", - "updateTime": 1613719060086 + "updateTime": 1720334191182 } ]