|
|
@@ -8,7 +8,6 @@ import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import cn.reghao.jutil.jdk.web.db.Page;
|
|
|
import cn.reghao.jutil.jdk.web.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
-import cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileCount;
|
|
|
import cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileDetail;
|
|
|
import cn.reghao.tnb.file.app.zdisk.model.vo.FileInfo;
|
|
|
import cn.reghao.tnb.file.app.zdisk.model.vo.NamePath;
|
|
|
@@ -49,11 +48,16 @@ public class DiskFileService {
|
|
|
|
|
|
public Result addDiskFile(UploadedFile uploadedFile) {
|
|
|
String pid = uploadedFile.getPid();
|
|
|
- DiskFile diskFile1 = findByFileId(pid);
|
|
|
- if (diskFile1 == null) {
|
|
|
- return Result.fail("folder not exist");
|
|
|
+ String parentPath = "/";
|
|
|
+ if (!"0".equals(pid)) {
|
|
|
+ DiskFile diskFile1 = findByFileId(pid);
|
|
|
+ if (diskFile1 == null) {
|
|
|
+ return Result.fail("folder not exist");
|
|
|
+ }
|
|
|
+
|
|
|
+ parentPath = diskFile1.getPath();
|
|
|
}
|
|
|
- String parentPath = diskFile1.getPath();
|
|
|
+
|
|
|
try {
|
|
|
int channelCode = uploadedFile.getChannelCode();
|
|
|
String uploadId = uploadedFile.getUploadId();
|
|
|
@@ -62,7 +66,9 @@ public class DiskFileService {
|
|
|
String path = FileUtil.getCanonicalPath(String.format("%s/%s", parentPath, filename));
|
|
|
DiskFile diskFile2 = findByPath(path);
|
|
|
if (diskFile2 != null) {
|
|
|
- return Result.fail("file exist");
|
|
|
+ filename = filename + System.currentTimeMillis();
|
|
|
+ path = FileUtil.getCanonicalPath(String.format("%s/%s", parentPath, filename));
|
|
|
+ //return Result.fail("file exist");
|
|
|
}
|
|
|
|
|
|
long size = objectMeta.getSize();
|
|
|
@@ -122,97 +128,6 @@ public class DiskFileService {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- public void restore(List<String> fileIds) {
|
|
|
- List<DiskFile> list = findByFileIds(fileIds);
|
|
|
- List<String> files = list.stream()
|
|
|
- .filter(diskFile -> diskFile.getFileType() != ObjectType.Folder.getCode())
|
|
|
- .map(DiskFile::getFileId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- list.stream()
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Folder.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.Folder.getCode())
|
|
|
- .map(DiskFile::getFileId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- list.stream()
|
|
|
- .filter(diskFile -> diskFile.getFileType() == ObjectType.Folder.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) {
|
|
|
- DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
- .fileId(fileId)
|
|
|
- .build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
- List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- DiskFile current = diskFileList.get(0);
|
|
|
- if (current == null) {
|
|
|
- String msg = String.format("file %s not exist", fileId);
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
-
|
|
|
- String parentPath = getParentPath(current.getPath());
|
|
|
- String newPath = String.format("%s/%s", parentPath, newFilename);
|
|
|
-
|
|
|
- diskQuery = new DiskQuery.Builder()
|
|
|
- .owner(owner)
|
|
|
- .path(newPath)
|
|
|
- .build();
|
|
|
- page = new Page(1, 10);
|
|
|
- diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- DiskFile diskFile = diskFileList.get(0);
|
|
|
- if (diskFile != null) {
|
|
|
- String msg = String.format("filename %s exist", newFilename);
|
|
|
- return Result.fail(msg);
|
|
|
- }
|
|
|
-
|
|
|
- current.setPath(newPath);
|
|
|
- current.setFilename(newFilename);
|
|
|
- List<DiskFile> diskFiles = new ArrayList<>();
|
|
|
- diskFiles.add(current);
|
|
|
- if (current.getFileType() == ObjectType.Folder.getCode()) {
|
|
|
- getChildren(current.getPath()).stream()
|
|
|
- .filter(childFile -> !childFile.getFileId().equals(fileId))
|
|
|
- .forEach(childFile -> {
|
|
|
- String filename = childFile.getFilename();
|
|
|
- NamePath namePath = getUniqueNamePath(newPath, filename);
|
|
|
-
|
|
|
- childFile.setPath(namePath.getPath());
|
|
|
- childFile.setFilename(namePath.getFilename());
|
|
|
- diskFiles.add(childFile);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if (!diskFiles.isEmpty()) {
|
|
|
- //diskFile1Repository.updateFilenames(diskFileList);
|
|
|
- }
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
public Result move(MoveFile moveFile) {
|
|
|
long owner = UserContext.getUserId();
|
|
|
String pid = moveFile.getPid();
|
|
|
@@ -224,7 +139,7 @@ public class DiskFileService {
|
|
|
.build();
|
|
|
Page page = new Page(1, 1);
|
|
|
List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- DiskFile parentFile = diskFileList.get(0);
|
|
|
+ DiskFile parentFile = diskFileList.getFirst();
|
|
|
if (parentFile == null) {
|
|
|
String msg = "文件被移动/复制到的位置不存在";
|
|
|
return Result.fail(msg);
|
|
|
@@ -244,7 +159,7 @@ public class DiskFileService {
|
|
|
.build();
|
|
|
page = new Page(1, 10);
|
|
|
diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- pid1 = diskFileList.get(0).getPid();
|
|
|
+ pid1 = diskFileList.getFirst().getPid();
|
|
|
parents.add(pid1);
|
|
|
}
|
|
|
|
|
|
@@ -261,7 +176,7 @@ public class DiskFileService {
|
|
|
return Result.fail(msg);
|
|
|
}
|
|
|
|
|
|
- String currentPid = list.get(0).getPid();
|
|
|
+ String currentPid = list.getFirst().getPid();
|
|
|
if (currentPid.equals(pid)) {
|
|
|
String msg = "移动/复制的目的文件夹和当前相同";
|
|
|
return Result.fail(msg);
|
|
|
@@ -439,11 +354,6 @@ public class DiskFileService {
|
|
|
|
|
|
return path;
|
|
|
}
|
|
|
-
|
|
|
- private String getParentPath(String path) {
|
|
|
- int index = path.lastIndexOf("/");
|
|
|
- return path.substring(0, index);
|
|
|
- }
|
|
|
|
|
|
public List<NamePath> getPathList(String path) {
|
|
|
List<NamePath> pathList = new ArrayList<>();
|
|
|
@@ -472,16 +382,6 @@ public class DiskFileService {
|
|
|
return pathList;
|
|
|
}
|
|
|
|
|
|
- public List<DiskFile> findBySha256sum(String sha256sum) {
|
|
|
- long owner = UserContext.getUserId();
|
|
|
- DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
- .sha256sum(sha256sum)
|
|
|
- .owner(owner)
|
|
|
- .build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
- return diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- }
|
|
|
-
|
|
|
public DiskFile findByPath(String path) {
|
|
|
long owner = UserContext.getUserId();
|
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
@@ -490,7 +390,7 @@ public class DiskFileService {
|
|
|
.build();
|
|
|
Page page = new Page(1, 1);
|
|
|
List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
+ return diskFileList.isEmpty() ? null : diskFileList.getFirst();
|
|
|
}
|
|
|
|
|
|
public DiskFile findByFileId(String fileId) {
|
|
|
@@ -505,7 +405,7 @@ public class DiskFileService {
|
|
|
.build();
|
|
|
Page page = new Page(1, 1);
|
|
|
List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
- return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
+ return diskFileList.isEmpty() ? null : diskFileList.getFirst();
|
|
|
}
|
|
|
|
|
|
public List<DiskFile> findByFileIds(List<String> fileIds) {
|
|
|
@@ -516,22 +416,6 @@ public class DiskFileService {
|
|
|
return diskFileMapper.findByFileIds(fileIds);
|
|
|
}
|
|
|
|
|
|
- public List<DiskFile> findByParentIds(List<String> parentIds) {
|
|
|
- if (parentIds.isEmpty()) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- return diskFileMapper.findByParentIds(parentIds);
|
|
|
- }
|
|
|
-
|
|
|
- public List<DiskFile> findBySha256sumList(List<String> sha256sumList) {
|
|
|
- if (sha256sumList.isEmpty()) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- return diskFileMapper.findSha256sumGroup(sha256sumList);
|
|
|
- }
|
|
|
-
|
|
|
private List<DiskFile> findByPathPrefix(String pathPrefix) {
|
|
|
long owner = UserContext.getUserId();
|
|
|
DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
@@ -595,10 +479,4 @@ public class DiskFileService {
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
- public Map<Integer, DiskFileCount> getFileTypeCount() {
|
|
|
- long loginUser = UserContext.getUserId();
|
|
|
- List<DiskFileCount> list = diskFileMapper.findFileTypeCountByGroup(loginUser);
|
|
|
- return list.stream().collect(Collectors.toMap(DiskFileCount::getFileType, k -> k));
|
|
|
- }
|
|
|
}
|