1
0
فهرست منبع

调整关于初始附件数据

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

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

@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * 节点附件控制器
@@ -240,8 +241,6 @@ public class NodeAttachmentController extends BaseController {
     }
 
 
-
-
     /**
      * 当用户进入此页面进行数据初始化
      *
@@ -256,22 +255,23 @@ public class NodeAttachmentController extends BaseController {
             if (StringUtils.isBlank(nodeId)) {
                 return R.fail("nodeId不能为空");
             }
-            // 1.根据nodeId进行查询。
-            // 2.如果不存在插入数据返回。
-            //String id = nodeAttachmentService.processFileAndSave(null);
-            String id = "222222222222222111";
-            if (id != null) {
-                Map<String, String> responseData = new HashMap<>();
-                responseData.put("nodeAttachmentId", id);
-                return R.ok(responseData);
-            } else {
-                return R.fail(502,"处理文件失败");
+            String id = null;
+            NodeAttachment nodeAttachment = nodeAttachmentService.getByNodeId(nodeId);
+            //增加一条空目录结构
+            if (Objects.isNull(nodeAttachment)) {
+                id =  nodeAttachmentService.addDefaultAttachment(projectId,nodeId);
             }
+            Map<String, String> responseData = new HashMap<>();
+            responseData.put("nodeAttachmentId", id);
+            return R.ok(responseData);
         } catch (Exception e) {
             logger.error("初始化附件信息异常", e);
             return R.fail(502,"初始化附件信息异常:" + e.getMessage());
         }
 
+
+
+
     }
 
 

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

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

+ 89 - 4
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -4,6 +4,7 @@ import com.siwei.apply.common.UnifyAttachmentEnum;
 import com.siwei.apply.domain.NodeAttachment;
 import com.siwei.apply.domain.Project;
 import com.siwei.apply.domain.ProjectWorkflow;
+import com.siwei.apply.domain.Workflow;
 import com.siwei.apply.domain.res.TdgyRes;
 import com.siwei.apply.enums.*;
 import com.siwei.apply.mapper.NodeAttachmentMapper;
@@ -12,6 +13,7 @@ import com.siwei.apply.mapper.ProjectWorkflowMapper;
 import com.siwei.apply.service.NodeAttachmentService;
 import com.siwei.apply.service.TdgyService;
 import com.siwei.apply.utils.FileExtractUtil;
+import com.siwei.apply.utils.ServiceFileUtil;
 import com.siwei.apply.utils.ServiceUtil;
 import com.siwei.common.core.exception.ServiceException;
 import org.apache.commons.collections4.CollectionUtils;
@@ -25,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.nio.file.*;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -165,7 +168,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
                 directoryStructure = FileExtractUtil.getFileStructure(file);
             }
             // 保存附件信息并返回ID
-            String id = saveAttachment(directoryStructure);
+            String id = saveAttachment(directoryStructure,null);
             logger.info("成功处理文件并保存附件信息,id: {}, filePath: {}", id, filePath);
             return id;
 
@@ -267,15 +270,52 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
             return false;
         }
     }
-    
+
+
+    /**
+     * 初始化附件信息进行保存
+     * @param nodeId
+     * @return
+     */
+    @Override
+    public String addDefaultAttachment(String projectId,String nodeId) {
+        String nodeAttachmentId = null;
+        String tableName = "";
+        //获取当前节点表名
+        List<ProjectWorkflow> projectWorkflowList = projectWorkflowMapper.selectByNodeId(nodeId,projectId);
+        if(CollectionUtils.isNotEmpty(projectWorkflowList) && Objects.nonNull(projectWorkflowList.get(0))) {
+            ProjectWorkflow projectWorkflow = projectWorkflowList.get(0);
+            tableName = projectWorkflow.getNodeTableName();
+        }
+        //获取枚举配置的目录信息
+        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);
+        return nodeAttachmentId;
+    }
+
+
+
+
+
+
+
+
     /**
      * 保存附件信息
      */
