浏览代码

修改可以删除附件信息

chenendian 1 月之前
父节点
当前提交
d724e6a6d7

+ 3 - 4
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/LandOneCodeController.java

@@ -62,8 +62,6 @@ public class LandOneCodeController extends BaseController {
         }
     }
 
-
-
     /**
      * 删除(按ID)
      */
@@ -88,10 +86,11 @@ public class LandOneCodeController extends BaseController {
     }
 
 
+
     @GetMapping("/getResourceCode")
-    public R<LandOneCodeVo> getResourceCode(@RequestBody LandOneCode body) {
+    public R<LandOneCodeVo> getResourceCode(@RequestParam String projectId,@RequestParam String projectWorkflowId) {
         try {
-            LandOneCodeVo landOneCodeVo = service.getLandOneCodeByWorkflowId(body.getProjectWorkflowId());
+            LandOneCodeVo landOneCodeVo = service.getLandOneCodeByWorkflowId(projectWorkflowId);
             return R.ok(landOneCodeVo);
         } catch (Exception e) {
             return R.fail(e.getMessage());

+ 49 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/NodeAttachmentController.java

@@ -51,6 +51,55 @@ public class NodeAttachmentController extends BaseController {
         }
     }
 
+
+
+
+
+    /**
+     * 删除某个附件信息
+     *
+     * @param requestBody 包含filePath的请求体
+     * @return 数据库存储后的id
+     */
+    @PostMapping("/deleteOneFile")
+    public R<Map<String, String>> deleteOneFile(@RequestBody Map<String, String> requestBody) {
+        try {
+            String nodeAttachmentId = requestBody.get("id");
+            String nodeId = requestBody.get("nodeId");
+            String path = requestBody.get("path");
+            String filePath = requestBody.get("file");
+
+            if (filePath == null || filePath.trim().isEmpty()) {
+                return R.fail("filePath不能为空");
+            }
+            if (nodeAttachmentId == null || nodeAttachmentId.trim().isEmpty()) {
+                return R.fail("附件id不能为空");
+            }
+
+            String id = nodeAttachmentService.deleteFileAndSave(path,nodeAttachmentId,filePath);
+
+            if (id != null) {
+                Map<String, String> responseData = new HashMap<>();
+                responseData.put("nodeAttachmentId", id);
+                return R.ok(responseData);
+            } else {
+                return R.fail("处理文件失败");
+            }
+
+
+        } catch (Exception e) {
+            logger.error("处理文件异常", e);
+            return R.fail("处理文件异常:" + e.getMessage());
+        }
+    }
+
+
+
+
+
+
+
+
     /**
      * 根据ID查询附件信息
      *

+ 4 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/NodeAttachmentService.java

@@ -48,4 +48,8 @@ public interface NodeAttachmentService {
      * @return 是否更新成功
      */
     boolean updateNodeId(String nodeAttachmentId, String nodeId);
+
+    String deleteFileAndSave(String path,String nodeAttachmentId ,String filePath);
+
+
 }

+ 60 - 3
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -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();
     }
+
+
+
+
 }