|
@@ -22,7 +22,6 @@ class loadGclBaseTree {
|
|
this.splitChar = '-';
|
|
this.splitChar = '-';
|
|
// 索引
|
|
// 索引
|
|
// 以code为索引
|
|
// 以code为索引
|
|
- this.codeNodes = {};
|
|
|
|
this.items = [];
|
|
this.items = [];
|
|
|
|
|
|
// 缓存
|
|
// 缓存
|
|
@@ -39,8 +38,10 @@ class loadGclBaseTree {
|
|
if (!parent.children) return null;
|
|
if (!parent.children) return null;
|
|
|
|
|
|
for (const child of parent.children) {
|
|
for (const child of parent.children) {
|
|
- if (child.b_code === node.b_code && child.name === node.name && child.unit === node.unit) return child;
|
|
|
|
|
|
+ const checkLeaf = (child.is_leaf && node.is_leaf) || (!child.is_leaf && !node.is_leaf);
|
|
|
|
+ if (child.b_code === node.b_code && child.name === node.name && child.unit === node.unit && checkLeaf) return child;
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -50,11 +51,12 @@ class loadGclBaseTree {
|
|
* @returns {*}
|
|
* @returns {*}
|
|
*/
|
|
*/
|
|
addNode(source, parent) {
|
|
addNode(source, parent) {
|
|
|
|
+ if (source.b_code === '101') console.log('101 parent', parent);
|
|
parent = parent ? parent : this.parent;
|
|
parent = parent ? parent : this.parent;
|
|
- if (!parent.children) parent.children = [];
|
|
|
|
-
|
|
|
|
let node = this.findNode(source, parent);
|
|
let node = this.findNode(source, parent);
|
|
|
|
+ if (source.b_code === '101') console.log('101 cur', node);
|
|
if (!node) {
|
|
if (!node) {
|
|
|
|
+ if (!parent.children) parent.children = [];
|
|
node = {
|
|
node = {
|
|
id: this.ctx.app.uuid.v4(),
|
|
id: this.ctx.app.uuid.v4(),
|
|
tender_id: this.ctx.tender.id,
|
|
tender_id: this.ctx.tender.id,
|
|
@@ -67,6 +69,10 @@ class loadGclBaseTree {
|
|
b_code: source.b_code,
|
|
b_code: source.b_code,
|
|
name: source.name,
|
|
name: source.name,
|
|
unit: source.unit,
|
|
unit: source.unit,
|
|
|
|
+ sgfh_qty: 0,
|
|
|
|
+ qtcl_qty: 0,
|
|
|
|
+ sjcl_qyt: 0,
|
|
|
|
+ quantity: 0,
|
|
};
|
|
};
|
|
this.keyNodeId += 1;
|
|
this.keyNodeId += 1;
|
|
parent.children.push(node);
|
|
parent.children.push(node);
|
|
@@ -104,6 +110,83 @@ class loadLedgerGclTree extends loadGclBaseTree {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+class updateReviseGclTree extends loadGclBaseTree {
|
|
|
|
+ constructor (ctx, setting) {
|
|
|
|
+ super(ctx, setting);
|
|
|
|
+ this.baseNodes = [];
|
|
|
|
+ }
|
|
|
|
+ loadBase(datas) {
|
|
|
|
+ datas.sort((x, y) => { return x.level === y.level ? x.order - y.order : x.level - y.level; });
|
|
|
|
+ const Index = {};
|
|
|
|
+ for (const d of datas) {
|
|
|
|
+ const parent = this.parent.ledger_id === d.ledger_pid ? this.parent : Index[d.ledger_pid];
|
|
|
|
+ if (!parent) continue;
|
|
|
|
+
|
|
|
|
+ if (!parent.children) parent.children = [];
|
|
|
|
+ const baseNode = {
|
|
|
|
+ id: d.id,
|
|
|
|
+ ledger_id: d.ledger_id,
|
|
|
|
+ ledger_pid: d.ledger_pid,
|
|
|
|
+ level: d.level,
|
|
|
|
+ is_leaf: d.is_leaf,
|
|
|
|
+ full_path: d.full_path,
|
|
|
|
+ b_code: d.b_code,
|
|
|
|
+ name: d.name,
|
|
|
|
+ unit: d.unit,
|
|
|
|
+ unit_price: d.unit_price,
|
|
|
|
+ org_sgfh_qty: d.sgfh_qty || 0,
|
|
|
|
+ org_sjcl_qty: d.sjcl_qty || 0,
|
|
|
|
+ org_qtcl_qty: d.qtcl_qty || 0,
|
|
|
|
+ org_qty: d.quantity || 0,
|
|
|
|
+ org_order: d.order,
|
|
|
|
+ sgfh_qty: 0,
|
|
|
|
+ sjcl_qty: 0,
|
|
|
|
+ qtcl_qty: 0,
|
|
|
|
+ quantity: 0,
|
|
|
|
+ };
|
|
|
|
+ parent.children.push(baseNode);
|
|
|
|
+ Index[baseNode.ledger_id] = baseNode;
|
|
|
|
+ this.baseNodes.push(baseNode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ gather(source, parent) {
|
|
|
|
+ const node = this.addNode(source, parent);
|
|
|
|
+ if (source.b_code === '207-2-1') console.log('207-2-1', node, source);
|
|
|
|
+ node.sgfh_qty = this.ctx.helper.add(node.sgfh_qty, source.sgfh_qty);
|
|
|
|
+ node.qtcl_qty = this.ctx.helper.add(node.qtcl_qty, source.qtcl_qty);
|
|
|
|
+ node.sjcl_qty = this.ctx.helper.add(node.sjcl_qty, source.sjcl_qty);
|
|
|
|
+ node.quantity = this.ctx.helper.add(node.quantity, source.quantity);
|
|
|
|
+ return node;
|
|
|
|
+ }
|
|
|
|
+ getUpdateData() {
|
|
|
|
+ const result = {update: [], errors: [], create: []};
|
|
|
|
+ if (this.baseNodes.length === 0) {
|
|
|
|
+ result.update = [{id: this.parent.id, is_leaf: false}];
|
|
|
|
+ } else {
|
|
|
|
+ for (const bn of this.baseNodes) {
|
|
|
|
+ if (bn.children && bn.children.length > 0) continue;
|
|
|
|
+
|
|
|
|
+ if (bn.sjcl_qty < bn.org_sjcl_qty || bn.qtcl_qty < bn.org_qtcl_qty || bn.sgfh_qty < bn.org_sgfh_qty) {
|
|
|
|
+ result.errors.push(bn);
|
|
|
|
+ } else if (bn.sjcl_qty !== bn.org_sjcl_qty || bn.qtcl_qty !== bn.org_qtcl_qty || bn.sgfh_qty !== bn.org_sgfh_qty) {
|
|
|
|
+ result.update.push({
|
|
|
|
+ id: bn.id, sgfh_qty: bn.sgfh_qty, sjcl_qty: bn.sjcl_qty, qtcl_qty: bn.qtcl_qty, quantity: bn.quantity,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (const i of this.items) {
|
|
|
|
+ result.create.push({
|
|
|
|
+ id: i.id, tender_id: i.tender_id, ledger_id: i.ledger_id, ledger_pid: i.ledger_pid,
|
|
|
|
+ level: i.level, order: i.order, full_path: i.full_path, is_leaf: !i.children || i.children.length === 0,
|
|
|
|
+ b_code: i.b_code, name: i.name, unit: i.unit,
|
|
|
|
+ sgfh_qty: i.sgfh_qty, sjcl_qty: i.sjcl_qty, qtcl_qty: i.qtcl_qty, quantity: i.quantity,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
class sumLoad {
|
|
class sumLoad {
|
|
constructor (ctx) {
|
|
constructor (ctx) {
|
|
this.ctx = ctx;
|
|
this.ctx = ctx;
|
|
@@ -140,6 +223,33 @@ class sumLoad {
|
|
}
|
|
}
|
|
return this.loadTree;
|
|
return this.loadTree;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async updateGatherGcl(select, maxId, tenders, defaultData) {
|
|
|
|
+ this.loadTree = new updateReviseGclTree(this.ctx, {
|
|
|
|
+ parent: select, maxId, type: 'ledger', defaultData,
|
|
|
|
+ });
|
|
|
|
+ const posterity = await this.ctx.service.reviseBills.getPosterityByParentId(this.ctx.tender.id, select.ledger_id);
|
|
|
|
+ this.loadTree.loadBase(posterity);
|
|
|
|
+
|
|
|
|
+ for (const tender of tenders) {
|
|
|
|
+ const billsData = await this.ctx.service.ledger.getData(tender.tid);
|
|
|
|
+ const billsTree = new Ledger.billsTree(this.ctx, {
|
|
|
|
+ id: 'ledger_id',
|
|
|
|
+ pid: 'ledger_pid',
|
|
|
|
+ order: 'order',
|
|
|
|
+ level: 'level',
|
|
|
|
+ rootId: -1,
|
|
|
|
+ keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
|
+ stageId: 'id',
|
|
|
|
+ });
|
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
|
+ for (const top of billsTree.children) {
|
|
|
|
+ if ([1].indexOf(top.node_type) < 0) continue;
|
|
|
|
+ this.recusiveLoadGatherGcl(top, null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return this.loadTree;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = sumLoad;
|
|
module.exports = sumLoad;
|