ソースを参照

feat: 可靠性预计

NickOooo 2 週間 前
コミット
83af84d195

+ 25 - 2
nationrel-module-rp-biz/src/main/java/com/nationrel/modules/rp/mapper/PredictionStruTreeMapper.java

@@ -19,7 +19,7 @@ public interface PredictionStruTreeMapper extends BaseMapper<PredictionStruTree>
      * @Title: updateLeftNoByChangeNum
      * @Description: 更新左序号
      */
-    void updateLeftNoByChangeNum(@Param("leftNo") Integer leftNo, @Param("changeNum") Integer changeNum, @Param("perdictionId") String perdictionId);
+    void updateLeftNoByChangeNum(@Param("leftNo") Integer leftNo, @Param("changeNum") Integer changeNum, @Param("predictionId") String predictionId);
 
     /**
      * @param rightNo   右序号
@@ -28,6 +28,29 @@ public interface PredictionStruTreeMapper extends BaseMapper<PredictionStruTree>
      * @Title: updateRightNoByChangeNum
      * @Description: 更新右序号
      */
-    void updateRightNoByChangeNum(@Param("rightNo") Integer rightNo, @Param("changeNum") Integer changeNum, @Param("perdictionId") String perdictionId);
+    void updateRightNoByChangeNum(@Param("rightNo") Integer rightNo, @Param("changeNum") Integer changeNum, @Param("predictionId") String predictionId);
 
+    void updateLeftRightNoBecauseRemove(@Param("predictionId") String predictionId, @Param("leftNo") Integer leftNo, @Param("rightNo") Integer rightNo, @Param("offset") Integer offset, @Param("offsetDeep") int offsetDeep);
+
+    /**
+     * @Title: updateLeftNoInPartTree
+     * @Description: 由于子树的增删, 批量调整左序号.
+     * @param predictionId
+     * @param leftNo 左序号
+     * @param maxNo 最大序号
+     * @param offset void
+     */
+    void updateLeftNoInPartTree(@Param("predictionId") String predictionId, @Param("leftNo")Integer leftNo, @Param("maxNo")  Integer maxNo, @Param("offset") int offset);
+
+    /**
+     * @Title: updateRightNoInPartTree
+     * @Description: 由于子树的增删, 批量调整右序号.
+     * @param predictionId
+     * @param rightNo 右序号
+     * @param maxNo 最大序号
+     * @param offset void
+     */
+    void updateRightNoInPartTree(@Param("predictionId") String predictionId, @Param("rightNo") Integer rightNo, @Param("maxNo")  Integer maxNo, @Param("offset") int offset);
+
+    void updateParentStructureId(@Param("predictionId") String predictionId, @Param("leftNo")  int leftNo, @Param("rightNo")  int rightNo, @Param("enableStructureId") String enableStructureId, @Param("structureId") String structureId);
 }

+ 52 - 2
nationrel-module-rp-biz/src/main/java/com/nationrel/modules/rp/mapper/xml/PredictionStruTreeMapper.xml

@@ -7,7 +7,7 @@
         update
             PREDICTION_STRU_TREE
         set LEFT_NO = LEFT_NO + #{changeNum}
-        where PREDICTION_ID = #{perdictionId}
+        where PREDICTION_ID = #{predictionId}
           and <![CDATA[ LEFT_NO >= #{leftNo}
         ]]>
     </update>
@@ -17,8 +17,58 @@
         update
             PREDICTION_STRU_TREE
         set RIGHT_NO = RIGHT_NO + #{changeNum}
-        where PREDICTION_ID = #{perdictionId}
+        where PREDICTION_ID = #{predictionId}
           and <![CDATA[RIGHT_NO >= #{rightNo}
         ]]>
     </update>
