|
@@ -8,6 +8,8 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+const Ledger = require('../lib/ledger');
|
|
|
+
|
|
|
class loadStageExcelTree {
|
|
|
constructor(ctx) {
|
|
|
this.ctx = ctx;
|
|
@@ -48,7 +50,7 @@ class loadStageExcelTree {
|
|
|
if (node.b_code) {
|
|
|
if (x.has_pos === undefined) {
|
|
|
const relaPos = self.pos.getLedgerPos(x.id);
|
|
|
- x.has_pos = !!relaPos && relaPos.length > 0;
|
|
|
+ x.has_pos = !!(relaPos && relaPos.length > 0);
|
|
|
}
|
|
|
return node.b_code === _.trimEnd(x.b_code) && node.name === _.trimEnd(x.name) && node.unit === _.trimEnd(x.unit)
|
|
|
&& node.unit_price === x.unit_price && node.has_pos === x.has_pos;
|
|
@@ -122,7 +124,7 @@ class loadStageExcelTree {
|
|
|
}
|
|
|
loadNode(node, parent) {
|
|
|
node.is_leaf = !node.children || node.children.length === 0 ? 1 : 0;
|
|
|
- node.has_pos = node.pos && node.pos.length > 0;
|
|
|
+ node.has_pos = !!(node.pos && node.pos.length > 0);
|
|
|
const cur = this.findNode(node, parent);
|
|
|
if (!cur || cur.settle_status === this.settleStatus.finish) return;
|
|
|
|
|
@@ -144,8 +146,31 @@ class loadStageExcelTree {
|
|
|
this.loadNode(node, null);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ loadDealNode(node, parent, pos) {
|
|
|
+ node.pos = pos.getLedgerPos(node.id) || [];
|
|
|
+ node.has_pos = node.pos.length > 0;
|
|
|
+ const cur = this.findNode(node, parent);
|
|
|
+ if (!cur || cur.settle_status === this.settleStatus.finish) return;
|
|
|
+
|
|
|
+ if (cur) {
|
|
|
+ if (!node.b_code) this.loadDgn(node, cur);
|
|
|
+ if (node.is_leaf) {
|
|
|
+ this.loadLeaf(node, cur);
|
|
|
+ } else {
|
|
|
+ for (const c of node.children) {
|
|
|
+ this.loadDealNode(c, cur, pos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loadDeal(dealTree, dealPos, source) {
|
|
|
+ this.init(source);
|
|
|
+ for (const node of dealTree.children) {
|
|
|
+ this.loadDealNode(node, null, dealPos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
module.exports = app => {
|
|
|
class StageStash extends app.BaseService {
|
|
@@ -423,6 +448,64 @@ module.exports = app => {
|
|
|
throw '解析Excel错误';
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async loadStageDealData(stage, dealData) {
|
|
|
+ try {
|
|
|
+ const dealTree = new Ledger.billsTree(this.ctx, {
|
|
|
+ id: 'ledger_id',
|
|
|
+ pid: 'ledger_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ });
|
|
|
+ const dealPos = new Ledger.pos({ id: 'id', ledgerId: 'lid' });
|
|
|
+ dealTree.loadDatas(dealData.ledger);
|
|
|
+ dealPos.loadDatas(dealData.pos);
|
|
|
+
|
|
|
+ const ledgerData = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
+ columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price'],
|
|
|
+ where: { tender_id: stage.tid},
|
|
|
+ });
|
|
|
+ const extraData = await this.ctx.service.ledgerExtra.getData(this.ctx.tender.id, ['is_tp']);
|
|
|
+ const settleStatusBills = stage.readySettle ? await this.ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
|
|
|
+ this.ctx.helper.assignRelaData(ledgerData, [
|
|
|
+ { data: extraData, fields: ['is_tp'], prefix: '', relaId: 'id' },
|
|
|
+ { data: settleStatusBills, fields: ['settle_status'], prefix: '', relaId: 'lid' },
|
|
|
+ ]);
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({
|
|
|
+ columns: ['id', 'lid', 'name', 'porder'],
|
|
|
+ where: { tid: stage.tid },
|
|
|
+ });
|
|
|
+ const settleStatusPos = stage.readySettle ? await this.ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ { data: settleStatusPos, fields: ['settle_status'], prefix: '', relaId: 'pid' },
|
|
|
+ ]);
|
|
|
+ const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
+ const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
+ const stageBillsDgn = await this.ctx.service.stageBillsDgn.getAllDataByCondition({ where: { tid: stage.tid } });
|
|
|
+
|
|
|
+ const loadModal = new loadStageExcelTree(this.ctx);
|
|
|
+ loadModal.loadDeal(dealTree, dealPos, { ledgerData, posData, stageBills, stagePos, stageBillsDgn, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
|
|
|
+
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ if (loadModal.insertBills.length > 0) conn.insert(this.ctx.service.stageBills.tableName, loadModal.insertBills);
|
|
|
+ if (loadModal.updateBills.length > 0) conn.updateRows(this.ctx.service.stageBills.tableName, loadModal.updateBills);
|
|
|
+ if (loadModal.insertPos.length > 0) conn.insert(this.ctx.service.stagePos.tableName, loadModal.insertPos);
|
|
|
+ if (loadModal.updatePos.length > 0) conn.updateRows(this.ctx.service.stagePos.tableName, loadModal.updatePos);
|
|
|
+ if (loadModal.insertDgn.length > 0) conn.insert(this.ctx.service.stageBillsDgn.tableName, loadModal.insertDgn);
|
|
|
+ if (loadModal.updateDgn.length > 0) conn.updateRows(this.ctx.service.stageBillsDgn.tableName, loadModal.updateDgn);
|
|
|
+ await conn.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await conn.rollback();
|
|
|
+ this.ctx.log(err);
|
|
|
+ throw '保存导入数据失败';
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ this.ctx.log(err);
|
|
|
+ throw '导入本期合同计量';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return StageStash;
|