浏览代码

导入接口,组织措施项目节点NextSiblingID问题,树结构自检方法

zhongzewei 6 年之前
父节点
当前提交
58f280921c
共有 3 个文件被更改,包括 56 次插入14 次删除
  1. 40 0
      public/web/id_tree.js
  2. 3 2
      web/building_saas/main/js/models/importStandardInterface.js
  3. 13 12
      web/building_saas/pm/js/pm_tree.js

+ 40 - 0
public/web/id_tree.js

@@ -758,6 +758,46 @@ var idTree = {
             let node = this.nodes[this.prefix+ID];
             return node;
         };
+        //检查树结构数据有没问题
+        Tree.prototype.check = function (roots) {
+            return isValid(roots);
+            function isValid(nodes) {
+                for (let node of nodes) {
+                    if (node.data.ParentID !== -1 &&
+                        (!node.parent || node.parent.data.ID !== node.data.ParentID)) {
+                        console.log(`${node.serialNo() + 1}:${node.data.name} parent对应错误`);
+                        return false;
+                    }
+                    if (node.data.ParentID === -1 && node.parent) {
+                        console.log(`${node.serialNo() + 1}:${node.data.name} 不应有parent`);
+                        return false;
+                    }
+                    if (node.data.NextSiblingID !== -1 &&
+                        (!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)) {
+                        console.log(`${node.serialNo() + 1}:${node.data.name} next对应错误`);
+                        return false;
+                    }
+                    if (node.data.NextSiblingID === -1 && node.nextSibling) {
+                        console.log(`${node.serialNo() + 1}:${node.data.name} 不应有next`);
+                        return false;
+                    }
+                    let sameDepthNodes = node.parent ? node.parent.children : roots,
+                        nodeIdx = sameDepthNodes.indexOf(node),
+                        nextIdx = sameDepthNodes.indexOf(node.nextSibling);
+                    if (nodeIdx !== -1 && nextIdx !== -1 && nodeIdx > nextIdx) {
+                        console.log(`${node.serialNo() + 1}:${node.data.name} node索引大于next索引`);
+                        return false;
+                    }
+                    if (node.children.length) {
+                        let v = isValid(node.children);
+                        if (!v) {
+                            return false;
+                        }
+                    }
+                }
+                return true;
+            }
+        };
         return new Tree(setting);
     },
     updateType: {update: 'update', new: 'new', delete: 'delete'}

+ 3 - 2
web/building_saas/main/js/models/importStandardInterface.js

@@ -1064,10 +1064,11 @@ const ImportXML = (() => {
                     zzcsSubs.push(item);
                 }
             }
+            addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
+            //更新原本的最后一个节点
             if (zzcsSubs.length && lastItem) {
-                zzcsSubs[0].NextSiblingID = lastItem.ID;
+                lastItem.NextSiblingID = zzcsSubs[0].ID;
             }
-            addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
             //技术措施
             addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
             //暂列金额

+ 13 - 12
web/building_saas/pm/js/pm_tree.js

@@ -374,32 +374,33 @@ const pmTree = {
 
             };
 
-            Tree.prototype.check = function (roots, _root) {
-                return isValid(roots);
+            Tree.prototype.check = function (_root) {
+                return isValid(_root.children);
                 function isValid(nodes) {
                     for (let node of nodes) {
                         if (node.data.ParentID !== -1 &&
                             (!node.parent || node.parent.data.ID !== node.data.ParentID)) {
-                            console.log(node);
-                            console.log(`node.data.ParentID !== -1 &&
-                            (!node.parent || node.parent.data.ID !== node.data.ParentID)`);
+                            console.log(`${node.serialNo() + 1}:${node.data.name} parent对应错误`);
                             return false;
                         }
                         if (node.data.ParentID === -1 && node.parent && node.parent !== _root) {
-                            console.log(node);
-                            console.log(`node.data.ParentID === -1 && node.parent && node.parent !== roots`);
+                            console.log(`${node.serialNo() + 1}:${node.data.name} 不应有parent`);
                             return false;
                         }
                         if (node.data.NextSiblingID !== -1 &&
                             (!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)) {
-                            console.log(node);
-                            console.log(`node.data.NextSiblingID !== -1 &&
-                            (!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)`);
+                            console.log(`${node.serialNo() + 1}:${node.data.name} next对应错误`);
                             return false;
                         }
                         if (node.data.NextSiblingID === -1 && node.nextSibling) {
-                            console.log(node);
-                            console.log(`node.data.NextSiblingID === -1 && node.nextSibling`);
+                            console.log(`${node.serialNo() + 1}:${node.data.name} 不应有next`);
+                            return false;
+                        }
+                        let parent = node.parent,
+                            nodeIdx = parent.children.indexOf(node),
+                            nextIdx = parent.children.indexOf(node.nextSibling);
+                        if (nodeIdx !== -1 && nextIdx !== -1 && nodeIdx > nextIdx) {
+                            console.log(`${node.serialNo() + 1}:${node.data.name} node索引大于next索引`);
                             return false;
                         }
                         if (node.children.length) {