소스 검색

文件初始化方法

chenendian 7 달 전
부모
커밋
a87a00f6ca

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

@@ -89,7 +89,6 @@ public class NodeAttachmentController extends BaseController {
                 return R.fail("处理文件失败");
             }
 
-
         } catch (Exception e) {
             logger.error("处理文件异常", e);
             return R.fail("处理文件异常:" + e.getMessage());
@@ -98,11 +97,6 @@ public class NodeAttachmentController extends BaseController {
 
 
 
-
-
-
-
-
     /**
      * 根据ID查询附件信息
      *
@@ -266,7 +260,6 @@ public class NodeAttachmentController extends BaseController {
 
 
 
-
     }
 
 

+ 21 - 30
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -189,25 +189,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
             //先删除当前 文件
             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;
+            return this.restFileAttachment(path,nodeAttachmentId);
         } catch (Exception e) {
             logger.error("处理文件并保存附件信息异常,filePath: {}", filePath, e);
             return null;
@@ -222,6 +204,12 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     @Override
     public String restFileAttachment(String rootPath,String nodeAttachmentId) {
         Path file = Paths.get(rootPath);
+        //重新构建json文件
+        if (!Files.exists(file)) {
+            logger.warn("处理文件失败:文件不存在: {}", rootPath);
+            throw new ServiceException("处理文件失败:文件路径不存在:"+rootPath);
+        }
+
         Map<String, Object> directoryStructure;
         if(Files.isDirectory(file)) {
             // 如果是目录直接获取目录信息
@@ -303,23 +291,26 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     public NodeAttachment addDefaultAttachment(String projectId,String nodeId) {
         String nodeAttachmentId = null;
         String tableName = "";
+        Map<String, Object> directoryStructure = null;
+
         //获取当前节点表名
         List<ProjectWorkflow> projectWorkflowList = projectWorkflowMapper.selectByNodeId(nodeId,projectId);
         if(CollectionUtils.isNotEmpty(projectWorkflowList) && Objects.nonNull(projectWorkflowList.get(0))) {
             ProjectWorkflow projectWorkflow = projectWorkflowList.get(0);
             tableName = projectWorkflow.getNodeTableName();
+            logger.info("这里获取projectWorkflow表的节点表名:{}",tableName);
+            //获取枚举配置的目录信息
+            Map<String,List<String>> resultMap =  this.getCurrentAttachmentName(tableName);
+            String directoryName = resultMap.keySet().stream().findFirst().get();
+            List<String> subDirectoryName = resultMap.values().stream().findFirst().get();
+            String[] subDirectoryNameArr = subDirectoryName.toArray(new String[0]);
+            //这里操作文件系统,并生成json目录结构
+            String  path = ServiceFileUtil.createMultipartDirectory(directoryName,subDirectoryNameArr);
+            //重新构建json文件
+            Path file = Paths.get(path);
+            directoryStructure = FileExtractUtil.getDirectoryStructure(file);
+            nodeAttachmentId = this.saveAttachment(directoryStructure,nodeId);
         }
-        //获取枚举配置的目录信息
-        Map<String,List<String>> resultMap =  this.getCurrentAttachmentName(tableName);
-        String directoryName = resultMap.keySet().stream().findFirst().get();
-        List<String> subDirectoryName = resultMap.values().stream().findFirst().get();
-        String[] subDirectoryNameArr = subDirectoryName.toArray(new String[0]);
-        //这里操作文件系统,并生成json目录结构
-        String  path = ServiceFileUtil.createMultipartDirectory(directoryName,subDirectoryNameArr);
-        //重新构建json文件
-        Path file = Paths.get(path);
-        Map<String, Object> directoryStructure = FileExtractUtil.getDirectoryStructure(file);
-        nodeAttachmentId = this.saveAttachment(directoryStructure,nodeId);
         NodeAttachment nodeAttachment = new NodeAttachment();
         nodeAttachment.setId(nodeAttachmentId);
         nodeAttachment.setNodeId(nodeId); // 不设置nodeId

+ 2 - 6
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ProjectImpl.java

@@ -1,6 +1,5 @@
 package com.siwei.apply.service.impl;
 
-import com.alibaba.druid.support.json.JSONUtils;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.siwei.apply.domain.BaseId;
@@ -16,9 +15,6 @@ import com.siwei.apply.mapper.*;
 import com.siwei.apply.service.NodeAttachmentService;
 import com.siwei.apply.service.NodeLandService;
 import com.siwei.apply.service.ProjectService;
-import com.siwei.apply.utils.FileExtractUtil;
-import com.siwei.apply.utils.JsonUtil;
-import com.siwei.apply.utils.ServiceFileUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.io.FileUtils;
@@ -417,8 +413,8 @@ public class ProjectImpl implements ProjectService {
 //            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";
+        String path1 = "D:\\home\\siwei\\uploadPath\\2025\\11\\03\\建设工程规划许可阶段_20251103152826A002\\办理结果\\Untitled-1.html";
+        String path2 = "D:\\home\\siwei\\uploadPath\\2025\\11\\03\\建设工程规划许可阶段_20251103152826A002\\用地图形\\Untitled-1.html";
 
         Path file = Paths.get(path1);
         Path dirPath = Paths.get(path2);

+ 11 - 4
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceFileUtil.java

@@ -102,19 +102,26 @@ public class ServiceFileUtil {
             logger.warn("目录不存在: {}", directoryPath);
             throw new ServiceException("目录不存在: "+directoryPath);
         }
-        directoryPath+="/"+file.getFileName();
+        //这里拼接文件名
+        if(directoryPath.endsWith("/")){
+            directoryPath+=file.getFileName();
+        }else {
+            directoryPath+="/"+file.getFileName();
+        }
         dirPath = Paths.get(directoryPath);
         try {
-            Files.copy(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
-            //Files.move(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+            //Files.copy(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
+            Files.move(file, dirPath, StandardCopyOption.REPLACE_EXISTING);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
-        return directoryPath+"/"+ filePath;
+        return directoryPath;
     }
 
 
 
 
 
+
+
 }