|
|
@@ -22,24 +22,29 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class DiskFolderService {
|
|
|
+ private DiskFileService diskFileService;
|
|
|
private final DiskFileMapper diskFileMapper;
|
|
|
|
|
|
- public DiskFolderService(DiskFileMapper diskFileMapper) {
|
|
|
+ public DiskFolderService(DiskFileService diskFileService, DiskFileMapper diskFileMapper) {
|
|
|
+ this.diskFileService = diskFileService;
|
|
|
this.diskFileMapper = diskFileMapper;
|
|
|
}
|
|
|
|
|
|
public synchronized Result createFolder(CreateFolder createFolder) {
|
|
|
String parentPath = FileUtil.getCanonicalPath(createFolder.getParentPath());
|
|
|
- DiskFile parentDiskFile = findByPath(parentPath);
|
|
|
- if (parentDiskFile == null) {
|
|
|
- return Result.fail("parent dir not exist");
|
|
|
+ String pid = "0";
|
|
|
+ if (!parentPath.equals("/")) {
|
|
|
+ DiskFile parentDiskFile = diskFileService.findByPath(parentPath);
|
|
|
+ if (parentDiskFile == null) {
|
|
|
+ return Result.fail("parent dir not exist");
|
|
|
+ }
|
|
|
+ pid = parentDiskFile.getFileId();
|
|
|
}
|
|
|
- String pid = parentDiskFile.getFileId();
|
|
|
|
|
|
String folderName = createFolder.getFolderName();
|
|
|
String folderPath = String.format("%s/%s", parentPath, folderName);
|
|
|
String folderPath0 = FileUtil.getCanonicalPath(folderPath);
|
|
|
- DiskFile diskFile = findByPath(folderPath0);
|
|
|
+ DiskFile diskFile = diskFileService.findByPath(folderPath0);
|
|
|
if (diskFile != null) {
|
|
|
return Result.fail("current dir exist");
|
|
|
}
|
|
|
@@ -49,17 +54,6 @@ public class DiskFolderService {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- private DiskFile findByPath(String path) {
|
|
|
- long loginUser = UserContext.getUserId();
|
|
|
- DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
- .path(path)
|
|
|
- .owner(loginUser)
|
|
|
- .build();
|
|
|
- Page page = new Page(1, 1);
|
|
|
- List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
- }
|
|
|
-
|
|
|
public synchronized String createFolders(String folderPath, long owner) {
|
|
|
File file = new File(folderPath);
|
|
|
String dirPath = file.getAbsolutePath();
|