1
0
فهرست منبع

调整关于初始附件直接返回数据

chenendian 3 ماه پیش
والد
کامیت
95fdfd8f95

+ 14 - 19
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/NodeAttachmentController.java

@@ -2,6 +2,7 @@ package com.siwei.apply.controller;
 
 import com.siwei.apply.domain.NodeAttachment;
 import com.siwei.apply.service.NodeAttachmentService;
+import com.siwei.apply.utils.ServiceFileUtil;
 import com.siwei.common.core.domain.R;
 import com.siwei.common.core.utils.StringUtils;
 import com.siwei.common.core.web.controller.BaseController;
@@ -211,10 +212,11 @@ public class NodeAttachmentController extends BaseController {
         }
     }
 
-
     @PostMapping("/processOneFile")
     public R<Map<String, String>> processOneFile(@RequestBody Map<String, String> requestBody) {
         try {
+            String rootPath = requestBody.get("rootPath");
+            String nodeAttachmentId = requestBody.get("id");
             String filePath = requestBody.get("filePath");
             String fileUploadPath = requestBody.get("fileUploadPath");
             if (filePath == null || filePath.trim().isEmpty()) {
@@ -223,24 +225,18 @@ public class NodeAttachmentController extends BaseController {
             if (fileUploadPath == null || fileUploadPath.trim().isEmpty()) {
                 return R.fail(502,"fileUploadPath");
             }
-
-            //这里把文件迁移到当前目录中,重新更新目录结构
-            //String id = nodeAttachmentService.processFileAndSave(filePath);
-            String id = "11111111222";
-            if (id != null) {
-                Map<String, String> responseData = new HashMap<>();
-                responseData.put("nodeAttachmentId", id);
-                return R.ok(responseData);
-            } else {
-                return R.fail("处理一个文件失败");
-            }
+            //文件移动
+            String movePath = ServiceFileUtil.moveFileToDirectory(filePath,fileUploadPath);
+            nodeAttachmentService.restFileAttachment(rootPath,nodeAttachmentId);
+            Map<String, String> responseData = new HashMap<>();
+            responseData.put("nodeAttachmentId", nodeAttachmentId);
+            return R.ok(responseData);
         } catch (Exception e) {
             logger.error("处理文件异常", e);
             return R.fail("处理一个文件异常:" + e.getMessage());
         }
     }
 
-
     /**
      * 当用户进入此页面进行数据初始化
      *
@@ -248,22 +244,19 @@ public class NodeAttachmentController extends BaseController {
      * @return 数据库存储后的id
      */
     @PostMapping("/initProcess")
-    public R<Map<String, String>> initProcessFile(@RequestBody Map<String, String> requestBody) {
+    public R<NodeAttachment> initProcessFile(@RequestBody Map<String, String> requestBody) {
         try {
             String nodeId = requestBody.get("nodeId");
             String projectId = requestBody.get("projectId");
             if (StringUtils.isBlank(nodeId)) {
                 return R.fail("nodeId不能为空");
             }
-            String id = null;
             NodeAttachment nodeAttachment = nodeAttachmentService.getByNodeId(nodeId);
             //增加一条空目录结构
             if (Objects.isNull(nodeAttachment)) {
-                id =  nodeAttachmentService.addDefaultAttachment(projectId,nodeId);
+                nodeAttachment =  nodeAttachmentService.addDefaultAttachment(projectId,nodeId);
             }
-            Map<String, String> responseData = new HashMap<>();
-            responseData.put("nodeAttachmentId", id);
-            return R.ok(responseData);
+            return R.ok(nodeAttachment);
         } catch (Exception e) {
             logger.error("初始化附件信息异常", e);
             return R.fail(502,"初始化附件信息异常:" + e.getMessage());
@@ -272,6 +265,8 @@ public class NodeAttachmentController extends BaseController {
 
 
 
+
+
     }
 
 

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

@@ -58,6 +58,9 @@ public interface NodeAttachmentService {
 
     NodeAttachment getAttachmentByProjectIdAndTable(String projectId,String nodeTableName) ;
 
-    String addDefaultAttachment(String projectId, String nodeId) ;
+    NodeAttachment addDefaultAttachment(String projectId, String nodeId);
+
+    String restFileAttachment(String rootPath,String nodeAttachmentId);
+
 
     }

+ 28 - 2
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -214,6 +214,28 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
         }
     }
 
+    /**
+     * 处理文件并保存附件信息
+     * @param rootPath 文件路径
+     * @return
+     */
+    @Override
+    public String restFileAttachment(String rootPath,String nodeAttachmentId) {
+        Path file = Paths.get(rootPath);
+        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: {}", nodeAttachmentId, rootPath);
+        return id;
+    }
+
 
 
 
@@ -278,7 +300,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
      * @return
      */
     @Override
-    public String addDefaultAttachment(String projectId,String nodeId) {
+    public NodeAttachment addDefaultAttachment(String projectId,String nodeId) {
         String nodeAttachmentId = null;
         String tableName = "";
         //获取当前节点表名
@@ -298,7 +320,11 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
         Path file = Paths.get(path);
         Map<String, Object> directoryStructure = FileExtractUtil.getDirectoryStructure(file);
         nodeAttachmentId = this.saveAttachment(directoryStructure,nodeId);
-        return nodeAttachmentId;
+        NodeAttachment nodeAttachment = new NodeAttachment();
+        nodeAttachment.setId(nodeAttachmentId);
+        nodeAttachment.setNodeId(nodeId); // 不设置nodeId
+        nodeAttachment.setAttachment(directoryStructure);
+        return nodeAttachment;
     }
 
 

+ 20 - 7
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ProjectImpl.java

@@ -33,6 +33,7 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.*;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.stream.Collectors;
@@ -410,15 +411,27 @@ public class ProjectImpl implements ProjectService {
 //        String sss = JsonUtil.toJson(ccc);
 //        System.out.println(sss);
 
-            String str = "国有建设用地使用权及房屋所有权首次登记";
-            String path = ServiceFileUtil.createDirectory(str);
-            Path file = Paths.get(path);
-            Map<String, Object> res = FileExtractUtil.getDirectoryStructure(file);
-            log.info("------------"+res);
-
+//            String str = "国有建设用地使用权及房屋所有权首次登记";
+//            String path = ServiceFileUtil.createDirectory(str);
+//            Path file = Paths.get(path);
+//            Map<String, Object> res = FileExtractUtil.getDirectoryStructure(file);
+
+        Map<String, Object> res = null;
+        String path1 = "D:\\home\\siwei\\uploadPath\\2025\\11\\03\\建设工程规划许可阶段_20251103152826A002\\办理结果\\前端修改点.docx";
+        String path2 = "D:\\home\\siwei\\uploadPath\\2025\\11\\03\\建设工程规划许可阶段_20251103152826A002\\用地图形\\前端修改点.docx";
+
+        Path file = Paths.get(path1);
+        Path dirPath = Paths.get(path2);
+        try {
+            //Files.copy(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+            Files.move(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        log.info("-----move success-------"+res);
+    }
 
 
-    }
 
 
 

+ 22 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceFileUtil.java

@@ -12,6 +12,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.Arrays;
 
 /**
@@ -89,6 +90,27 @@ public class ServiceFileUtil {
 
 
 
+    //给定一个名称创建一个目录,返回路径
+    public static String  moveFileToDirectory(String filePath,String directoryPath) {
+        Path file = Paths.get(filePath);
+        Path dirPath = Paths.get(directoryPath);
+        if (!Files.exists(file)) {
+            logger.warn("处理文件失败,文件不存在: {}",filePath);
+            throw new ServiceException("处理文件失败:文件不存在: "+filePath);
+        }
+        if (!Files.exists(dirPath)) {
+            logger.warn("目录不存在: {}", directoryPath);
+            throw new ServiceException("目录不存在: "+directoryPath);
+        }
+        try {
+            //Files.copy(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+            Files.move(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return directoryPath+"/"+ filePath;
+    }
+