|
@@ -162,7 +162,7 @@ class YbpImportTree {
|
|
|
// x.unit_price === data.unit_price;
|
|
// x.unit_price === data.unit_price;
|
|
|
// });
|
|
// });
|
|
|
}
|
|
}
|
|
|
- _importNode(node, parent, loadRelaFun, filter) {
|
|
|
|
|
|
|
+ _importNode(node, parent, loadRelaFun, filter, forceMerge = false) {
|
|
|
|
|
|
|
|
const setting = this.setting;
|
|
const setting = this.setting;
|
|
|
const compareData = { kind: node.kind };
|
|
const compareData = { kind: node.kind };
|
|
@@ -178,7 +178,7 @@ class YbpImportTree {
|
|
|
: 0;
|
|
: 0;
|
|
|
if (filter && filter(node, compareData, isXmj)) return;
|
|
if (filter && filter(node, compareData, isXmj)) return;
|
|
|
|
|
|
|
|
- let cur = (this.importType === YbpImportType.merge && defaultMerge.indexOf(compareData.kind) >= 0)
|
|
|
|
|
|
|
+ let cur = forceMerge || (this.importType === YbpImportType.merge && defaultMerge.indexOf(compareData.kind) >= 0)
|
|
|
? this._findNode(compareData, parent)
|
|
? this._findNode(compareData, parent)
|
|
|
: null;
|
|
: null;
|
|
|
if (!cur) {
|
|
if (!cur) {
|
|
@@ -221,8 +221,16 @@ class YbpImportTree {
|
|
|
}
|
|
}
|
|
|
return cur;
|
|
return cur;
|
|
|
}
|
|
}
|
|
|
- importTree(tree, unitName, loadRelaFun, filter) {
|
|
|
|
|
- const parent = this.importType === YbpImportType.flow ? this._importNode({name: unitName}) : null;
|
|
|
|
|
|
|
+ _importUnitParent(unitParents) {
|
|
|
|
|
+ let cur;
|
|
|
|
|
+ for (const up of unitParents) {
|
|
|
|
|
+ cur = this._importNode({ name: up }, cur, null, null, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ return cur;
|
|
|
|
|
+ }
|
|
|
|
|
+ importTree(tree, unitName, unitParents, loadRelaFun, filter) {
|
|
|
|
|
+ const unitTop = this.importType === YbpImportType.flow ? this._importUnitParent(unitParents) : null;
|
|
|
|
|
+ const parent = this.importType === YbpImportType.flow ? this._importNode({name: unitName}, unitTop) : null;
|
|
|
this.unitName = unitName;
|
|
this.unitName = unitName;
|
|
|
for (const n of tree.children) {
|
|
for (const n of tree.children) {
|
|
|
this._importNode(n, parent, loadRelaFun, filter);
|
|
this._importNode(n, parent, loadRelaFun, filter);
|
|
@@ -309,8 +317,31 @@ class YbpImportTree {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const YbpUtils = {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * (限制3层)在subjects中获取节点的所有父结构节点名称project.name
|
|
|
|
|
+ * PS:仅供外部用Utils,实际上与YbpTree内部数据无关,依赖ID,parentID,如果树结构需先转换再使用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param node 节点
|
|
|
|
|
+ * @param nodes 所有节点Array
|
|
|
|
|
+ * @returns {Array} 父节点名称
|
|
|
|
|
+ */
|
|
|
|
|
+ getSubjectParentPath(node, nodes) {
|
|
|
|
|
+ const result = [];
|
|
|
|
|
+ let parent = nodes.find(x => { return x.project.ID === node.project.parentID; });
|
|
|
|
|
+ let i = 0;
|
|
|
|
|
+ while (parent && i < 4 && [3, 4].indexOf(parent.project.type) >= 0) {
|
|
|
|
|
+ result.unshift(parent.project.name);
|
|
|
|
|
+ parent = nodes.find(y => { return y.project.ID === parent.project.parentID; });
|
|
|
|
|
+ i++;
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
YbpImportType,
|
|
YbpImportType,
|
|
|
YbpTree,
|
|
YbpTree,
|
|
|
YbpImportTree,
|
|
YbpImportTree,
|
|
|
|
|
+ YbpUtils,
|
|
|
};
|
|
};
|