-    private String saveAttachment(Map<String, Object> directoryStructure) {
+    private String saveAttachment(Map<String, Object> directoryStructure,String nodeId) {
         // 创建新记录
         NodeAttachment nodeAttachment = new NodeAttachment();
         nodeAttachment.generateId();
-        nodeAttachment.setNodeId(null); // 不设置nodeId
+        nodeAttachment.setNodeId(nodeId); // 不设置nodeId
         nodeAttachment.setAttachment(directoryStructure);
         nodeAttachmentMapper.insert(nodeAttachment);
         return nodeAttachment.getId();
@@ -460,6 +500,51 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     }
 
 
+    /**
+     * 根据表名获取内容
+     * @param tableName
+     * @return
+     */
+    public Map<String,List<String>> getCurrentAttachmentName(String tableName) {
+        Map<String,List<String>> retMap = new LinkedHashMap<>();
+        String parentName = "";
+        List<String> nameList = null;
+        if(AloneWorkFlowEnum.NODE_0.getTableName().equalsIgnoreCase(tableName)){
+            parentName = YdysyxzAttachmentNameEnum.NAME_1.getParentName();
+            YdysyxzAttachmentNameEnum[] enumValues = YdysyxzAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(YdysyxzAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_1.getTableName().equalsIgnoreCase(tableName)){
+            parentName = YdbpAttachmentNameEnum.NAME_1.getParentName();
+            YdbpAttachmentNameEnum[] enumValues = YdbpAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(YdbpAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_2.getTableName().equalsIgnoreCase(tableName)){
+            parentName = TdgyAttachmentNameEnum.NAME_1.getParentName();
+            TdgyAttachmentNameEnum[] enumValues = TdgyAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(TdgyAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_3.getTableName().equalsIgnoreCase(tableName)){
+            parentName = GyjsydscdjAttachmentNameEnum.NAME_1.getParentName();
+            GyjsydscdjAttachmentNameEnum[] enumValues = GyjsydscdjAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(GyjsydscdjAttachmentNameEnum::getName).collect(Collectors.toList());
+        } else if(AloneWorkFlowEnum.NODE_4.getTableName().equalsIgnoreCase(tableName)){
+            parentName = JsydghxkAttachmentNameEnum.NAME_1.getParentName();
+            JsydghxkAttachmentNameEnum[] enumValues = JsydghxkAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(JsydghxkAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_5.getTableName().equalsIgnoreCase(tableName)){
+            parentName = JsgcghxkAttachmentNameEnum.NAME_1.getParentName();
+            JsgcghxkAttachmentNameEnum[] enumValues = JsgcghxkAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(JsgcghxkAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_6.getTableName().equalsIgnoreCase(tableName)){
+            parentName = TdhyhsAttachmentNameEnum.NAME_1.getParentName();
+            TdhyhsAttachmentNameEnum[] enumValues = TdhyhsAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(TdhyhsAttachmentNameEnum::getName).collect(Collectors.toList());
+        }else if(AloneWorkFlowEnum.NODE_7.getTableName().equalsIgnoreCase(tableName)){
+            parentName = GyjsydjfwscdjAttachmentNameEnum.NAME_1.getParentName();
+            GyjsydjfwscdjAttachmentNameEnum[] enumValues = GyjsydjfwscdjAttachmentNameEnum.values();
+            nameList = Arrays.stream(enumValues).map(GyjsydjfwscdjAttachmentNameEnum::getName).collect(Collectors.toList());
+        }
+        retMap.put(parentName,nameList);
+        return retMap;
+    }
 
 
 

+ 42 - 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.util.Arrays;
 
 /**
  * 文件工具类
@@ -31,6 +32,10 @@ public class ServiceFileUtil {
                 FilenameUtils.getBaseName(name), Seq.getId(Seq.uploadSeqType));
     }
 
+
+
+
+
     //给定一个名称创建一个目录,返回路径
     public static String  createDirectory(String directoryName) {
         String directoryPathAndName = null;
@@ -50,5 +55,42 @@ public class ServiceFileUtil {
         return directoryPathAndName;
     }
 
+    //给定一个名称创建一个目录,返回路径
+    public static String  createMultipartDirectory(String directoryName,String[] subDirectoryName) {
+        String directoryPath = createFilePath;
+        directoryName = extractFilename(directoryName);
+        String directoryPathAndName = createDirectory(directoryPath,directoryName);
+        Arrays.stream(subDirectoryName).forEach(name -> {
+            createDirectory(directoryPathAndName,name);
+        });
+        return directoryPath+"/"+ directoryName;
+    }
+
+
+
+    //给定一个名称创建一个目录,返回路径
+    public static String  createDirectory(String directoryPath, String directoryName) {
+        String directoryPathAndName = null;
+        try {
+            directoryPathAndName =directoryPath+"/"+ directoryName;
+            Path file = Paths.get(directoryPathAndName);
+            if (Files.exists(file)) {
+                logger.warn("处理文件失败:文件不存在: {}", directoryPathAndName);
+            }else {
+                //直接创建目录
+                Path extractPath = Paths.get(directoryPathAndName);
+                Files.createDirectories(extractPath);
+            }
+        } catch (IOException e) {
+            throw new ServiceException("创建目录失败,请检查!"+e.getMessage());
+        }
+        return directoryPathAndName;
+    }
+
+
+
+
+
+
 
 }