Procházet zdrojové kódy

台账修订,单价调整,更新金额概况等缓存

MaiXinRong před 2 roky
rodič
revize
2c1fc0cd7b

+ 8 - 0
app/lib/ledger.js

@@ -1012,6 +1012,14 @@ class reviseTree extends billsTree {
             }
         });
     }
+    sum() {
+        const result = { total_price: 0 };
+        for (const d of this.datas) {
+            if (d.children && d.children.length > 0) continue;
+            result.total_price = this.ctx.helper.add(result.total_price, d.total_price);
+        }
+        return result;
+    }
 }
 
 module.exports = {

+ 7 - 1
app/service/ledger_history.js

@@ -109,6 +109,7 @@ module.exports = app => {
             const timestamp = (now).getTime();
 
             const price = await this.ctx.service.revisePrice.getAllDataByCondition({ where: { rid: revise.id } });
+            let sum = { total_price: 0 };
 
             const billsHis = `${this.ctx.session.sessionProject.id}/${revise.tid}/ledger/bills${timestamp}-r.json`;
             const bills = await this.ctx.service.reviseBills.getData(revise.tid);
@@ -116,12 +117,17 @@ module.exports = app => {
             const posHis = `${this.ctx.session.sessionProject.id}/${revise.tid}/ledger/pos${timestamp}-r.json`;
             const pos = await this.ctx.service.revisePos.getData(revise.tid);
             if (price.length === 0) {
+                for (const b of bills) {
+                    if (!b.is_leaf) continue;
+                    sum.total_price = this.ctx.helper.add(sum.total_price, b.total_price);
+                }
                 await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
                 await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
             } else {
                 const reviseTree = new Ledger.reviseTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 });
                 reviseTree.loadRevisePrice(price, this.ctx.tender.info.decimal);
                 reviseTree.loadDatas(bills);
+                sum = reviseTree.sum();
                 await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(reviseTree.getUpdateReviseData()), 'utf8'));
                 await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
             }
@@ -134,7 +140,7 @@ module.exports = app => {
                 bills_count: bills.length, pos_count: pos.length,
             });
 
-            return result.insertId;
+            return [result.insertId, sum];
         }
     }
 

+ 22 - 6
app/service/ledger_revise.js

@@ -24,6 +24,14 @@ module.exports = app => {
             this.tableName = 'ledger_revise';
         }
 
+        _analysisData(data) {
+            if (!data) return;
+            const datas = data instanceof Array ? data : [data];
+            for (const d of datas) {
+                if (d.sum) d.sum = JSON.parse(d.sum);
+            }
+        }
+
         /**
          * 获取标段下,修订(分页,且按时间倒序)
          * @param {Number}tid - 标段id
@@ -39,7 +47,9 @@ module.exports = app => {
                 '  LIMIT ?, ?';
             const Len = this.app.config.pageSize;
             const sqlParam = [tid, (this.ctx.page - 1) * Len, Len];
-            return await this.db.query(sql, sqlParam);
+            const result = await this.db.query(sql, sqlParam);
+            this._analysisData(result);
+            return result;
         }
 
         /**
@@ -55,7 +65,9 @@ module.exports = app => {
                 '  WHERE lc.tid = ?' +
                 '  ORDER BY lc.in_time DESC';
             const sqlParam = [tid];
-            return await this.db.query(sql, sqlParam);
+            const result = await this.db.query(sql, sqlParam);
+            this._analysisData(result);
+            return result;
         }
 
         async getLastestRevise(tid, valid = true) {
@@ -67,7 +79,9 @@ module.exports = app => {
                 '  ORDER BY lc.in_time DESC' +
                 '  LIMIT 0, 1';
             const sqlParam = [tid];
-            return await this.db.queryOne(sql, sqlParam);
+            const result = await this.db.queryOne(sql, sqlParam);
+            this._analysisData(result);
+            return result;
         }
 
         async getRevise(tid, rid) {
@@ -79,7 +93,9 @@ module.exports = app => {
                 '  ORDER BY lc.in_time DESC' +
                 '  LIMIT 0, 1';
             const sqlParam = [tid, rid];
-            return await this.db.queryOne(sql, sqlParam);
+            const result = await this.db.queryOne(sql, sqlParam);
+            this._analysisData(result);
+            return result;
         }
 
         /**
@@ -191,12 +207,12 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async cancelRevise(revise) {
-            const his_id = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
+            const [his_id, sum] = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
             const transaction = await this.db.beginTransaction();
             try {
                 const result = await transaction.update(this.tableName, {
                     id: revise.id, valid: false, end_time: new Date(),
-                    his_id,
+                    his_id, sum: JSON.stringify(sum),
                 });
                 await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: his_id, valid: 0 });
                 if (revise.his_id > 0) await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: revise.his_id, valid: 0 });

+ 3 - 3
app/service/revise_audit.js

@@ -232,7 +232,7 @@ module.exports = app => {
             const time = new Date();
 
             // 拷贝备份台账数据
-            const his_id = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
+            const [his_id, sum] = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -246,7 +246,7 @@ module.exports = app => {
                 const reviseData = {
                     id: revise.id,
                     status: auditConst.status.checking,
-                    his_id,
+                    his_id, sum: JSON.stringify(sum),
                 };
                 if (revise.times === 1) {
                     reviseData.begin_time = time;
@@ -453,7 +453,7 @@ module.exports = app => {
                         // 重算台账、计量、工程变更
                         const reviseCalc = new RevisePrice(this.ctx);
                         await reviseCalc.calcRevise(revise, transaction);
-                        const sum = await this.ctx.service.reviseBills.addUp({
+                        const sum = revise.sum || await this.ctx.service.reviseBills.addUp({
                             tender_id: revise.tid, /* , is_leaf: true*/
                         });
                         await transaction.update(this.ctx.service.tender.tableName, {

+ 3 - 0
sql/update.sql

@@ -241,4 +241,7 @@ ADD COLUMN `contract_pc_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补
 ADD COLUMN `qc_pc_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(变更)' AFTER `contract_pc_tp`,
 ADD COLUMN `pc_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差' AFTER `qc_pc_tp`;
 
+ALTER TABLE `zh_ledger_revise`
+ADD COLUMN `sum`   varchar(255) NOT NULL DEFAULT '' COMMENT 'sum统计数据' AFTER `pre_his_id`;
+
 ALTER TABLE `zh_project` ADD `fun_set` VARCHAR(1000) NULL DEFAULT NULL COMMENT '项目设置页内容json' AFTER `map_json`;