浏览代码

升级数据部分脚本

MaiXinRong 3 年之前
父节点
当前提交
2e5e63b148
共有 2 个文件被更改,包括 74 次插入2 次删除
  1. 15 2
      db_script/ledger_his.js
  2. 59 0
      db_script/update_revise.js

+ 15 - 2
db_script/ledger_his.js

@@ -8,7 +8,19 @@
  * @version
  */
 
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
 const audit = require('../app/const/audit');
+const measureType = require('../app/const/message_type');
 
 const mysql = require('mysql');
 const oss = require('ali-oss');
@@ -105,7 +117,7 @@ const doCompleteTender = async function(t) {
                 if (r.status !== 1) withoutHisRevise.push(r);
             }
         }
-        if (!his_id) his_id = await saveLedgerHis(t);
+        if (!his_id || t.measure_type === measureType.gcl.value) his_id = await saveLedgerHis(t);
         await querySql('Update zh_tender Set his_id = ? Where id = ?', [his_id, t.id]);
         const stages = await querySql('Select * From zh_stage where tid = ? and status = ?', [t.id, audit.stage.status.checked]);
         for (const s of stages) {
@@ -166,5 +178,6 @@ doComplete();
 //     }
 //     pool.end();
 // };
-doCompeletTest();
+
+// doCompeletTest();
 

+ 59 - 0
db_script/update_revise.js

@@ -0,0 +1,59 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+const oss = require('ali-oss');
+const config = process.argv.splice(2)[0];
+if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
+const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
+
+const ossOption = {
+    bucket: options.oss.clients.his.bucket,
+    accessKeyId: options.oss.default.accessKeyId,
+    accessKeySecret: options.oss.default.accessKeySecret,
+    endpoint: options.oss.default.endpoint,
+    timeout: options.oss.default.timeout,
+};
+const ossClient = new oss(ossOption);
+
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
+const filepath = ['/etc/calc/files/revise', 'mnt/files/calc/revise'];
+// const filepath = ['/etc/calc/files/xx'];
+
+let iCount = 0;
+const updatePath = async function (filepath) {
+    console.log(`UpdatePath: ${filepath}`);
+    const files = fs.readdirSync(filepath);
+    for (const f of files) {
+        const stat = fs.statSync(path.join(filepath, f));
+        const ossPath = options.hisOssPath + 'revise/' + f;
+        if (stat.isFile()) await ossClient.put(ossPath, path.join(filepath, f));
+        console.log(`UpdateOss: ${path.join(filepath, f)} --> ${ossPath}`);
+        iCount++;
+    }
+    console.log('');
+};
+const updateAll = async function () {
+    for (const p of filepath) {
+        await updatePath(p);
+    }
+    console.log(`UpdateOss: ${iCount} files`);
+};
+
+updateAll();