|
@@ -12,6 +12,7 @@ import cn.reghao.oss.sdk.model.dto.ObjectInfo;
|
|
|
import cn.reghao.tnb.common.auth.UserContext;
|
|
import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.common.util.StringUtil;
|
|
import cn.reghao.tnb.common.util.StringUtil;
|
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.DiskFileMapper;
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.DiskFileMapper;
|
|
|
|
|
+import cn.reghao.tnb.content.app.disk.model.dto.DeleteFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.dto.UploadedFile;
|
|
import cn.reghao.tnb.content.app.disk.model.dto.UploadedFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.dto.MoveFile;
|
|
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.po.DiskFile;
|
|
@@ -73,6 +74,91 @@ public class DiskFileService {
|
|
|
return Result.fail("上传文件失败");
|
|
return Result.fail("上传文件失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Result deleteDiskFile(DeleteFile deleteFile) {
|
|
|
|
|
+ List<String> fileIds = deleteFile.getFileIds();
|
|
|
|
|
+ List<DiskFile> list = findByFileIds(fileIds);
|
|
|
|
|
+
|
|
|
|
|
+ // 删除文件
|
|
|
|
|
+ Map<String, List<DiskFile>> groupMap0 = list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
+ .collect(Collectors.groupingBy(DiskFile::getPid));
|
|
|
|
|
+ if (groupMap0.size() == 1) {
|
|
|
|
|
+ // 保证 file 具有相同的 pid
|
|
|
|
|
+ List<String> fileIds0 = groupMap0.values().stream()
|
|
|
|
|
+ .flatMap(Collection::stream)
|
|
|
|
|
+ .map(DiskFile::getFileId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (!fileIds0.isEmpty()) {
|
|
|
|
|
+ diskFileMapper.updateDeleteDiskFiles(fileIds0);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (groupMap0.size() > 1) {
|
|
|
|
|
+ return Result.fail("只能删除同一个文件夹下的文件");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 删除文件夹
|
|
|
|
|
+ Map<String, List<DiskFile>> groupMap = list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
+ .collect(Collectors.groupingBy(DiskFile::getPid));
|
|
|
|
|
+ if (groupMap.size() == 1) {
|
|
|
|
|
+ // 保证 folder 具有相同的 pid
|
|
|
|
|
+ List<String> foderPaths = groupMap.values().stream()
|
|
|
|
|
+ .flatMap(Collection::stream)
|
|
|
|
|
+ .map(DiskFile::getPath)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (!foderPaths.isEmpty()) {
|
|
|
|
|
+ long loginUser = UserContext.getUserId();
|
|
|
|
|
+ foderPaths.forEach(path -> {
|
|
|
|
|
+ diskFileMapper.updateDeleteByPathPrefix(loginUser, path);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (groupMap.size() > 1) {
|
|
|
|
|
+ return Result.fail("只能删除同一个文件夹下的子文件夹");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void restore(List<String> fileIds) {
|
|
|
|
|
+ List<DiskFile> list = findByFileIds(fileIds);
|
|
|
|
|
+ List<String> files = list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
+ .map(DiskFile::getFileId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
+ .map(diskFile1 -> getChildren(diskFile1.getPath()))
|
|
|
|
|
+ .flatMap(Collection::stream)
|
|
|
|
|
+ .forEach(diskFile -> {
|
|
|
|
|
+ files.add(diskFile.getFileId());
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (!files.isEmpty()) {
|
|
|
|
|
+ //diskFile1Repository.updateRestoreFiles(files);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void erase(List<String> fileIds) {
|
|
|
|
|
+ List<DiskFile> list = findByFileIds(fileIds);
|
|
|
|
|
+ List<String> files = list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
+ .map(DiskFile::getFileId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ list.stream()
|
|
|
|
|
+ .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
+ .map(diskFile -> findByPathPrefix(diskFile.getPath()))
|
|
|
|
|
+ .flatMap(Collection::stream)
|
|
|
|
|
+ .forEach(diskFile -> {
|
|
|
|
|
+ files.add(diskFile.getFileId());
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (!files.isEmpty()) {
|
|
|
|
|
+ //diskFile1Repository.deleteByFileIds(files);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Result rename(String fileId, String newFilename, long owner) {
|
|
public Result rename(String fileId, String newFilename, long owner) {
|
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
.fileId(fileId)
|
|
.fileId(fileId)
|
|
@@ -142,7 +228,7 @@ public class DiskFileService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (parentFile.getFileType() != ObjectType.Dir.getCode()) {
|
|
if (parentFile.getFileType() != ObjectType.Dir.getCode()) {
|
|
|
- String msg = "文件被移动/复制到的位置不是目录";
|
|
|
|
|
|
|
+ String msg = "文件被移动/复制到的位置不是文件夹";
|
|
|
return Result.fail(msg);
|
|
return Result.fail(msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -161,23 +247,27 @@ public class DiskFileService {
|
|
|
|
|
|
|
|
for (String fileId : fileIds) {
|
|
for (String fileId : fileIds) {
|
|
|
if (parents.contains(fileId)) {
|
|
if (parents.contains(fileId)) {
|
|
|
- String msg = "文件被移动/复制到的位置不能是其自身或子目录";
|
|
|
|
|
|
|
+ String msg = "文件被移动/复制到的位置不能是其自身或子文件夹";
|
|
|
return Result.fail(msg);
|
|
return Result.fail(msg);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- List<DiskFile> list = findByFileIdContains(fileIds);
|
|
|
|
|
|
|
+ List<DiskFile> list = findByFileIds(fileIds);
|
|
|
if (list.isEmpty()) {
|
|
if (list.isEmpty()) {
|
|
|
String msg = "被移动/复制的文件不存在";
|
|
String msg = "被移动/复制的文件不存在";
|
|
|
return Result.fail(msg);
|
|
return Result.fail(msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String currentPid = list.get(0).getPid();
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (currentPid.equals(pid)) {
|
|
|
|
|
+ String msg = "移动/复制的目的文件夹和当前相同";
|
|
|
|
|
+ return Result.fail(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, List<DiskFile>> groupMap = list.stream().collect(Collectors.groupingBy(DiskFile::getPid));
|
|
|
|
|
+ if (groupMap.size() != 1 || groupMap.get(currentPid) == null) {
|
|
|
|
|
+ String msg = "被移动/复制的文件必须来自同一文件夹";
|
|
|
|
|
+ return Result.fail(msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
List<DiskFile> copiedFiles = list.stream()
|
|
List<DiskFile> copiedFiles = list.stream()
|
|
@@ -281,67 +371,6 @@ public class DiskFileService {
|
|
|
diskFile.setUpdateTime(null);
|
|
diskFile.setUpdateTime(null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void delete(List<String> fileIds) {
|
|
|
|
|
- List<DiskFile> list = findByFileIdContains(fileIds);
|
|
|
|
|
- List<String> files = list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
- .map(DiskFile::getFileId)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- if (!files.isEmpty()) {
|
|
|
|
|
- //diskFile1Repository.updateDeleteFiles(files);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<String> files1 = list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
- .map(diskFile1 -> getChildren(diskFile1.getPath()))
|
|
|
|
|
- .flatMap(Collection::stream)
|
|
|
|
|
- .map(DiskFile::getFileId)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- if (!files1.isEmpty()) {
|
|
|
|
|
- //diskFile1Repository.updateDeleteFiles(files1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void restore(List<String> fileIds) {
|
|
|
|
|
- List<DiskFile> list = findByFileIdContains(fileIds);
|
|
|
|
|
- List<String> files = list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
- .map(DiskFile::getFileId)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
- .map(diskFile1 -> getChildren(diskFile1.getPath()))
|
|
|
|
|
- .flatMap(Collection::stream)
|
|
|
|
|
- .forEach(diskFile -> {
|
|
|
|
|
- files.add(diskFile.getFileId());
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (!files.isEmpty()) {
|
|
|
|
|
- //diskFile1Repository.updateRestoreFiles(files);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void erase(List<String> fileIds) {
|
|
|
|
|
- List<DiskFile> list = findByFileIdContains(fileIds);
|
|
|
|
|
- List<String> files = list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() != ObjectType.Dir.getCode())
|
|
|
|
|
- .map(DiskFile::getFileId)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- list.stream()
|
|
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Dir.getCode())
|
|
|
|
|
- .map(diskFile -> findByPathPrefix(diskFile.getPath()))
|
|
|
|
|
- .flatMap(Collection::stream)
|
|
|
|
|
- .forEach(diskFile -> {
|
|
|
|
|
- files.add(diskFile.getFileId());
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (!files.isEmpty()) {
|
|
|
|
|
- //diskFile1Repository.deleteByFileIds(files);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public List<DiskFile> getChildren(String path) {
|
|
public List<DiskFile> getChildren(String path) {
|
|
|
return findByPathPrefix(path);
|
|
return findByPathPrefix(path);
|
|
|
}
|
|
}
|
|
@@ -380,7 +409,7 @@ public class DiskFileService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 当前目录中存在同名文件时, 自动修改文件名
|
|
|
|
|
|
|
+ * 当前文件夹中存在同名文件时, 自动修改文件名
|
|
|
*
|
|
*
|
|
|
* @param
|
|
* @param
|
|
|
* @return
|
|
* @return
|
|
@@ -412,23 +441,7 @@ public class DiskFileService {
|
|
|
int index = path.lastIndexOf("/");
|
|
int index = path.lastIndexOf("/");
|
|
|
return path.substring(0, index);
|
|
return path.substring(0, index);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private List<DiskFile> findByPathPrefix(String pathPrefix) {
|
|
|
|
|
- /*Specification<DiskFile> specification = (root, query, cb) -> {
|
|
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
|
|
- predicates.add(cb.like(root.get("path"), "%" + pathPrefix + "%"));
|
|
|
|
|
-
|
|
|
|
|
- // select * from app_building where app_id like '%test%' and app_name like '%测试%'
|
|
|
|
|
- return cb.and(predicates.toArray(new Predicate[0]));
|
|
|
|
|
- };*/
|
|
|
|
|
-
|
|
|
|
|
- return diskFileMapper.findAll();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private List<DiskFile> findByFileIdContains(List<String> fileIds) {
|
|
|
|
|
- return diskFileMapper.findByFileIds(fileIds);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public List<NamePath> getPathList(String path) {
|
|
public List<NamePath> getPathList(String path) {
|
|
|
List<NamePath> pathList = new ArrayList<>();
|
|
List<NamePath> pathList = new ArrayList<>();
|
|
|
if (path.equals("/")) {
|
|
if (path.equals("/")) {
|
|
@@ -516,6 +529,16 @@ public class DiskFileService {
|
|
|
return diskFileMapper.findSha256sumGroup(sha256sumList);
|
|
return diskFileMapper.findSha256sumGroup(sha256sumList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private List<DiskFile> findByPathPrefix(String pathPrefix) {
|
|
|
|
|
+ long owner = UserContext.getUserId();
|
|
|
|
|
+ DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
|
|
+ .pathPrefix(pathPrefix)
|
|
|
|
|
+ .owner(owner)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Page page = new Page(1, 1000);
|
|
|
|
|
+ return diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public PageList<FileInfo> findByDiskQuery(DiskQuery diskQuery) {
|
|
public PageList<FileInfo> findByDiskQuery(DiskQuery diskQuery) {
|
|
|
int pageNumber = diskQuery.getPageNumber();
|
|
int pageNumber = diskQuery.getPageNumber();
|
|
|
int pageSize = diskQuery.getPageSize();
|
|
int pageSize = diskQuery.getPageSize();
|