|
|
@@ -16,10 +16,7 @@ import cn.reghao.tnb.content.app.disk.model.dto.CreateFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.dto.MoveFile;
|
|
|
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.vo.FileInfo;
|
|
|
-import cn.reghao.tnb.content.app.disk.model.vo.NamePath;
|
|
|
-import cn.reghao.tnb.content.app.disk.model.vo.DiskFileCount;
|
|
|
-import cn.reghao.tnb.content.app.disk.model.vo.DiskFileDetail;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.vo.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -117,7 +114,7 @@ public class DiskFileService {
|
|
|
.filter(childFile -> !childFile.getFileId().equals(fileId))
|
|
|
.forEach(childFile -> {
|
|
|
String filename = childFile.getFilename();
|
|
|
- NamePath namePath = getUniqueNamePath(newPath, filename, owner);
|
|
|
+ NamePath namePath = getUniqueNamePath(newPath, filename);
|
|
|
|
|
|
childFile.setPath(namePath.getPath());
|
|
|
childFile.setFilename(namePath.getFilename());
|
|
|
@@ -132,15 +129,16 @@ public class DiskFileService {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- public Result move(MoveFile moveFile, long owner) {
|
|
|
+ public Result move(MoveFile moveFile) {
|
|
|
+ long owner = UserContext.getUserId();
|
|
|
String pid = moveFile.getPid();
|
|
|
List<String> fileIds = moveFile.getFileIds();
|
|
|
- boolean copy = moveFile.getType() == 2;
|
|
|
+ boolean copy = false;
|
|
|
|
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
.fileId(pid)
|
|
|
.build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
+ Page page = new Page(1, 1);
|
|
|
List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
DiskFile parentFile = diskFileList.get(0);
|
|
|
if (parentFile == null) {
|
|
|
@@ -212,95 +210,12 @@ public class DiskFileService {
|
|
|
copiedFiles.addAll(list1);
|
|
|
if (!copiedFiles.isEmpty()) {
|
|
|
if (copy) {
|
|
|
- //diskFile1Repository.saveAll(copiedFiles);
|
|
|
+ diskFileMapper.saveAll(copiedFiles);
|
|
|
} else {
|
|
|
- // diskFile1Repository.updateDiskFiles(copiedFiles);
|
|
|
+ copiedFiles.forEach(diskFileMapper::updateMoveDiskFile);
|
|
|
}
|
|
|
}
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
|
|
|
- public Result move(String pid, List<String> fileIds, boolean copy, long owner) {
|
|
|
- DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
- .fileId(pid)
|
|
|
- .build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
- List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- DiskFile parentFile = diskFileList.get(0);
|
|
|
- if (parentFile == null) {
|
|
|
- String msg = "文件被移动/复制到的位置不存在";
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
-
|
|
|
- if (parentFile.getFileType() != ObjectType.Dir.getCode()) {
|
|
|
- String msg = "文件被移动/复制到的位置不是目录";
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
-
|
|
|
- Set<String> parents = new HashSet<>();
|
|
|
- String pid1 = parentFile.getPid();
|
|
|
- parents.add(pid1);
|
|
|
- while (!pid1.equals("0")) {
|
|
|
- diskQuery = new DiskQuery.Builder()
|
|
|
- .fileId(pid1)
|
|
|
- .build();
|
|
|
- page = new Page(1, 10);
|
|
|
- diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- pid1 = diskFileList.get(0).getPid();
|
|
|
- parents.add(pid1);
|
|
|
- }
|
|
|
-
|
|
|
- for (String fileId : fileIds) {
|
|
|
- if (parents.contains(fileId)) {
|
|
|
- String msg = "文件被移动/复制到的位置不能是其自身或子目录";
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<DiskFile> list = findByFileIdContains(fileIds);
|
|
|
- if (list.isEmpty()) {
|
|
|
- String msg = "被移动/复制的文件不存在";
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
-
|
|
|
- String currentPid = list.get(0).getPid();
|
|
|
- for (int i = 1; i < list.size(); i++) {
|
|
|
- if (!list.get(i).getPid().equals(currentPid)) {
|
|
|
- String msg = "被移动/复制的文件必须来自同一目录";
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<DiskFile> copiedFiles = list.stream()
|
|
|
- .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
- .peek(diskFile -> {
|
|
|
- setRootPath(diskFile, parentFile, owner);
|
|
|
- if (copy) {
|
|
|
- reinitDiskFile(diskFile);
|
|
|
- }
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- List<DiskFile> list1 = new ArrayList<>();
|
|
|
- list.stream()
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
- .forEach(dirFile -> {
|
|
|
- List<DiskFile> results = getChildren(dirFile.getPath());
|
|
|
- DiskFile diskFile = list2tree(dirFile.getFileId(), results);
|
|
|
-
|
|
|
- moveRoot(diskFile, parentFile, copy, owner);
|
|
|
- List<DiskFile> list2 = new ArrayList<>();
|
|
|
- tree2List(diskFile, list2);
|
|
|
- list1.addAll(list2);
|
|
|
- });
|
|
|
-
|
|
|
- copiedFiles.addAll(list1);
|
|
|
- if (!copiedFiles.isEmpty()) {
|
|
|
- if (copy) {
|
|
|
- diskFileMapper.saveAll(copiedFiles);
|
|
|
- } else {
|
|
|
- //diskFile1Repository.updateDiskFiles(list1);
|
|
|
- }
|
|
|
- }
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -339,7 +254,7 @@ public class DiskFileService {
|
|
|
String parentPath = parent.getPath();
|
|
|
|
|
|
String filename = current.getFilename();
|
|
|
- NamePath namePath = getUniqueNamePath(parentPath, filename, owner);
|
|
|
+ NamePath namePath = getUniqueNamePath(parentPath, filename);
|
|
|
current.setPid(pid);
|
|
|
current.setPath(namePath.getPath());
|
|
|
current.setFilename(namePath.getFilename());
|
|
|
@@ -458,15 +373,9 @@ public class DiskFileService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public NamePath getUniqueNamePath(String parentPath, String filename, long owner) {
|
|
|
+ public NamePath getUniqueNamePath(String parentPath, String filename) {
|
|
|
String path = getPath(parentPath, filename);
|
|
|
- DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
- .path(path)
|
|
|
- .path(path)
|
|
|
- .build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
- List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- DiskFile diskFile = diskFileList.get(0);
|
|
|
+ DiskFile diskFile = findByPath(path);
|
|
|
if (diskFile != null) {
|
|
|
filename = getNewFilename(filename);
|
|
|
path = getPath(parentPath, filename);
|
|
|
@@ -522,7 +431,7 @@ public class DiskFileService {
|
|
|
}
|
|
|
|
|
|
private List<DiskFile> findByFileIdContains(List<String> fileIds) {
|
|
|
- return Collections.emptyList();
|
|
|
+ return diskFileMapper.findByFileIds(fileIds);
|
|
|
}
|
|
|
|
|
|
public List<NamePath> getPathList(String path) {
|