Browse Source

台账数据分表调整

MaiXinRong 1 năm trước cách đây
mục cha
commit
62b9979533

+ 1 - 1
app/service/change_pos.js

@@ -19,7 +19,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            // this.depart = 20;
+            // this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'change_pos';
         }
 

+ 1 - 1
app/service/ledger.js

@@ -53,7 +53,7 @@ module.exports = app => {
                 keyPre: 'ledger_bills_maxLid:',
                 uuid: true,
             }, 'pos');
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'ledger';
         }
 

+ 1 - 1
app/service/ledger_extra.js

@@ -19,7 +19,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'ledger_extra';
         }
 

+ 1 - 1
app/service/payment_safe_bills.js

@@ -45,7 +45,7 @@ module.exports = app => {
                 keyPre: 'safe_bills_maxLid:',
                 uuid: true,
             });
-            // this.depart = 10;
+            // this.depart = ctx.app.config.table_depart.light;
             this.tableName = 'payment_safe_bills';
             this.decimal = { tp: 2, up: 2, qty: 3 };
         }

+ 1 - 1
app/service/pos.js

@@ -19,7 +19,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'pos';
         }
 

+ 1 - 1
app/service/pos_extra.js

@@ -19,7 +19,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'pos_extra';
         }
 

+ 1 - 1
app/service/revise_bills.js

@@ -30,7 +30,7 @@ module.exports = app => {
                 keyPre: 'revise_bills_maxLid:',
                 uuid: true,
             }, 'revisePos');
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'revise_bills';
         }
 

+ 1 - 1
app/service/revise_pos.js

@@ -19,7 +19,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'revise_pos';
         }
 

+ 1 - 1
app/service/settle_bills.js

@@ -18,7 +18,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.light;
             this.tableName = 'settle_bills';
         }
     }

+ 1 - 1
app/service/settle_pos.js

@@ -18,7 +18,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.light;
             this.tableName = 'settle_pos';
         }
     }

+ 1 - 1
app/service/stage_bills.js

@@ -22,7 +22,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'stage_bills';
         }
 

+ 1 - 1
app/service/stage_bills_final.js

@@ -20,7 +20,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 10;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'stage_bills_final';
         }
 

+ 1 - 1
app/service/stage_pos.js

@@ -21,7 +21,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'stage_pos';
             this.qtyFields = ['contract_qty', 'qc_qty', 'qc_minus_qty', 'positive_qc_qty', 'negative_qc_qty']
         }

+ 1 - 1
app/service/stage_pos_final.js

@@ -21,7 +21,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.depart = 20;
+            this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'stage_pos_final';
         }
 

+ 4 - 0
config/config.default.js

@@ -260,5 +260,9 @@ module.exports = appInfo => {
     config.managementProxyPath = 'https://pm.smartcost.com.cn';
 
     config.url3f = '/3f';
+    config.table_depart = {
+        heavy: 1000,
+        light: 10,
+    };
     return config;
 };

+ 4 - 0
config/config.local.js

@@ -126,5 +126,9 @@ module.exports = appInfo => {
     config.managementProxyPath = 'http://192.168.1.76:2020';
 
     config.url3f = 'http://127.0.0.1:7005/3f';
+    config.table_depart = {
+        heavy: 100,
+        light: 10,
+    };
     return config;
 };

+ 4 - 0
config/config.qa.js

@@ -88,5 +88,9 @@ module.exports = appInfo => {
     config.managementProxyPath = 'http://192.168.1.76:2020';
 
     config.url3f = 'http://jlqa.smartcost.com.cn:7005/3f';
+    config.table_depart = {
+        heavy: 100,
+        light: 10,
+    };
     return config;
 };

+ 4 - 0
config/config.uat.js

@@ -97,5 +97,9 @@ module.exports = appInfo => {
     // 项目管理跳转路径
     config.managementPath = 'https://pmuat.smartcost.com.cn';
     config.managementProxyPath = 'https://pmuat.smartcost.com.cn';
+    config.table_depart = {
+        heavy: 100,
+        light: 10,
+    };
     return config;
 };

+ 70 - 0
db_script/depart_table.js

@@ -0,0 +1,70 @@
+const BaseUtil = require('./baseUtils');
+
+const ledgerTables = ['zh_ledger', 'zh_ledger_extra', 'zh_revise_bills', 'zh_stage_bills', 'zh_stage_bills_final', 'zh_settle_bills'];
+const ledgerDepartKey = ['tender_id', 'tid', 'tender_id', 'tid', 'tid', 'tid'];
+const posTables = ['zh_pos', 'zh_pos_extra', 'zh_revise_pos', 'zh_stage_pos', 'zh_stage_pos_final', 'zh_settle_pos'];
+const posDepartKey = ['tid', 'tid', 'tid', 'tid', 'tid', 'tid'];
+const orgLedgerDepart = 10, orgPosDepart = 20;
+const tableDepart = 1000;
+
+const sqlArr = [];
+const getDepartSql = function (table, key, orgDepart, newDepart) {
+    sqlArr.push(`-- ${table}`);
+    sqlArr.push(`-- ${table} RENAME`);
+    for (let i = 0; i < orgDepart; i++) {
+        sqlArr.push(`RENAME TABLE ${table}_${i} TO ${table}_bak_${i};`);
+    }
+    sqlArr.push(`-- ${table} RE_DEPART`);
+    for (let i = 0; i < newDepart; i++) {
+        const orgDepartIndex = i % orgDepart;
+        sqlArr.push(`Create Table ${table}_${i} SELECT * FROM ${table}_bak_${orgDepartIndex} WHERE ${key} % 100 = ${i};`);
+    }
+    sqlArr.push('');
+};
+const getArrDepartSql = function(tableArr, keyArr, orgDepart, newDepart) {
+    for (let i = 0, iLen = tableArr.length; i < iLen; i++) {
+        getDepartSql(tableArr[i], keyArr[i], orgDepart, newDepart);
+    }
+};
+getArrDepartSql(ledgerTables, ledgerDepartKey, orgLedgerDepart, tableDepart);
+getArrDepartSql(posTables, posDepartKey, orgPosDepart, tableDepart);
+
+BaseUtil.saveBufferFile(sqlArr.join('\n'), BaseUtil.getFileName('depart_table.sql'));
+
+// Select Sum(amount) FROM (
+//     Select Count(*) As amount From zh_settle_bills_bak_0
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_1
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_2
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_3
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_4
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_5
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_6
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_7
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_8
+//     UNION ALL
+//     Select Count(*) As amount From zh_settle_bills_bak_9
+// ) As temp;
+
+// 数据量预估
+// qa执行时间(分表100)
+// zh_ledger: 320s(876461条)
+// zh_ledger_extra: 80s(155730条)
+// zh_revise_bills: 230s(386041条)
+// zh_stage_bills: 90s(80435条)
+// zh_stage_bills_final: 90s(108374条)
+// zh_settle_bills: 40s(360条)
+// zh_pos: 480s(3122249条)
+// zh_pos_extra: 50s(77条)
+// zh_revise_pos: 350s(1173963条)
+// zh_stage_pos: 110s(380576条)
+// zh_stage_pos_final: 130s(658929条)
+// zh_settle_pos: 50s(266条)
+