+
+    <update id="updateLeftRightNoBecauseRemove">
+        update
+            PREDICTION_STRU_TREE
+        set
+            LEFT_NO = LEFT_NO + #{offset},
+            RIGHT_NO = RIGHT_NO + #{offset},
+            DEEP = DEEP + #{offsetDeep}
+        where
+            PREDICTION_ID = #{predictionId}
+            and LEFT_NO <![CDATA[ >= ]]> #{leftNo}
+            and RIGHT_NO <![CDATA[ <= ]]> #{rightNo}
+    </update>
+
+    <!-- 由于子树的增删, 批量调整左序号. -->
+    <update id="updateLeftNoInPartTree">
+        update
+            PREDICTION_STRU_TREE
+        set
+            LEFT_NO = LEFT_NO + #{offset}
+        where
+            PREDICTION_ID = #{predictionId}
+          and LEFT_NO <![CDATA[ >= ]]> #{leftNo}
+          and LEFT_NO <![CDATA[ <= ]]> #{maxNo}
+    </update>
+
+    <!-- 由于子树的增删, 批量调整右序号. -->
+    <update id="updateRightNoInPartTree">
+        update
+            PREDICTION_STRU_TREE
+        set
+            RIGHT_NO = RIGHT_NO + #{offset}
+        where
+            PREDICTION_ID = #{predictionId}
+          and RIGHT_NO <![CDATA[ >= ]]> #{rightNo}
+          and RIGHT_NO <![CDATA[ <= ]]> #{maxNo}
+    </update>
+
+    <!-- 原上级节点等于A的更改为B -->
+    <update id="updateParentStructureId">
+        update
+            PREDICTION_STRU_TREE
+        set
+            PARENT_STRU_ID = #{structureId}
+        where
+            PREDICTION_ID = #{predictionId}
+          and PARENT_STRU_ID = #{enableStructureId}
+          and LEFT_NO <![CDATA[ >= ]]> #{leftNo}
+          and RIGHT_NO <![CDATA[ <= ]]> #{rightNo}
+    </update>
 </mapper>

+ 70 - 3
nationrel-module-rp-biz/src/main/java/com/nationrel/modules/rp/service/impl/PredictionStruTreeServiceImpl.java

@@ -294,7 +294,7 @@ public class PredictionStruTreeServiceImpl extends ServiceImpl<PredictionStruTre
                 .orderByAsc(PredictionStruTree::getLeftNo)
                 .last("limit 0, 1"));
 
-        PredictionStruTree parentRdfmStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+        PredictionStruTree parentStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
                 .eq(PredictionStruTree::getPredictionId, pasteStructureReq.getPredictionId())
                 .eq(PredictionStruTree::getStruId, pasteStructureReq.getStruId()));
 
@@ -308,11 +308,11 @@ public class PredictionStruTreeServiceImpl extends ServiceImpl<PredictionStruTre
             }
 
             // 拷贝
-            this.copy(sysUser, parentRdfmStruTree, pasteStructureReq.getPredictionId(),
+            this.copy(sysUser, parentStruTree, pasteStructureReq.getPredictionId(),
                     pasteStructureReq.getStruId(), copyStruTree,
                     pasteStructureReq.getSrcStruId(), no);
         } else if (pasteStructureReq.getOptType() == 2) {
-
+            this.cut(sysUser, parentStruTree, pasteStructureReq.getPredictionId(), parentStruTree.getStruId(), copyStruTree, copyStruTree.getStruId());
         }
 
     }
@@ -595,4 +595,71 @@ public class PredictionStruTreeServiceImpl extends ServiceImpl<PredictionStruTre
         importingTree.clear();
         return newStruIdMap;
     }
