Browse Source

导入Excel时,项目节的设计量金额也不导入

MaiXinRong 2 năm trước cách đây
mục cha
commit
ce39dfd51e
4 tập tin đã thay đổi với 88 bổ sung1 xóa
  1. 4 0
      app/extend/context.js
  2. 1 1
      app/service/ledger.js
  3. 3 0
      config/config.default.js
  4. 80 0
      db_script/stage_stash.js

+ 4 - 0
app/extend/context.js

@@ -80,6 +80,10 @@ module.exports = {
         return this.app.config.stashOssPath;
     },
 
+    print(str) {
+        this.getLogger('out').info(str);
+    },
+
     saveTempFile(filename, text) {
         const filepath = path.join(this.app.config.logger.dir, this.app.config.version, filename);
         this.helper.saveBufferFile(text, filepath);

+ 1 - 1
app/service/ledger.js

@@ -716,7 +716,7 @@ module.exports = app => {
                     // todo 最底层项目节其实应该导入,但是由于目前项目节不能输入金额,也不能计量,导入金额就会有矛盾,故暂时不导入
                     if (this.ctx.tender.data.measure_type === measureType.tz.value) {
                         data.sgfh_qty = node.quantity;
-                        data.sgfh_tp = node.total_price;
+                        data.sgfh_tp = node.b_code ? node.total_price : 0;
                         data.quantity = node.quantity;
                         data.total_price = node.b_code ? node.total_price : 0;
                     } else if (this.ctx.tender.data.measure_type === measureType.gcl.value) {

+ 3 - 0
config/config.default.js

@@ -170,6 +170,9 @@ module.exports = appInfo => {
         },
         warning: {
             file: path.join(appInfo.root, 'logs', appInfo.name, config.version, 'warning.log'),
+        },
+        out: {
+            file: path.join(appInfo.root, 'logs', appInfo.name, config.version, 'out.log'),
         }
     };
 

+ 80 - 0
db_script/stage_stash.js

@@ -0,0 +1,80 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+var logPath = path.join(__dirname, 'update_ledger_his.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 mysql = require('mysql');
+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 pool = mysql.createPool(options.mysql.client);
+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);
+
+const querySql = async function(sql, sqlParam) {
+    return new Promise(function(resolve, reject) {
+        pool.getConnection(function(err, conn) {
+            if (err) {
+                if (err) console.log(err);
+                reject(err);
+            } else {
+                conn.query(sql, sqlParam, function(err, rows, fields) {
+                    if (err) console.log(err);
+                    // 释放连接
+                    conn.release();
+                    // 传递Promise回调对象
+                    resolve(rows);
+                });
+            }
+        });
+    });
+};
+
+const loadDataFromOss = async function(url) {
+    const File = await ossClient.get('undefined' + url);
+    if (File.res.status !== 200) return '获取修订台账有误';
+    return File.content;
+};
+
+const doCompleteStashStash = async function(stash) {
+    const data = await loadDataFromOss(stash.filepath);
+    await ossClient.put(options.stashOssPath + stash.filepath, data);
+};
+
+const doComplete = async function() {
+    try {
+        const stash = await querySql('Select * From zh_stage_stash');
+        for (const s of stash) {
+            console.log(s);
+            await doCompleteStashStash(s);
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    pool.end();
+};
+doComplete();
+