From f3ad14f8af7fb651426d1ee617e7ecb9d3fc9aab Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期四, 28 三月 2024 11:15:52 +0800
Subject: [PATCH] 新增产品节点上设置关系,可设置项为“无/旁联/表决”

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java |   76 ++++++++++++++++++++++++++++++++++----
 1 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
index ec0f8a3..24ca30a 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
@@ -17,10 +17,14 @@
 import org.dom4j.DocumentHelper;
 import org.dom4j.Document;
 import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.zt.common.db.query.QueryFilter;
 import org.springframework.transaction.annotation.Transactional;
+
+import java.io.StringWriter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -121,23 +125,67 @@
 
         // 1. 瑙f瀽鍑鸿妭鐐逛笌杈�
         getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList);
-        // 2. 璁$畻鎵�鏈夎妭鐐圭殑鍏ュ彛绾挎暟鍙婂嚭鍙g嚎鏁�
+        // 2. 瀵逛簬鏈夊鏍瑰叆鍙g嚎鐨勪骇鍝佽妭鐐癸紝灏嗗叾涓婄殑琛ㄥ喅銆佹梺鑱斿叧绯诲墺绂绘垚杩愮畻绗﹁妭鐐癸紝娣诲姞鍒拌鑺傜偣鐨勫墠闈紝骞舵坊鍔犵浉搴旂殑杈�
+        peelOperationFromProductNode(modelRbd.getId(), modelNodeList, modelLineList);
+        // 3. 璁$畻鎵�鏈夎妭鐐圭殑鍏ュ彛绾挎暟鍙婂嚭鍙g嚎鏁�
         calcInOutLineNumAllNode(modelNodeList, modelLineList);
-        // 3. 澶嶅埗浜у搧鑺傜偣(node)鍒發ist
+        // 4. 澶嶅埗浜у搧鑺傜偣(node)鍒發ist
         List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item ->
                 "node".equals(item.getNodeType())).collect(Collectors.toList());
-        // 4. 涓嶆柇灏嗗熀鏈ā鍨嬶紙涓茶仈銆佸苟鑱斻�佹梺鑱斻�佽〃鍐炽�佹ˉ鑱旓級鏇挎崲涓鸿櫄鑺傜偣鑰岀畝鍖栧浘褰紝鐩磋嚦鏃犳硶绠�鍖栦负姝€��
+        // 5. 涓嶆柇灏嗗熀鏈ā鍨嬶紙涓茶仈銆佸苟鑱斻�佹梺鑱斻�佽〃鍐炽�佹ˉ鑱旓級鏇挎崲涓鸿櫄鑺傜偣鑰岀畝鍖栧浘褰紝鐩磋嚦鏃犳硶绠�鍖栦负姝€��
         result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList);
 
-        // 5. 杞崲涓虹畻娉曞簱鎺ュ彛XML
+        // 6. 杞崲涓虹畻娉曞簱鎺ュ彛XML
         if (result) {
             result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
         }
 
-        // 6. 淇濆瓨妯″瀷
+        // 7. 淇濆瓨妯″瀷
         if (saveFlag) saveModel(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList);
 
         return result;
+    }
+
+    private void peelOperationFromProductNode(Long modelId,
+                                              List<ModelNode> modelNodeList,
+                                              List<ModelLine> modelLineList) {
+        List<ModelNode> nodesToAdd = new ArrayList<>();
+        List<ModelLine> linesToAdd = new ArrayList<>();
+        for (ModelNode node: modelNodeList) {
+            List<ModelLine> inLineList = modelLineList.stream().filter(item ->
+                    item.getEndCell().equals(node.getPicId())).collect(Collectors.toList());
+            if ("node".equals(node.getNodeType()) &&
+                    StringUtils.isNotBlank(node.getNodeTypeExt()) &&
+                    inLineList.size() > 1) {
+                // 鏃佽仈or琛ㄥ喅
+                ModelNode nodeNew =  new ModelNode();
+                Long nodeNewId = UUIDUtil.generateId();
+                nodeNew.setId(nodeNewId);
+                nodeNew.setPicId(nodeNewId.toString());
+                nodeNew.setModelId(modelId);
+                nodeNew.setNodeType(node.getNodeTypeExt());
+                nodeNew.setName(node.getNodeTypeExt());
+                nodeNew.setVoteNum(node.getVoteNum());
+                nodeNew.setPositionX(node.getPositionX());
+                nodeNew.setPositionY(node.getPositionY());
+                nodesToAdd.add(nodeNew);
+
+                ModelLine lineNew = new ModelLine();
+                Long lineNewId = UUIDUtil.generateId();
+                lineNew.setId(lineNewId);
+                lineNew.setPicId(lineNewId.toString());
+                lineNew.setModelId(modelId);
+                lineNew.setBeginCell(nodeNewId.toString());
+                lineNew.setEndCell(node.getPicId());
+                linesToAdd.add(lineNew);
+
+                for(ModelLine line: inLineList){
+                    line.setEndCell(nodeNewId.toString());
+                }
+            }
+        }
+        modelNodeList.addAll(nodesToAdd);
+        modelLineList.addAll(linesToAdd);
     }
 
     private boolean createIfXmlFromRbd(ModelRbd modelRbd,
@@ -175,9 +223,20 @@
             block = link.addElement("Block");
             block.addAttribute("Name", "Start");
 
-            document.setXMLEncoding("UTF-8");
-            String xmlString = document.asXML();
-            modelRbd.setIfXml(xmlString);
+//            document.setXMLEncoding("UTF-8");
+//            String xmlString = document.asXML();
+            // 杈撳嚭鏍煎紡鍖杧ml
+            XMLWriter xmlWriter = null;
+            try {
+                OutputFormat format = OutputFormat.createPrettyPrint();
+                format.setEncoding("UTF-8");
+                StringWriter writer = new StringWriter();
+                xmlWriter = new XMLWriter(writer, format);
+                xmlWriter.write(document);
+                modelRbd.setPublishedXml(writer.toString());
+            } finally {
+                if (xmlWriter!=null) xmlWriter.close();
+            }
         } catch (Exception e) {
             e.printStackTrace();
             result = false;
@@ -1162,6 +1221,7 @@
         }
 
         // 鏇存柊RBD鏁版嵁
+        modelRbd.setPublishedContent(modelRbd.getContent());
         modelRbdDao.updateById(modelRbd);
     }
 

--
Gitblit v1.9.1