+
+    private void cut(LoginUser user, PredictionStruTree parentStruTree, String predictionId,
+                     String parentStruId, PredictionStruTree copyStruTree, String copyStruId) throws Exception {
+        PredictionStruTree rootStructNode = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+                .eq(PredictionStruTree::getPredictionId, predictionId)
+                .eq(PredictionStruTree::getParentStruId, RpConstant.ROOTNODE_PARENT));
+
+        // (2.1)将拷贝节点排除在树外(排除方法左右序号都+根结点右序号+前次假删的节点数*2)。便于以后更新。
+        predictionStruTreeMapper.updateLeftRightNoBecauseRemove(predictionId, copyStruTree.getLeftNo(),
+                copyStruTree.getRightNo(), rootStructNode.getRightNo(), 0);
+        int offset = copyStruTree.getRightNo() - copyStruTree.getLeftNo() + 1;
+
+        // (2.2)将拷贝节点排除在树外,余下节点左右序号重新顺处理;
+        predictionStruTreeMapper.updateLeftNoInPartTree(predictionId, copyStruTree.getLeftNo(), rootStructNode.getRightNo(), -offset);
+        predictionStruTreeMapper.updateRightNoInPartTree(predictionId, copyStruTree.getRightNo(), rootStructNode.getRightNo(), -offset);
+
+        // (2.3)将拷贝节点排除在树外,原上级节点类型更改
+        PredictionStruTree copyParentStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+                .eq(PredictionStruTree::getPredictionId, predictionId)
+                .eq(PredictionStruTree::getStruId, copyStruTree.getParentStruId()));
+        if (copyParentStruTree.getRightNo() - copyParentStruTree.getLeftNo() == 1) {
+            copyParentStruTree.setType(RpConstant.TREENODE_TYPE_LEAF);
+            copyParentStruTree.setUpdateUserBy(user.getUsername());
+            copyParentStruTree.setUpdateTime(new Date());
+            predictionStruTreeMapper.updateById(copyParentStruTree);
+        }
+
+        // (2.5) 被粘贴节点的类型更改
+        parentStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+                .eq(PredictionStruTree::getPredictionId, predictionId)
+                .eq(PredictionStruTree::getStruId, parentStruId));
+        if (RpConstant.TREENODE_TYPE_LEAF.equals(parentStruTree.getType())) {
+            parentStruTree.setType(RpConstant.TREENODE_TYPE_NONLEAF);
+            parentStruTree.setUpdateUserBy(user.getUsername());
+            parentStruTree.setUpdateTime(new Date());
+            predictionStruTreeMapper.updateById(parentStruTree);
+        }
+
+        // 取得剪切节点在新上级节点下的位置
+        int rightNo = parentStruTree.getRightNo();
+        PredictionStruTree sonNodeOfStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+                .eq(PredictionStruTree::getPredictionId, predictionId)
+                .eq(PredictionStruTree::getParentStruId, parentStruId)
+                .gt(PredictionStruTree::getLeftNo, parentStruTree.getLeftNo())
+                .lt(PredictionStruTree::getRightNo, parentStruTree.getRightNo())
+                .orderByDesc(PredictionStruTree::getLeftNo)
+                .last("limit 1"));
+        if (ObjectUtils.isNotEmpty(sonNodeOfStruTree)) {
+            // 兄弟节点的最大右序号
+            rightNo = sonNodeOfStruTree.getRightNo() + 1;
+        }
+
+        // (2.6) 被粘贴节点下, 左右序号,被剪切节点数量的预留
+        predictionStruTreeMapper.updateLeftNoInPartTree(predictionId, rightNo, rootStructNode.getRightNo(), offset);
+        predictionStruTreeMapper.updateRightNoInPartTree(predictionId, rightNo, rootStructNode.getRightNo(), offset);
+
+        copyStruTree = predictionStruTreeMapper.selectOne(new LambdaQueryWrapper<PredictionStruTree>()
+                .eq(PredictionStruTree::getPredictionId, predictionId)
+                .eq(PredictionStruTree::getStruId, copyStruId));
+        int minusOffset = copyStruTree.getLeftNo() - (rightNo);
+        // (2.7) 剪切节点的上级节点修改, 左右序号,深度,序号
+        predictionStruTreeMapper.updateParentStructureId(predictionId, copyStruTree.getLeftNo(), copyStruTree.getRightNo(),
+                copyStruTree.getParentStruId(), parentStruId);
+
+        predictionStruTreeMapper.updateLeftRightNoBecauseRemove(predictionId, copyStruTree.getLeftNo(),
+                copyStruTree.getRightNo(), -minusOffset, parentStruTree.getDeep() - copyStruTree.getDeep() + 1);
+    }
 }