| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- const audit = require('../app/const/audit');
 
- const mysql = require('mysql');
 
- const config = process.argv[2];
 
- console.log(config);
 
- const mysqlOptions = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' }).mysql;
 
- console.log(mysqlOptions);
 
- const pool = mysql.createPool(mysqlOptions.client);
 
- const querySql = async function (sql, sqlParam) {
 
-     return new Promise(function (resolve, reject) {
 
-         pool.getConnection(function (err, conn) {
 
-             if (err) {
 
-                 reject(err);
 
-             } else {
 
-                 conn.query(sql, sqlParam, function (err, rows, fields) {
 
-                     //释放连接
 
-                     conn.release();
 
-                     //传递Promise回调对象
 
-                     resolve({"err": err, "rows": rows, "fields": fields});
 
-                 });
 
-             }
 
-         });
 
-     });
 
- };
 
- const doComplete = async function () {
 
-     try {
 
-         const tenders = await querySql('Select * From zh_tender where ledger_status = ?', [audit.ledger.status.checked]);
 
-         for (const t of tenders.rows) {
 
-             const stages = await querySql('Select * From zh_stage where tid = ?', [t.id]);
 
-             for (const s of stages.rows) {
 
-                 console.log('处理标段: ' + t.name + ' 期: ' + s.order);
 
-                 const auditors = await querySql('Select * From zh_stage_audit where sid = ? and times = ? order by `order`', [s.id, s.times ? s.times : 1]);
 
-                 const curAuditor = auditors.rows.find(x => { return x.status === audit.stage.status.checking});
 
-                 const order = curAuditor ? curAuditor.order : (auditors.rows.length > 0 ? auditors.rows.length : 0);
 
-                 const latestStagePay = await querySql('Select * From zh_stage_pay where sid = ? and stimes = ? and sorder = ?', [s.id, s.times ? s.times : 1, order]);
 
-                 const insertData = [];
 
-                 for (const lsp of latestStagePay.rows) {
 
-                     if (!lsp.attachment) continue;
 
-                     const attachment = JSON.parse(lsp.attachment);
 
-                     for (const a of attachment) {
 
-                         insertData.unshift([t.id, s.id, lsp.pid, a.uid, a.filename, a.fileext, a.filesize, a.filepath, a.in_time, a.username || '']);
 
-                     }
 
-                 }
 
-                 const result = await querySql('Insert Into zh_pay_attachment (tid, sid, pid, uid, filename, fileext, filesize, filepath, in_time, username ) Values ?', [insertData]);
 
-             }
 
-         }
 
-         await querySql("Update zh_pay_attachment att Left Join zh_project_account acc On att.uid = acc.id Set att.username = acc.name Where att.username = ''");
 
-         pool.end();
 
-     } catch(err) {
 
-         console.log(err);
 
-     }
 
- };
 
- doComplete();
 
 
  |