Explorar el Código

1. 脚本调整
2. 动态决算,补差bug

MaiXinRong hace 2 años
padre
commit
4d2eae2785
Se han modificado 3 ficheros con 39 adiciones y 35 borrados
  1. 1 1
      app/lib/budget_final.js
  2. 1 1
      db_script/baseUtils.js
  3. 37 33
      db_script/change.js

+ 1 - 1
app/lib/budget_final.js

@@ -162,7 +162,7 @@ class BudgetFinal {
                 ? await this.ctx.service.stageBills.getAuditorStageData2(id, stage.id, stage.curTimes, stage.curOrder)
                 : await this.ctx.service.stageBills.getLastestStageData2(id, stage.id);
             const preBills = stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData({id}, stage.order - 1) : [];
-            const bpcData = await ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: ctx.stage.id } });
+            const bpcData = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stage.id } });
             helper.assignRelaData(bills, [
                 { data: curBills, fields: ['contract_tp', 'qc_tp'], prefix: '', relaId: 'lid' },
                 { data: preBills, fields: ['contract_tp', 'qc_tp'], prefix: 'pre_', relaId: 'lid' },

+ 1 - 1
db_script/baseUtils.js

@@ -12,7 +12,7 @@ console.log = function() {
 };
 
 const mysql = require('mysql');
-const config = process.argv.splice(2)[0];
+const config = process.argv[2];
 if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
 const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
 const pool = mysql.createPool(options.mysql.client);

+ 37 - 33
db_script/change.js

@@ -28,7 +28,7 @@ const checkStage = async function(stage, decimal, preStage) {
     if (history) {
         for (const h of history) {
             const sbFilter = stageBills.filter(x => {
-                return x.times < h.times || (x.times = h.times && x.order <= h.order);
+                return x.times < h.times || (x.times === h.times && x.order <= h.order);
             });
             const sbLatest = BaseUtil.filterLastestData(sbFilter, ['lid']);
             history.positive_qc_tp = 0;
@@ -195,14 +195,38 @@ const doComplete = async function() {
             const info = await querySql('Select * From zh_tender_info where tid = ?', [t.id]);
             const decimal = info[0].decimal ? JSON.parse(info[0].decimal) : defaultInfo.parseInfo.decimal;
 
-            // const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
-            // for (const c of changes) {
-            //     await checkChange(c, decimal);
-            // }
+            const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
+            for (const c of changes) {
+                await checkChange(c, decimal);
+            }
+            const stage = await querySql('Select * From zh_stage where tid = ? order by `order` asc', [t.id]);
+            for (const [i, s] of stage.entries()) {
+                await checkStagePos(s, decimal, i > 0 ? stage[i-1] : null);
+                await checkStageBills(s, decimal, i > 0 ? stage[i-1] : null);
+                await checkStage(s, decimal, i > 0 ? stage[i-1] : null);
+            }
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    BaseUtil.closePool();
+};
+const doCompleteTest = async function(tid) {
+    try {
+        const tender = await querySql('Select * From zh_tender where id = ?', [tid]);
+        for (const t of tender) {
+            console.log(`Update Tender ${t.id}:`);
+            const info = await querySql('Select * From zh_tender_info where tid = ?', [t.id]);
+            const decimal = info[0].decimal ? JSON.parse(info[0].decimal) : defaultInfo.parseInfo.decimal;
+
+            const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
+            for (const c of changes) {
+                await checkChange(c, decimal);
+            }
             const stage = await querySql('Select * From zh_stage where tid = ? order by `order` asc', [t.id]);
             for (const [i, s] of stage.entries()) {
-                // await checkStagePos(s, decimal, i > 0 ? stage[i-1] : null);
-                // await checkStageBills(s, decimal, i > 0 ? stage[i-1] : null);
+                await checkStagePos(s, decimal, i > 0 ? stage[i-1] : null);
+                await checkStageBills(s, decimal, i > 0 ? stage[i-1] : null);
                 await checkStage(s, decimal, i > 0 ? stage[i-1] : null);
             }
         }
@@ -211,29 +235,9 @@ const doComplete = async function() {
     }
     BaseUtil.closePool();
 };
-doComplete();
-// const doCompleteTest = async function() {
-//     try {
-//         const tender = await querySql('Select * From zh_tender where id = 860');
-//         for (const t of tender) {
-//             console.log(`Update Tender ${t.id}:`);
-//             const info = await querySql('Select * From zh_tender_info where tid = ?', [t.id]);
-//             const decimal = info[0].decimal ? JSON.parse(info[0].decimal) : defaultInfo.parseInfo.decimal;
-//
-//             const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
-//             for (const c of changes) {
-//                 await checkChange(c, decimal);
-//             }
-//             const stage = await querySql('Select * From zh_stage where tid = ? order by `order` asc', [t.id]);
-//             for (const [i, s] of stage.entries()) {
-//                 await checkStagePos(s, decimal, i > 1 ? stage[i-1] : null);
-//                 await checkStageBills(s, decimal, i > 1 ? stage[i-1] : null);
-//                 await checkStage(s, decimal, i > 1 ? stage[i-1] : null);
-//             }
-//         }
-//     } catch (err) {
-//         console.log(err);
-//     }
-//     BaseUtil.closePool();
-// };
-// doCompleteTest();
+const tenderId = process.argv[3];
+if (tenderId) {
+    doCompleteTest(tenderId);
+} else {
+    doComplete()
+}