支持批量复制文件/文件夹

This commit is contained in:
2024-01-11 15:59:13 +08:00
parent d0f967d58a
commit f0c23ca47d
2 changed files with 20 additions and 27 deletions

View File

@@ -2,11 +2,13 @@ package cn.lihongjie.coal.netDisk.dto;
import lombok.Data;
import java.util.List;
@Data
public class CopyDto {
private String srcId;
private String newName;
private List<String> srcIds;
private String targetId;

View File

@@ -626,42 +626,33 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
public NetDiskDto copy(CopyDto request) {
NetDiskEntity srcEntity = get(request.getSrcId());
NetDiskEntity src = this.mapper.copyChildren(srcEntity);
NetDiskEntity target = get(request.getTargetId());
if (StringUtils.isNotEmpty(request.getNewName())) {
src.setName(request.getNewName());
}
// TreeUtils.allChildren(src, NetDiskEntity::getChildren)
// .forEach(
// x -> {
// if (x.getId().equals(src.getId())) {
// throw new BizException("不能复制到自己的子目录");
// }
// });
if (!target.getEntryType().equals("0")) {
throw new BizException("只能复制到目录");
}
if (target.getChildren().stream().filter(x -> x.getName().equals(src.getName())).count()
> 0) {
throw new BizException("目标目录已经存在同名文件/文件夹");
for (String srcId : request.getSrcIds()) {
NetDiskEntity srcEntity = get(srcId);
NetDiskEntity src = this.mapper.copyChildren(srcEntity);
if (target.getChildren().stream().filter(x -> x.getName().equals(src.getName())).count()
> 0) {
throw new BizException("目标目录已经存在同名文件/文件夹");
}
src.setParent(target);
this.save(src);
}
src.setParent(target);
if (target.getParent() != null) {
this.save(src);
if (src.getParent() != null) {
updateDirSize(src.getParent().getId());
updateDirSize(target.getParent().getId());
}
return this.mapper.toDto(src);
return null;
}
public String downloadFile(String id, boolean attachment) {