瀏覽代碼

Merge remote-tracking branch 'remotes/origin/dev' into uat

MaiXinRong 4 年之前
父節點
當前提交
a64d9c7621

+ 19 - 18
app/controller/advance_controller.js

@@ -2,7 +2,6 @@
 const accountGroup = require('../const/account_group').group;
 const auditConst = require('../const/audit').advance;
 const shenpiConst = require('../const/shenpi');
-const sendToWormhole = require('stream-wormhole');
 const path = require('path');
 const fs = require('fs');
 module.exports = app => {
@@ -366,30 +365,33 @@ module.exports = app => {
             let stream;
             try {
                 // this._checkAdvanceFileCanModify(ctx);
-                const parts = this.ctx.multipart({
-                    autoFields: true,
-                });
+
                 const files = [];
-                const create_time = Date.parse(new Date()) / 1000;
                 let idx = 0;
+                const create_time = Date.parse(new Date()) / 1000;
                 const extra_upload = ctx.advance.status === auditConst.status.checked;
-                while ((stream = await parts()) !== undefined) {
-                    if (!stream.filename) {
-                        // 如果没有传入直接返回
-                        return;
+                for (const file of ctx.request.files) {
+                    // 如果没有传入直接返回
+                    if (!file.filename) return;
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const filepath = `public/upload/${this.ctx.tender.id.toString()}/yfk/fujian_${create_time + idx.toString() + fileInfo.ext}`;
+                        await this.ctx.helper.recursiveMkdirSync(path.dirname(path.join(this.app.baseDir, 'app', filepath)));
+                        await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, 'app', filepath));
+                        files.push({
+                            filepath, name: file.filename, ext: fileInfo.ext
+                        });
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
                     }
-                    const fileInfo = path.parse(stream.filename);
-                    const filepath = `public/upload/${this.ctx.tender.id.toString()}/yfk/fujian_${create_time + idx.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
-                    files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
                     ++idx;
-                    stream && (await sendToWormhole(stream));
                 }
+
                 const in_time = new Date();
                 const payload = files.map(file => {
                     let idx;
-                    if (Array.isArray(parts.field.name)) {
-                        idx = parts.field.name.findIndex(name => name === file.name);
+                    if (Array.isArray(ctx.request.body.name)) {
+                        idx = ctx.request.body.name.findIndex(name => name === file.name);
                     } else {
                         idx = 'isString';
                     }
@@ -399,7 +401,7 @@ module.exports = app => {
                         tid: ctx.tender.id,
                         create_time: in_time,
                         filepath: file.filepath,
-                        filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
+                        filesize: ctx.helper.bytesToSize(idx === 'isString' ? ctx.request.body.size : ctx.request.body.size[idx]),
                         filename: file.name,
                         fileext: file.ext,
                         extra_upload,
@@ -412,7 +414,6 @@ module.exports = app => {
                 const data = await ctx.service.advanceFile.getAdvanceFiles({ vid: ctx.advance.id });
                 ctx.body = { err: 0, msg: '', data };
             } catch (err) {
-                stream && (await sendToWormhole(stream));
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
             }

+ 34 - 53
app/controller/change_controller.js

@@ -9,7 +9,6 @@
  */
 
 const moment = require('moment');
-const sendToWormhole = require('stream-wormhole');
 const fs = require('fs');
 const path = require('path');
 const audit = require('../const/audit');
@@ -989,66 +988,48 @@ module.exports = app => {
          * @return {void}
          */
         async uploadFile(ctx) {
-            const responseData = {
-                err: 0,
-                msg: '',
-                data: [],
-            };
-            let stream;
+            const responseData = { err: 0, msg: '', data: [], };
             try {
-                const parts = ctx.multipart({ autoFields: true });
-                const files = [];
-                let index = 0;
                 const change = await ctx.service.change.getDataByCondition({ cid: ctx.params.cid });
                 const extra_upload = change.status === audit.flow.status.checked;
-                while ((stream = await parts()) !== undefined) {
-                    // 判断用户是否选择上传文件
-                    if (!stream.filename) {
-                        throw '请选择上传的文件!';
-                    }
-                    // const create_time = Date.parse(new Date()) / 1000;
-                    // const fileInfo = path.parse(stream.filename);
-                    // const dirName = 'app/public/upload/changes/' + moment().format('YYYYMMDD');
-                    // const fileName = 'changes' + create_time + '_' + index + fileInfo.ext;
-                    // // 判断文件夹是否存在,不存在则直接创建文件夹
-                    // if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                    //     await fs.mkdirSync(path.join(this.app.baseDir, dirName));
-                    // }
-                    // // 保存文件
-                    // await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
-                    const fileInfo = path.parse(stream.filename);
-                    const create_time = Date.parse(new Date()) / 1000;
-                    const filepath = `app/public/upload/change/fujian_${create_time + index.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, filepath));
-                    await sendToWormhole(stream);
-                    // 保存数据到att表
-                    const fileData = {
-                        in_time: create_time,
-                        filename: fileInfo.name,
-                        fileext: fileInfo.ext,
-                        filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
-                        filepath,
-                        extra_upload,
-                    };
-                    const result = await ctx.service.changeAtt.save(parts.field, fileData, ctx.session.sessionUser.accountId);
-                    if (!result) {
-                        throw '导入数据库保存失败';
+                const files = [];
+
+                let index = 0;
+                for (const file of ctx.request.files) {
+                    if (!file.filename) throw '请选择上传的文件!';
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const create_time = Date.parse(new Date()) / 1000;
+                        const filepath = `app/public/upload/change/fujian_${create_time + index.toString() + fileInfo.ext}`;
+
+                        await this.ctx.helper.recursiveMkdirSync(path.dirname(path.resolve(this.app.baseDir, filepath)));
+                        await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, filepath));
+
+                        const fileData = {
+                            in_time: create_time,
+                            filename: fileInfo.name,
+                            fileext: fileInfo.ext,
+                            filesize: Array.isArray(ctx.request.body.size) ? ctx.request.body.size[index] : ctx.request.body.size,
+                            uid: ctx.session.sessionUser.accountId,
+                            filepath,
+                            extra_upload
+                        };
+                        const result = await ctx.service.changeAtt.save(ctx.request.body, fileData, ctx.session.sessionUser.accountId);
+                        if (!result) {
+                            throw '导入数据库保存失败';
+                        }
+                        fileData.uid = ctx.session.sessionUser.accountId;
+                        fileData.id = result.insertId;
+                        delete fileData.filepath;
+                        files.push(fileData);
+                        ++index;
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
                     }
-                    // fileData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
-                    // fileData.filesize = await ctx.helper.bytesToSize(fileData.filesize);
-                    fileData.uid = ctx.session.sessionUser.accountId;
-                    fileData.id = result.insertId;
-                    delete fileData.filepath;
-                    files.push(fileData);
-                    ++index;
                 }
                 responseData.data = files;
             } catch (err) {
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.setMessage(err.toString(), this.messageType.ERROR);
             }
             ctx.body = responseData;

