添加重命名接口

This commit is contained in:
2024-01-10 10:40:38 +08:00
parent 4bb6223d7c
commit 62e613128e
2 changed files with 39 additions and 8 deletions

View File

@@ -139,6 +139,20 @@ public class NetDiskController {
return this.service.preCreateFile(request);
}
/**
* 重命名
*
* @param request
* @return
*/
@PostMapping("/rename")
@SysLog(action = "rename")
public Boolean rename(@RequestBody UpdateNetDiskDto request) {
this.service.rename(request);
return true;
}
/**
* 创建文件分片
*

View File

@@ -596,13 +596,13 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
src.setName(request.getNewName());
}
// TreeUtils.allChildren(src, NetDiskEntity::getChildren)
// .forEach(
// x -> {
// if (x.getId().equals(src.getId())) {
// throw new BizException("不能复制到自己的子目录");
// }
// });
// TreeUtils.allChildren(src, NetDiskEntity::getChildren)
// .forEach(
// x -> {
// if (x.getId().equals(src.getId())) {
// throw new BizException("不能复制到自己的子目录");
// }
// });
if (!target.getEntryType().equals("0")) {
throw new BizException("只能复制到目录");
@@ -888,7 +888,24 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
List<String> ans = this.repository.idToPath2(id);
List<NetDiskEntity> allById = this.repository.findAllById(ans).stream().sorted( Comparator.comparing(x -> ans.indexOf(x.getId()))).collect(Collectors.toList());
List<NetDiskEntity> allById =
this.repository.findAllById(ans).stream()
.sorted(Comparator.comparing(x -> ans.indexOf(x.getId())))
.collect(Collectors.toList());
return this.mapper.toDto(allById);
}
public void rename(UpdateNetDiskDto dto) {
NetDiskEntity entity = get(dto.getId());
if (entity.getParent() != null) {
if (entity.getParent().getChildren().stream()
.anyMatch(x -> x.getId() != dto.getId() && x.getName().equals(dto.getName()))) {
throw new BizException("目录已经存在同名文件/文件夹");
}
}
entity.setName(dto.getName());
save(entity);
}
}