mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
支持批量复制文件/文件夹
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user