浏览代码

调整返回数据

chenendian 3 月之前
父节点
当前提交
4b57858aed

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

@@ -220,7 +220,7 @@ public class NodeAttachmentController extends BaseController {
                 return R.fail(502,"fileUploadPath");
             }
             //文件移动
-            String movePath = ServiceFileUtil.moveFileToDirectory(filePath,fileUploadPath);
+            String moveAfterPath = ServiceFileUtil.moveFileToDirectory(filePath,fileUploadPath);
             nodeAttachmentService.restFileAttachment(rootPath,nodeAttachmentId);
             Map<String, String> responseData = new HashMap<>();
             responseData.put("nodeAttachmentId", nodeAttachmentId);
@@ -248,8 +248,10 @@ public class NodeAttachmentController extends BaseController {
             NodeAttachment nodeAttachment = nodeAttachmentService.getByNodeId(nodeId);
             //增加一条空目录结构
             if (Objects.isNull(nodeAttachment)) {
-                nodeAttachment =  nodeAttachmentService.addDefaultAttachment(projectId,nodeId);
+                nodeAttachmentService.addDefaultAttachment(projectId,nodeId);
             }
+            //这里重新获取依赖关系
+            nodeAttachment = nodeAttachmentService.getNodeAttachmentData(nodeId);
             return R.ok(nodeAttachment);
         } catch (Exception e) {
             logger.error("初始化附件信息异常", e);
@@ -258,8 +260,6 @@ public class NodeAttachmentController extends BaseController {
 
 
 
-
-
     }
 
 

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

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

+ 17 - 19
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -288,11 +288,9 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
      * @return
      */
     @Override
-    public NodeAttachment addDefaultAttachment(String projectId,String nodeId) {
+    public String 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))) {
@@ -308,14 +306,10 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
             String  path = ServiceFileUtil.createMultipartDirectory(directoryName,subDirectoryNameArr);
             //重新构建json文件
             Path file = Paths.get(path);
-            directoryStructure = FileExtractUtil.getDirectoryStructure(file);
+            Map<String, Object> directoryStructure = FileExtractUtil.getDirectoryStructure(file);
             nodeAttachmentId = this.saveAttachment(directoryStructure,nodeId);
         }
-        NodeAttachment nodeAttachment = new NodeAttachment();
-        nodeAttachment.setId(nodeAttachmentId);
-        nodeAttachment.setNodeId(nodeId); // 不设置nodeId
-        nodeAttachment.setAttachment(directoryStructure);
-        return nodeAttachment;
+        return nodeAttachmentId;
     }
 
 
@@ -484,14 +478,15 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
         List<Map <String,String>> currentAttachmentList = ServiceUtil.getDirChildrenList(name,nodeAttachment);
         //当前目录不存在此节点,需要通过依赖关系填充
         if(CollectionUtils.isEmpty(currentAttachmentList)) {
-            currentAttachmentList = new ArrayList<>();
-            List<String> relationNameList = new ArrayList();
+            if(Objects.isNull(currentAttachmentList)) {
+                currentAttachmentList = new ArrayList<>();
+            }
             String relationNameStr = attachmentEnum.getRelationName();
             if (StringUtils.isNotBlank(relationNameStr)) {
-                relationNameList = Arrays.asList(relationNameStr.split("\\|"));
+                List<String> relationNameList = Arrays.asList(relationNameStr.split("\\|"));
                 if (CollectionUtils.isNotEmpty(relationNameList)) {
                     for (String innerRelationNameStr : relationNameList) {
-                        List<String> innerRelationNameList = Arrays.asList(innerRelationNameStr.split("\\:"));
+                        List<String> innerRelationNameList = Arrays.asList(innerRelationNameStr.split(":"));
                         String relationName = innerRelationNameList.get(0);
                         String tableName = innerRelationNameList.get(1);
                         NodeAttachment relationNodeAttachment = this.getAttachmentByProjectIdAndTable(projectId, tableName);
@@ -501,15 +496,17 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
                 }//end for
             }
             //这里构建当前节点的附件信息
-            Map<String, Object> currentNodeAttachmentMap = new LinkedHashMap<>();
-            currentNodeAttachmentMap.put("name", name);
-            currentNodeAttachmentMap.put("path", "");
-            currentNodeAttachmentMap.put("physicalFlag", "0");
-            currentNodeAttachmentMap.put("type", "directory");
+//            Map<String, Object> currentNodeAttachmentMap = new LinkedHashMap<>();
+//            currentNodeAttachmentMap.put("name", name);
+//            currentNodeAttachmentMap.put("path", "");
+//            currentNodeAttachmentMap.put("physicalFlag", "0");
+//            currentNodeAttachmentMap.put("type", "directory");
+//            currentNodeAttachmentMap.put("children", currentAttachmentList);
+            //获取当前的节点
+            Map<String, Object> currentNodeAttachmentMap = ServiceUtil.getDirChildrenMap(name,nodeAttachment);
             currentNodeAttachmentMap.put("children", currentAttachmentList);
             attachmentChildrenList.add(currentNodeAttachmentMap);
         }
-
         //这里构建最终的附件信息list
         attachmentMap.put("children",attachmentChildrenList);
         nodeAttachment.setAttachment(attachmentMap);
@@ -517,6 +514,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     }
 
 
+
     /**
      * 根据表名获取内容
      * @param tableName

+ 18 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceUtil.java

@@ -37,7 +37,24 @@ public class ServiceUtil {
     }
 
 
-
+    public static   Map<String,Object>  getDirChildrenMap(String dirName, NodeAttachment nodeAttachment) {
+        Map<String,Object> retMap = new LinkedHashMap<>();
+        if (Objects.nonNull(nodeAttachment) && Objects.nonNull(nodeAttachment.getAttachment())) {
+            Map<String, Object> attachment = nodeAttachment.getAttachment();
+            //第一曾经children 所有目录list
+            List<Map> childrenList = (List<Map>) attachment.get("children");
+            if (CollectionUtils.isNotEmpty(childrenList)) {
+                for (Map childMap : childrenList) {
+                    String childName = (String) childMap.get("name");
+                    if (StringUtils.containsIgnoreCase(childName, dirName)) {
+                        retMap = childMap;
+                        break;
+                    }
+                }
+            }
+        }
+        return  retMap;
+    }