|
@@ -70,6 +70,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 处理文件并保存附件信息
|
|
|
* @param filePath 文件路径
|
|
@@ -102,14 +103,15 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
logger.error("解压文件失败: {}", filePath);
|
|
|
return null;
|
|
|
}
|
|
|
+ }else if(Files.isDirectory(file)) {
|
|
|
+ // 如果是目录直接获取目录信息
|
|
|
+ directoryStructure = FileExtractUtil.getDirectoryStructure(file);
|
|
|
} else {
|
|
|
// 直接获取文件信息
|
|
|
directoryStructure = FileExtractUtil.getFileStructure(file);
|
|
|
}
|
|
|
-
|
|
|
// 保存附件信息并返回ID
|
|
|
String id = saveAttachment(directoryStructure);
|
|
|
-
|
|
|
logger.info("成功处理文件并保存附件信息,id: {}, filePath: {}", id, filePath);
|
|
|
return id;
|
|
|
|
|
@@ -118,7 +120,46 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理文件并保存附件信息
|
|
|
+ * @param filePath 文件路径
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String deleteFileAndSave(String path,String nodeAttachmentId,String filePath) {
|
|
|
+ try {
|
|
|
+ //先删除当前 文件
|
|
|
+ Path deleteFile = Paths.get(filePath);
|
|
|
+ Files.deleteIfExists(deleteFile);
|
|
|
+ //重新构建json文件
|
|
|
+ Path file = Paths.get(path);
|
|
|
+ if (!Files.exists(file)) {
|
|
|
+ logger.warn("处理文件失败:文件不存在: {}", path);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> directoryStructure;
|
|
|
+ if(Files.isDirectory(file)) {
|
|
|
+ // 如果是目录直接获取目录信息
|
|
|
+ directoryStructure = FileExtractUtil.getDirectoryStructure(file);
|
|
|
+ } else {
|
|
|
+ // 直接获取文件信息
|
|
|
+ directoryStructure = FileExtractUtil.getFileStructure(file);
|
|
|
+ }
|
|
|
+ // 保存附件信息并返回ID
|
|
|
+ String id = updateAttachment(nodeAttachmentId,directoryStructure);
|
|
|
+ logger.info("成功处理文件并保存附件信息,id: {}, filePath: {}", id, filePath);
|
|
|
+ return id;
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("处理文件并保存附件信息异常,filePath: {}", filePath, e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void deleteByNodeId(String nodeId) {
|
|
|
try {
|
|
@@ -185,7 +226,23 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
nodeAttachment.setNodeId(null); // 不设置nodeId
|
|
|
nodeAttachment.setAttachment(directoryStructure);
|
|
|
nodeAttachmentMapper.insert(nodeAttachment);
|
|
|
+ return nodeAttachment.getId();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改节点附件信息
|
|
|
+ */
|
|
|
+ private String updateAttachment(String nodeAttachmentId, Map<String, Object> directoryStructure) {
|
|
|
+ // 创建新记录
|
|
|
+ NodeAttachment nodeAttachment = new NodeAttachment();
|
|
|
+ nodeAttachment.setId(nodeAttachmentId);
|
|
|
+ nodeAttachment.setAttachment(directoryStructure);
|
|
|
+ nodeAttachmentMapper.updateById(nodeAttachment);
|
|
|
return nodeAttachment.getId();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|