|
@@ -9,6 +9,7 @@ import cn.reghao.tnb.content.app.disk.model.dto.CreateFolder;
|
|
|
import cn.reghao.tnb.content.app.disk.model.po.DiskFile;
|
|
import cn.reghao.tnb.content.app.disk.model.po.DiskFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.query.DiskQuery;
|
|
import cn.reghao.tnb.content.app.disk.model.query.DiskQuery;
|
|
|
import cn.reghao.tnb.content.app.disk.model.vo.FolderTree;
|
|
import cn.reghao.tnb.content.app.disk.model.vo.FolderTree;
|
|
|
|
|
+import cn.reghao.tnb.content.app.disk.util.FileUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -28,7 +29,7 @@ public class DiskFolderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public synchronized Result createFolder(CreateFolder createFolder) {
|
|
public synchronized Result createFolder(CreateFolder createFolder) {
|
|
|
- String parentPath = getCanonicalPath(createFolder.getParentPath());
|
|
|
|
|
|
|
+ String parentPath = FileUtil.getCanonicalPath(createFolder.getParentPath());
|
|
|
DiskFile parentDiskFile = findByPath(parentPath);
|
|
DiskFile parentDiskFile = findByPath(parentPath);
|
|
|
if (parentDiskFile == null) {
|
|
if (parentDiskFile == null) {
|
|
|
return Result.fail("parent dir not exit");
|
|
return Result.fail("parent dir not exit");
|
|
@@ -37,13 +38,13 @@ public class DiskFolderService {
|
|
|
|
|
|
|
|
String folderName = createFolder.getFolderName();
|
|
String folderName = createFolder.getFolderName();
|
|
|
String folderPath = String.format("%s/%s", parentPath, folderName);
|
|
String folderPath = String.format("%s/%s", parentPath, folderName);
|
|
|
- String folderPath0 = getCanonicalPath(folderPath);
|
|
|
|
|
|
|
+ String folderPath0 = FileUtil.getCanonicalPath(folderPath);
|
|
|
DiskFile diskFile = findByPath(folderPath0);
|
|
DiskFile diskFile = findByPath(folderPath0);
|
|
|
if (diskFile != null) {
|
|
if (diskFile != null) {
|
|
|
return Result.fail("current dir exit");
|
|
return Result.fail("current dir exit");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- DiskFile folder = new DiskFile(getFileId(), pid, folderPath0, folderName);
|
|
|
|
|
|
|
+ DiskFile folder = new DiskFile(FileUtil.getFileId(), pid, folderPath0, folderName);
|
|
|
diskFileMapper.save(folder);
|
|
diskFileMapper.save(folder);
|
|
|
return Result.success();
|
|
return Result.success();
|
|
|
}
|
|
}
|
|
@@ -59,16 +60,7 @@ public class DiskFolderService {
|
|
|
return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getCanonicalPath(String path) {
|
|
|
|
|
- //return new File(path).getCanonicalPath();
|
|
|
|
|
- return new File(path).getAbsolutePath();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private String getFileId() {
|
|
|
|
|
- return UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private String createFolders(String folderPath, long owner) {
|
|
|
|
|
|
|
+ public synchronized String createFolders(String folderPath, long owner) {
|
|
|
File file = new File(folderPath);
|
|
File file = new File(folderPath);
|
|
|
String dirPath = file.getAbsolutePath();
|
|
String dirPath = file.getAbsolutePath();
|
|
|
|
|
|
|
@@ -105,7 +97,7 @@ public class DiskFolderService {
|
|
|
if (!diskFileList.isEmpty()) {
|
|
if (!diskFileList.isEmpty()) {
|
|
|
pid = diskFileList.get(0).getFileId();
|
|
pid = diskFileList.get(0).getFileId();
|
|
|
} else {
|
|
} else {
|
|
|
- String fileId = getFileId();
|
|
|
|
|
|
|
+ String fileId = FileUtil.getFileId();
|
|
|
String path = parent;
|
|
String path = parent;
|
|
|
String dirname = parent.substring(parent.lastIndexOf("/")+1);
|
|
String dirname = parent.substring(parent.lastIndexOf("/")+1);
|
|
|
diskFileMapper.save(new DiskFile(fileId, pid, path, dirname));
|
|
diskFileMapper.save(new DiskFile(fileId, pid, path, dirname));
|
|
@@ -119,6 +111,12 @@ public class DiskFolderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<FolderTree> getFolderTree() {
|
|
public List<FolderTree> getFolderTree() {
|
|
|
|
|
+ DiskFile root = diskFileMapper.findRoot();
|
|
|
|
|
+ if (root == null) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ FolderTree treeRoot = new FolderTree(root);
|
|
|
|
|
+
|
|
|
long loginUser = UserContext.getUserId();
|
|
long loginUser = UserContext.getUserId();
|
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
.fileType(ObjectType.Dir.getCode())
|
|
.fileType(ObjectType.Dir.getCode())
|
|
@@ -126,13 +124,20 @@ public class DiskFolderService {
|
|
|
.build();
|
|
.build();
|
|
|
|
|
|
|
|
Page page = new Page(1, 1000);
|
|
Page page = new Page(1, 1000);
|
|
|
- List<DiskFile> netDiskList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
|
|
- Map<String, FolderTree> map = netDiskList.stream()
|
|
|
|
|
|
|
+ List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
|
|
+ Map<String, List<FolderTree>> map = diskFileList.stream()
|
|
|
.map(FolderTree::new)
|
|
.map(FolderTree::new)
|
|
|
- .collect(Collectors.toMap(FolderTree::getFileId, diskFile -> diskFile));
|
|
|
|
|
|
|
+ .collect(Collectors.groupingBy(FolderTree::getPid));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String rootId = treeRoot.getFileId();
|
|
|
|
|
+ List<FolderTree> list = map.get(rootId);
|
|
|
|
|
+ if (list != null) {
|
|
|
|
|
+ treeRoot.setChildren(list);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
Map<String, FolderTree> tree = new TreeMap<>();
|
|
Map<String, FolderTree> tree = new TreeMap<>();
|
|
|
- netDiskList.forEach(diskFile -> {
|
|
|
|
|
|
|
+ /*diskFileList.forEach(diskFile -> {
|
|
|
String pid = diskFile.getPid();
|
|
String pid = diskFile.getPid();
|
|
|
String fileId = diskFile.getFileId();
|
|
String fileId = diskFile.getFileId();
|
|
|
FolderTree folderTree = map.get(fileId);
|
|
FolderTree folderTree = map.get(fileId);
|
|
@@ -143,10 +148,10 @@ public class DiskFolderService {
|
|
|
FolderTree parent = map.get(pid);
|
|
FolderTree parent = map.get(pid);
|
|
|
parent.getChildren().add(folderTree);
|
|
parent.getChildren().add(folderTree);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ });*/
|
|
|
|
|
+ /*String key = tree.keySet().iterator().next();
|
|
|
|
|
+ FolderTree folderTree = tree.get(key);*/
|
|
|
|
|
|
|
|
- String key = tree.keySet().iterator().next();
|
|
|
|
|
- FolderTree root = tree.get(key);
|
|
|
|
|
- return List.of(root);
|
|
|
|
|
|
|
+ return List.of(treeRoot);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|