Browse Source

导入计量台账Excel,导入合同、变更设计数量

MaiXinRong 3 years atrás
parent
commit
79706f11df
3 changed files with 36 additions and 21 deletions
  1. 11 1
      app/lib/analysis_excel.js
  2. 5 18
      app/service/stage_bills_dgn.js
  3. 20 2
      app/service/stage_stash.js

+ 11 - 1
app/lib/analysis_excel.js

@@ -899,6 +899,10 @@ class AnalysisStageExcelTree extends AnalysisExcelTree {
             unit_price: {value: ['单价'], type: colDefineType.match},
             contract_qty: {value: ['本期合同计量|数量'], type: colDefineType.match},
             contract_tp: {value: ['本期合同计量|金额'], type: colDefineType.match},
+            deal_dgn_qty1: {value: ['合同|项目节数量1'], type: colDefineType.match},
+            deal_dgn_qty2: {value: ['合同|项目节数量2'], type: colDefineType.match},
+            qc_dgn_qty1: {value: ['变更|项目节数量1'], type: colDefineType.match},
+            qc_dgn_qty2: {value: ['变更|项目节数量2'], type: colDefineType.match},
         };
         this.needCols = ['code', 'b_code', 'pos', 'name', 'unit', 'unit_price', 'contract_qty', 'contract_tp'];
     }
@@ -933,7 +937,13 @@ class AnalysisStageExcelTree extends AnalysisExcelTree {
             node.code = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.code]));
             node.name = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.name]));
             node.unit = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.unit]));
-            return this.cacheTree.addXmjNode(node);
+            const xmj = this.cacheTree.addXmjNode(node);
+            xmj.deal_dgn_qty1 = aeUtils.toNumber(row[this.colsDef.deal_dgn_qty1]);
+            xmj.deal_dgn_qty2 = aeUtils.toNumber(row[this.colsDef.deal_dgn_qty2]);
+            xmj.c_dgn_qty1 = aeUtils.toNumber(row[this.colsDef.c_dgn_qty1]);
+            xmj.c_dgn_qty2 = aeUtils.toNumber(row[this.colsDef.c_dgn_qty2]);
+            this.ctx.helper.checkDgnQtyPrecision(xmj);
+            return xmj;
         } catch (error) {
             if (error.stack) {
                 this.ctx.logger.error(error);

+ 5 - 18
app/service/stage_bills_dgn.js

@@ -77,11 +77,8 @@ module.exports = app => {
          * @private
          */
         async _saveDgnDatas(datas) {
-            const orgDatas = await this.db.select(this.tableName, {
-                where: {
-                    id: this._.map(datas, 'id'),
-                }
-            });
+            const ids = this._.map(datas, 'id');
+            const orgDatas = await this.db.select(this.tableName, { where: { id: ids } });
             const updateDatas = [], newDatas = [];
             for(const d of datas) {
                 this._filterInvalidField(d);
@@ -95,24 +92,14 @@ module.exports = app => {
             }
             const transaction = await this.db.beginTransaction();
             try {
-                if (newDatas.length > 0) {
-                    await transaction.insert(this.tableName, newDatas);
-                }
-                if (updateDatas.length > 0) {
-                    for (const u of updateDatas) {
-                        await transaction.update(this.tableName, u);
-                    }
-                }
+                if (newDatas.length > 0) await transaction.insert(this.tableName, newDatas);
+                if (updateDatas.length > 0) await transaction.update(this.tableName, updateDatas);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();
                 throw err;
             }
-            await this.db.select(this.tableName, {
-                where: {
-                    id: this._.map(datas, 'id')
-                }
-            });
+            await this.db.select(this.tableName, {where: { id: ids } });
         }
 
         /**

+ 20 - 2
app/service/stage_stash.js

@@ -18,6 +18,8 @@ class loadStageExcelTree {
         this.insertPos = [];
         this.updateBills = [];
         this.updatePos = [];
+        this.insertDgn = [];
+        this.updateDgn = [];
     }
     init(source) {
         this.default = source.default;
@@ -32,6 +34,8 @@ class loadStageExcelTree {
 
         this.stageBills = source.stageBills;
         this.stagePos = source.stagePos;
+
+        this.stageBillsDgn = source.stageBillsDgn;
     }
     findNode(node, parent) {
         const _ = this.ctx.helper._;
@@ -46,7 +50,7 @@ class loadStageExcelTree {
                     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 ;
+                    && node.unit_price === x.unit_price && node.has_pos === x.has_pos;
             } else {
                 return node.code === _.trimEnd(x.code) && node.name === _.trimEnd(x.name);
             }
@@ -96,6 +100,16 @@ class loadStageExcelTree {
             }
         }
     }
+    loadDgn(node, cur) {
+        if (!node.deal_dgn_qty1 && !node.deal_dgn_qty2 && !node.c_dgn_qty1 && !node.c_dgn_qty2) return;
+
+        const dgn = this.stageBillsDgn.find(x => { return x.id === cur.id; });
+        if (dgn) {
+            this.updateDgn.push({ id: cur.id, deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2, c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2 });
+        } else {
+            this.insertDgn.push({ id: cur.id, tid: this.default.tid, deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2, c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2 });
+        }
+    }
     loadNode(node, parent) {
         node.is_leaf = !node.children || node.children.length === 0 ? 1 : 0;
         node.has_pos = node.pos && node.pos.length > 0;
@@ -103,6 +117,7 @@ class loadStageExcelTree {
         if (!cur) return;
 
         if (cur) {
+            if (!node.b_code) this.loadDgn(node, cur);
             if (node.is_leaf) {
                 this.loadLeaf(node, cur);
             } else {
@@ -316,9 +331,10 @@ module.exports = app => {
                 });
                 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.load(cacheTree, {ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
+                loadModal.load(cacheTree, {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 {
@@ -326,6 +342,8 @@ module.exports = app => {
                     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();