+ 8 - 9
app/controller/deal_bills_controller.js

@@ -12,7 +12,6 @@ const fs = require('fs');
 const path = require('path');
 const excel = require('node-xlsx');
 const xlsx = require('js-xlsx');
-const sendToWormhole = require('stream-wormhole');
 const loadExcelType = {
     display: 1,
     actual: 2,
@@ -73,15 +72,19 @@ module.exports = app => {
          * @return {Promise<void>}
          */
         async loadExcel(ctx) {
-            let stream;
             try {
                 await this.checkPermisision(ctx);
-                stream = await ctx.getFileStream();
+
+                const file = ctx.request.files[0];
                 const create_time = Date.parse(new Date()) / 1000;
-                const fileInfo = path.parse(stream.filename);
+                const fileInfo = path.parse(file.filename);
                 const fileName = this.app.config.filePath + '/cache/deal_bills/uploads/' + 'deal_bills' + create_time + fileInfo.ext;
                 // 保存文件
-                await ctx.helper.saveStreamFile(stream, fileName);
+                try {
+                    await ctx.helper.copyFileSync(file.filepath, fileName);
+                } finally {
+                    await fs.unlinkSync(file.filepath);
+                }
                 if (loadType === loadExcelType.display) {
                     const wb = xlsx.readFile(fileName);
                     const name = wb.SheetNames[0];
@@ -112,10 +115,6 @@ module.exports = app => {
                 ctx.body = {err: 0, msg: '', data: dealBills};
             } catch (err) {
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.ajaxErrorBody(err, '导入数据失败');
             }
         }

+ 0 - 45
app/controller/ledger_controller.js

@@ -553,51 +553,6 @@ module.exports = app => {
                 ctx.body = { err: 1, msg: err.toString(), data: null };
             }
         }
-        // async uploadExcel(ctx) {
-        //     let stream;
-        //     try {
-        //         const responseData = { err: 0, msg: '', data: {}, };
-
-        //         // 保存文件
-        //         stream = await ctx.getFileStream();
-        //         const create_time = Date.parse(new Date());
-        //         const fileInfo = path.parse(stream.filename);
-        //         const fileName = this.app.config.filePath + '/cache/ledger/uploads/' + create_time + fileInfo.ext;
-        //         await ctx.helper.saveStreamFile(stream, fileName);
-
-        //         // 读取excel
-        //         console.log(ctx.query);
-        //         const name = ctx.query.sheetName;
-        //         if (!name) throw '未选择需要导入的工作簿';
-        //         const wb = xlsx.readFile(fileName);
-        //         const sheetData = {
-        //             rows: xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
-        //             merge: wb.Sheets[name]["!merges"],
-        //         };
-        //         if (!sheetData.rows) throw '读取工作簿数据错误';
-
-        //         const ueType = ctx.query.ueType;
-        //         switch (ueType) {
-        //             case 'tz':
-        //                 const templateId = await this.ctx.service.valuation.getValuationTemplate(
-        //                     this.ctx.tender.data.valuation, this.ctx.tender.data.measure_type);
-        //                 responseData.data = await ctx.service.ledger.importExcel(templateId, sheetData);
-        //                 break;
-        //             case 'gcl2xmj':
-        //                 responseData.data = await ctx.service.ledger.importGclExcel(ctx.tender.id, sheetData);
-        //                 break;
-        //             default:
-        //                 throw '数据错误';
-        //         }
-        //         ctx.body = responseData;
-        //     } catch (err) {
-        //         console.log(err);
-        //         this.log(err);
-        //         // 失败需要消耗掉stream 以防卡死
-        //         if (stream) await sendToWormhole(stream);
-        //         ctx.body = {err: 1, msg: err.toString(), data: null};
-        //     }
-        // }
 
         /**
          * 填设计量(Ajax)

+ 19 - 19
app/controller/material_controller.js

@@ -17,7 +17,6 @@ const accountGroup = require('../const/account_group').group;
 const materialConst = require('../const/material');
 const shenpiConst = require('../const/shenpi');
 const MaterialCalculator = require('../lib/material_calc');
-const sendToWormhole = require('stream-wormhole');
 const fs = require('fs');
 const path = require('path');
 const _ = require('lodash');
@@ -868,33 +867,35 @@ module.exports = app => {
          * @param {*} ctx 上下文
          */
         async upload(ctx) {
-            let stream;
             try {
                 await this._checkMaterialFileCanModify(ctx);
-                const parts = this.ctx.multipart({
-                    autoFields: true,
-                });
+
                 const files = [];
-                const create_time = Date.parse(new Date()) / 1000;
                 let idx = 0;
+                const create_time = Date.parse(new Date()) / 1000;
                 const extra_upload = ctx.material.status === auditConst.status.checked;
-                while ((stream = await parts()) !== undefined) {
-                    if (!stream.filename) {
-                        // 如果没有传入直接返回
-                        return;
+                for (const file of ctx.request.files) {
+                    // 如果没有传入直接返回
+                    if (!file.filename) return;
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx.toString() + fileInfo.ext}`;
+                        await this.ctx.helper.recursiveMkdirSync(path.dirname(path.join(this.app.baseDir, 'app', filepath)));
+                        await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, 'app', filepath));
+                        files.push({
+                            filepath, name: file.filename, ext: fileInfo.ext
+                        });
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
                     }
-                    const fileInfo = path.parse(stream.filename);
-                    // const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
-                    const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
-                    files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
                     ++idx;
                 }
+
                 const upload_time = this.ctx.helper.dateTran(new Date());
                 const payload = files.map(file => {
                     let idx;
-                    if (Array.isArray(parts.field.name)) {
-                        idx = parts.field.name.findIndex(name => name === file.name);
+                    if (Array.isArray(ctx.request.body.name)) {
+                        idx = ctx.request.body.name.findIndex(name => name === file.name);
                     } else {
                         idx = 'isString';
                     }
@@ -905,7 +906,7 @@ module.exports = app => {
                         s_order: ctx.params.order,
                         upload_time,
                         filepath: file.filepath,
-                        file_size: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
+                        file_size: ctx.helper.bytesToSize(idx === 'isString' ? ctx.request.body.size : ctx.request.body.size[idx]),
                         file_name: file.name,
                         fileext: file.ext,
                         extra_upload,
@@ -918,7 +919,6 @@ module.exports = app => {
                 const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
                 ctx.body = { err: 0, msg: '', data };
             } catch (err) {
-                stream && (await sendToWormhole(stream));
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
             }

+ 8 - 5
app/controller/profile_controller.js

@@ -13,8 +13,8 @@ const profileMenu = require('../../config/menu').profileMenu;
 const smsTypeConst = require('../const/sms_type');
 const qr = require('qr-image');
 const path = require('path');
-const sendToWormhole = require('stream-wormhole');
 const loginWay = require('../const/setting').loginWay;
+const fs = require('fs');
 
 module.exports = app => {
 
@@ -322,13 +322,16 @@ module.exports = app => {
                 err: 0, msg: '', data: null,
             };
             try {
-                const stream = await ctx.getFileStream();
                 const create_time = Date.parse(new Date()) / 1000;
-                const fileInfo = path.parse(stream.filename);
+                const file = ctx.request.files[0];
+                const fileInfo = path.parse(file.filename);
                 const dirName = 'public/upload/sign';
                 const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + fileInfo.ext;
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', dirName, fileName));
-                await sendToWormhole(stream);
+                try {
+                    await ctx.helper.copyFileSync(file.filepath, path.join(this.app.baseDir, 'app', dirName, fileName));
+                } finally {
+                    await fs.unlinkSync(file.filepath);
+                }
                 const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: ctx.session.sessionUser.accountId });
                 if (result) {
                     responseData.data = { sign_path: fileName };

+ 6 - 4
app/controller/sign_controller.js

@@ -9,7 +9,6 @@
  */
 const moment = require('moment');
 const path = require('path');
-const sendToWormhole = require('stream-wormhole');
 const fs = require('fs');
 
 module.exports = app => {
@@ -49,12 +48,15 @@ module.exports = app => {
          */
         async save(ctx) {
             try {
-                const stream = await ctx.getFileStream({ requireFile: false });
+                const file = ctx.request.files[0];
                 const create_time = Date.parse(new Date()) / 1000;
                 const dirName = 'app/public/upload/sign/';
                 const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + '.png';
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
-                await sendToWormhole(stream);
+                try {
+                    await ctx.helper.copyFileSync(file.filepath, path.join(this.app.baseDir, dirName, fileName));
+                } finally {
+                    await fs.unlinkSync(file.filepath);
+                }
 
                 const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: stream.fields.id });
                 if (result) {

+ 78 - 115
app/controller/stage_controller.js

@@ -21,7 +21,6 @@ const measureType = tenderConst.measureType;
 const path = require('path');
 const PayCalculator = require('../lib/pay_calc');
 const accountGroup = require('../const/account_group').group;
-const sendToWormhole = require('stream-wormhole');
 const billsPosConvert = require('../lib/bills_pos_convert');
 const fs = require('fs');
 const stdConst = require('../const/standard');
@@ -669,12 +668,16 @@ module.exports = app => {
             try {
                 this._checkStageCanModify(ctx);
 
-                const stream = await ctx.getFileStream();
-                const create_time = Date.parse(new Date()) / 1000;
-                const fileInfo = path.parse(stream.filename);
-                const fileName = path.join('public/upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + fileInfo.ext);
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', fileName));
-                ctx.body = { err: 0, msg: '', data: fileName };
+                const file = ctx.request.files[0];
+                try {
+                    const create_time = Date.parse(new Date()) / 1000;
+                    const fileInfo = path.parse(file.filename);
+                    const fileName = path.join('public/upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + fileInfo.ext);
+                    await ctx.helper.copyFileSync(file.filepath, path.join(this.app.baseDir, 'app', fileName));
+                    ctx.body = { err: 0, msg: '', data: fileName };
+                } finally {
+                    await fs.unlinkSync(file.filepath);
+                }
             } catch (err) {
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
@@ -1316,68 +1319,46 @@ module.exports = app => {
                 msg: '',
                 data: [],
             };
-            let stream;
             try {
                 // this._checkStageCanModifyRe(ctx);
 
-                const parts = ctx.multipart({ autoFields: true });
-                const files = [];
                 let index = 0;
+                const files = [];
                 const extra_upload = ctx.stage.status === auditConst.status.checked;
-                while ((stream = await parts()) !== undefined) {
-                    // 判断用户是否选择上传文件
-                    if (!stream.filename) {
-                        throw '请选择上传的文件!';
-                    }
-                    // const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
-                    // 判断文件夹是否存在,不存在则直接创建文件夹
-                    // if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                    //     await fs.mkdirSync(path.join(this.app.baseDir, dirName));
-                    // }
-                    const fileInfo = path.parse(stream.filename);
-                    const create_time = Date.parse(new Date()) / 1000;
-                    const filepath = `app/public/upload/${this.ctx.tender.id}/stage/fujian_${create_time + index.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, filepath));
-                    // console.log(await fs.existsSync(path.resolve(this.app.baseDir, 'app', filepath)));
-                    // const fileInfo = path.parse(stream.filename);
-                    // const fileName = 'stage' + create_time + '_' + index + fileInfo.ext;
-                    // 保存文件
-                    // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, dirName, fileName));
-
-                    if (stream) {
-                        await sendToWormhole(stream);
-                    }
-
-                    // 保存数据到att表
-                    const fileData = {
-                        tid: ctx.params.id,
-                        sid: ctx.params.order,
-                        in_time: create_time,
-                        filename: fileInfo.name,
-                        fileext: fileInfo.ext,
-                        filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
-                        filepath,
-                        extra_upload,
-                    };
-                    // if (ctx.reUploadPermission) {
-                    //     fileData.re_upload = 1;
-                    // }
-                    const result = await ctx.service.stageAtt.save(parts.field, fileData, ctx.session.sessionUser.accountId);
-                    if (!result) {
-                        throw '导入数据库保存失败';
+                for (const file of ctx.request.files) {
+                    if (!file.filename) throw '请选择上传的文件!';
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const create_time = Date.parse(new Date()) / 1000;
+                        const filepath = `app/public/upload/${this.ctx.tender.id}/stage/fujian_${create_time + index.toString() + fileInfo.ext}`;
+                        await this.ctx.helper.recursiveMkdirSync(path.dirname(path.join(this.app.baseDir, filepath)));
+                        await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, filepath));
+
+                        const fileData = {
+                            tid: ctx.params.id,
+                            sid: ctx.params.order,
+                            in_time: create_time,
+                            filename: fileInfo.name,
+                            fileext: fileInfo.ext,
+                            filesize: Array.isArray(ctx.request.body.size) ? ctx.request.body.size[index] : ctx.request.body.size,
+                            filepath,
+                            extra_upload,
+                        };
+                        const result = await ctx.service.stageAtt.save(ctx.request.body, fileData, ctx.session.sessionUser.accountId);
+                        if (!result) {
+                            throw '导入数据库保存失败';
+                        }
+                        const attData = await ctx.service.stageAtt.getDataByFid(result.insertId);
+                        attData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
+                        files.length !== 0 ? files.unshift(attData) : files.push(attData);
+                        ++index;
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
                     }
-                    const attData = await ctx.service.stageAtt.getDataByFid(result.insertId);
-                    attData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
-                    files.length !== 0 ? files.unshift(attData) : files.push(attData);
-                    ++index;
                 }
                 responseData.data = files;
             } catch (err) {
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.setMessage(err.toString(), this.messageType.ERROR);
                 responseData.err = 1;
                 responseData.msg = err.toString();
@@ -1511,42 +1492,34 @@ module.exports = app => {
                 msg: '',
                 data: [],
             };
-            let stream;
             try {
-                this._checkStageCanModifyRe(ctx);
-                stream = await ctx.getFileStream({ requireFile: false });
+                //this._checkStageCanModifyRe(ctx);
+
+                const file = ctx.request.files[0];
                 let fileData = {};
-                if (stream.filename !== undefined) {
+                if (file && file.filename !== undefined) {
                     const create_time = Date.parse(new Date()) / 1000;
-                    const fileInfo = path.parse(stream.filename);
+                    const fileInfo = path.parse(file.filename);
                     const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
                     const fileName = 'stage' + create_time + fileInfo.ext;
 
-                    // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
-                    }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                    await ctx.helper.copyFileSync(file.filepath, path.join(this.app.baseDir, dirName, fileName));
                     // 保存数据到att表
                     fileData = {
-                        filesize: stream.fields.size,
+                        filesize: ctx.request.body.size,
                         filepath: path.join(dirName, fileName),
                     };
                 }
-                const result = await ctx.service.stageAtt.updateByID(stream.fields, fileData);
+                const result = await ctx.service.stageAtt.updateByID(ctx.request.body, fileData);
                 if (!result) {
                     throw '导入数据库保存失败';
                 }
-                const attData = await ctx.service.stageAtt.getDataByFid(stream.fields.id);
+                const attData = await ctx.service.stageAtt.getDataByFid(ctx.request.body.id);
                 attData.in_time = moment(attData.in_time * 1000).format('YYYY-MM-DD');
                 responseData.data = attData;
             } catch (err) {
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.setMessage(err.toString(), this.messageType.ERROR);
                 responseData.err = 1;
                 responseData.msg = err.toString();
@@ -1605,55 +1578,45 @@ module.exports = app => {
                 msg: '',
                 data: [],
             };
-            let stream;
             try {
                 this._checkStageCanModify(ctx);
 
-                const parts = ctx.multipart({ autoFields: true });
-                const files = [];
                 let index = 0;
+                const files = [];
                 const create_time = Date.parse(new Date()) / 1000;
-                while ((stream = await parts()) !== undefined) {
-                    // 判断用户是否选择上传文件
-                    if (!stream.filename) {
-                        throw '请选择上传的文件!';
-                    }
-                    const fileInfo = path.parse(stream.filename);
-                    const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
-                    const fileName = 'pay' + create_time + '_' + index + fileInfo.ext;
-
-                    // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
-                    }
-                    // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
-                    await sendToWormhole(stream);
-                    // 插入到stage_pay对应的附件列表中
-                    const attData = {
-                        filename: fileInfo.name,
-                        fileext: fileInfo.ext,
-                        filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
-                        filepath: path.join(dirName, fileName),
-                        uid: ctx.session.sessionUser.accountId,
-                        in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
-                    };
-                    const result = await ctx.service.stagePay.saveAtt(parts.field.pay_id, attData);
-                    if (!result) {
-                        throw '导入数据库保存失败';
+                for (const file of ctx.request.files) {
+                    if (!file.filename) throw '请选择上传的文件!';
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
+                        const fileName = 'pay' + create_time + '_' + index + fileInfo.ext;
+
+                        await this.ctx.helper.recursiveMkdirSync(path.join(this.app.baseDir, dirName));
+                        await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, dirName, fileName));
+
+                        const attData = {
+                            filename: fileInfo.name,
+                            fileext: fileInfo.ext,
+                            filesize: Array.isArray(ctx.request.body.size) ? ctx.request.body.size[index] : ctx.request.body.size,
+                            filepath: path.join(dirName, fileName),
+                            uid: ctx.session.sessionUser.accountId,
+                            in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
+                        };
+                        const result = await ctx.service.stagePay.saveAtt(ctx.request.body.pay_id, attData);
+                        if (!result) {
+                            throw '导入数据库保存失败';
+                        }
+                        delete attData.filepath;
+                        attData.username = ctx.session.sessionUser.name;
+                        files.length !== 0 ? files.unshift(attData) : files.push(attData);
+                        ++index;
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
                     }
-                    delete attData.filepath;
-                    attData.username = ctx.session.sessionUser.name;
-                    files.length !== 0 ? files.unshift(attData) : files.push(attData);
-                    ++index;
                 }
                 responseData.data = files;
             } catch (err) {
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.setMessage(err.toString(), this.messageType.ERROR);
                 responseData.err = 1;
                 responseData.msg = err.toString();

+ 22 - 31
app/controller/stage_extra_controller.js

@@ -8,7 +8,6 @@
  * @version
  */
 const auditConst = require('../const/audit').stage;
-const sendToWormhole = require('stream-wormhole');
 const path = require('path');
 const moment = require('moment');
 const fs = require('fs');
@@ -198,37 +197,33 @@ module.exports = app => {
         }
 
         async uploadFile(ctx) {
-            let stream;
             try {
-                const parts = ctx.multipart({ autoFields: true });
-                let index = 0;
+                const bonus = await ctx.service.stageBonus.getStageDataById(ctx.request.body.bonus_id);
+                if (!bonus || bonus.sid !== ctx.stage.id) throw '该奖罚金,当前不允许上传附件';
                 const create_time = Date.parse(new Date()) / 1000;
-                let bonus;
-                while ((stream = await parts()) !== undefined) {
-                    if (!stream.filename) {
-                        throw '未发现上传文件!';
-                    }
-                    if (!bonus) bonus = await ctx.service.stageBonus.getStageDataById(parts.field.bonus_id);
-                    if (!bonus || bonus.sid !== ctx.stage.id) throw '该奖罚金,当前不允许上传附件';
 
-                    const fileInfo = path.parse(stream.filename);
-                    const dirName = 'app/public/upload/extra/' + moment().format('YYYYMMDD');
-                    const fileName = create_time + '_' + index + fileInfo.ext;
+                let index = 0;
+                for (const file of ctx.request.files) {
+                    try {
+                        const fileInfo = path.parse(file.filename);
+                        const dirName = 'app/public/upload/extra/' + moment().format('YYYYMMDD');
+                        const fileName = create_time + '_' + index + fileInfo.ext;
 
-                    // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
-                    await sendToWormhole(stream);
+                        await this.ctx.helper.recursiveMkdirSync(path.join(this.app.baseDir, dirName));
+                        await fs.copyFileSync(file.filepath, path.join(this.app.baseDir, dirName, fileName));
 
-                    // 插入到stage_pay对应的附件列表中
-                    bonus.proof_file.push({
-                        filename: fileInfo.name,
-                        fileext: fileInfo.ext,
-                        filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
-                        filepath: path.join(dirName, fileName),
-                        uid: ctx.session.sessionUser.accountId,
-                        in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
-                    });
-                    ++index;
+                        bonus.proof_file.push({
+                            filename: fileInfo.name,
+                            fileext: fileInfo.ext,
+                            filesize: Array.isArray(ctx.request.body.size) ? ctx.request.body.size[index] : ctx.request.body.size,
+                            filepath: path.join(dirName, fileName),
+                            uid: ctx.session.sessionUser.accountId,
+                            in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
+                        });
+                        ++index;
+                    } finally {
+                        await fs.unlinkSync(file.filepath);
+                    }
                 }
                 const result = await ctx.service.stageBonus.updateDatas({
                     update: [
@@ -242,10 +237,6 @@ module.exports = app => {
                 ctx.body = {err: 0, msg: '', data: bonus.proof_file};
             } catch (error) {
                 ctx.helper.log(error);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 ctx.body = this.ajaxErrorBody(error, '上传附件失败,请重试');
             }
         }

+ 12 - 11
app/controller/tender_controller.js

@@ -19,7 +19,7 @@ const accountPermission = require('../const/account_permission');
 const measureType = require('../const/tender').measureType;
 const billsPosConvert = require('../lib/bills_pos_convert');
 const path = require('path');
-const sendToWormhole = require('stream-wormhole');
+const fs = require('fs');
 
 module.exports = app => {
 
@@ -911,17 +911,18 @@ module.exports = app => {
          */
         async saveCooperateSign(ctx) {
             try {
-                const stream = await ctx.getFileStream();
                 const create_time = Date.parse(new Date()) / 1000;
-                const id = stream.fields.id;
-                const fileInfo = path.parse(stream.filename);
-                const fileName = path.join('public/upload', ctx.tender.id.toString(), 'sign', 'signImg_' + create_time + fileInfo.ext);
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', fileName));
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
-                await ctx.service.ledgerCooperation.saveSign(id, fileName);
-                ctx.body = { err: 0, msg: '', data: fileName };
+                const id = ctx.request.body.id;
+                const file = ctx.request.files[0];
+                try {
+                    const fileInfo = path.parse(file.filename);
+                    const fileName = path.join('public/upload', ctx.tender.id.toString(), 'sign', 'signImg_' + create_time + fileInfo.ext);
+                    await this.ctx.helper.copyFileSync(file.filepath, path.join(this.app.baseDir, 'app', fileName));
+                    await ctx.service.ledgerCooperation.saveSign(id, fileName);
+                    ctx.body = { err: 0, msg: '', data: fileName };
+                } finally {
+                    await fs.unlinkSync(file.filepath);
+                }
             } catch (err) {
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };

+ 8 - 0
app/extend/helper.js

@@ -571,6 +571,14 @@ module.exports = {
         await this.saveBufferFile(buffer, fileName);
     },
 
+    async copyFileSync(source, target) {
+        const pathName = path.dirname(target);
+        if (!fs.existsSync(pathName)) {
+            await this.recursiveMkdirSync(pathName);
+        }
+        await fs.copyFileSync(source, target);
+    },
+
     /**
      * 检查code是否是指标模板数据
      * @param {String} code

二進制
app/public/files/template/ledger/导入分项清单EXCEL格式.xlsx


+ 1 - 1
app/public/js/se_bonus.js

@@ -183,7 +183,7 @@ $(document).ready(() => {
                     toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
                     return false;
                 }
-                formData.append('size[]', file.size);
+                formData.append('size', file.size);
                 formData.append('file[]', file);
             }
             postDataWithFile('upload/file', formData, function (data) {

+ 1 - 1
app/public/js/shenpi.js

@@ -845,7 +845,7 @@ $(document).ready(function () {
         // 更新新的多人协同表格信息
         const newUidList = [];
         $('.stage_div ul li').each(function (k, v) {
-            const uid = $(v).find('a').data('id');
+            const uid = $(v).find('button').eq(0).data('id');
             if(uid) newUidList.push(uid);
         });
         const oldUidList = [];

+ 1 - 1
app/service/ledger_revise.js

@@ -142,7 +142,7 @@ module.exports = app => {
                     status: audit.status.uncheck,
                 });
             }
-            await transaction.insert(this.ctx.service.reviseAudit.tableName, newAuditors);
+            if (auditors) await transaction.insert(this.ctx.service.reviseAudit.tableName, newAuditors);
         }
 
         /**

+ 1 - 0
app/service/report.js

@@ -32,6 +32,7 @@ module.exports = app => {
 
         async getReportData(params, filters, memFieldKeys, customDefine, customSelect) {
             const service = this.ctx.service;
+            await service.tender.checkTender(params.tender_id);
             const rst = {};
             const runnableRst = [];
             const runnableKey = []; // 这个配合runnableRst用,未来考虑并行查询优化

+ 0 - 2
app/view/ledger/bwtz.ejs

@@ -53,7 +53,6 @@
                                         </div>
                                     </a>
                                 </div>
-                                <% if (ctx.app.config.is_debug) {%>
                                 <div class="d-inline-block">
                                     <div class="input-group input-group-sm ml-2">
                                         <div class="input-group-prepend">
@@ -65,7 +64,6 @@
                                 <div class="d-inline-block ml-2">
                                     <div class="alert-warning p-1"><i class="fa Example of exclamation-circle fa-exclamation-circle "></i> 父项/子项任一符合,均显示</div>
                                 </div>
-                                <% } %>
                             </li>
                         </ul>
                     </div>

+ 0 - 2
app/view/stage/bwtz.ejs

@@ -65,7 +65,6 @@
                                         </div>
                                     </a>
                                 </div>
-                                <% if (ctx.app.config.is_debug) {%>
                                 <div class="d-inline-block">
                                     <div class="input-group input-group-sm ml-2">
                                         <div class="input-group-prepend">
@@ -77,7 +76,6 @@
                                 <div class="d-inline-block ml-2">
                                     <div class="alert-warning p-1"><i class="fa Example of exclamation-circle fa-exclamation-circle "></i> 父项/子项任一符合,均显示</div>
                                 </div>
-                                <% } %>
                             </li>
                         </ul>
                     </div>

+ 1 - 1
app/view/stage_extra/bonus_modal.ejs

@@ -9,7 +9,7 @@
                 <% if (!ctx.stage.readOnly) { %>
                 <div class="form-group" id="upload-file-panel">
                     <label for="formGroupExampleInput">大小限制:30MB,支持<span data-toggle="tooltip" data-placement="bottom" title="doc,docx,xls,xlsx,ppt,pptx,pdf">office等文档格式</span>、<span data-toggle="tooltip" data-placement="bottom" title="jpg,png,bmp">图片格式</span>、<span data-toggle="tooltip" data-placement="bottom" title="rar,zip">压缩包格式</span></label>
-                    <input type="file" class="" id="upload-file" multiple onclick="file">
+                    <input type="file" class="" id="upload-file" multiple>
                 </div>
                 <% } %>
                 <div class="modal-height-500" style="overflow:auto;">

+ 1 - 0
config/config.default.js

@@ -122,6 +122,7 @@ module.exports = appInfo => {
             '.zip', '.rar', '.7z', ''],
         fileSize: '30mb',
         fields: '15',
+        mode: 'file',
     };
 
     // 是否压缩替换前端js

+ 3 - 13
db_script/stage-change-final.js

@@ -10,20 +10,10 @@
 const audit = require('../app/const/audit');
 
 const mysql = require('mysql');
+const config = process.argv.splice(2);
+const mysqlOptions = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' }).mysql;
 
-const pool = mysql.createPool({
-    // host
-    host: '192.168.1.76',
-    // 端口号
-    port: '3306',
-    // 用户名
-    user: 'zh_dev',
-    // 密码
-    password: 'zongheng2019',
-    // 数据库名
-    database: 'calculation',
-    // database: 'calc_copy_pro',
-});
+const pool = mysql.createPool(mysqlOptions);
 
 const querySql = async function (sql, sqlParam) {
     return new Promise(function (resolve, reject) {

+ 19 - 0
sql/update.sql

@@ -23,3 +23,22 @@ ADD COLUMN `check_calc`  tinyint(1) NULL DEFAULT 1 COMMENT '是否检查计算'
 
 ALTER TABLE `zh_revise_bills`
 ADD COLUMN `check_calc`  tinyint(1) NULL DEFAULT 1 COMMENT '是否检查计算' AFTER `dagl_url`;
+
+-- ----------------------------
+-- Table structure for zh_project_log
+-- ----------------------------
+CREATE TABLE `zh_project_log` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `pid` int(11) NOT NULL COMMENT '操作项目',
+  `tid` int(11) NOT NULL COMMENT '操作标段',
+  `uid` int(11) NOT NULL COMMENT '操作人',
+  `type` tinyint(1) NOT NULL COMMENT '操作模块',
+  `status` tinyint(1) NOT NULL COMMENT '操作状态',
+  `msg` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '操作名称',
+  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间',
+  `os` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '系统信息',
+  `browser` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '浏览器信息',
+  `ip` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '操作人IP地址',
+  `address` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '操作人地址(接口获取)',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='项目操作日志';