浏览代码

中间计量,上传草图、计量台账,附件,替换文件、签名、上传签约清单,接收上传数据调整

MaiXinRong 4 年之前
父节点
当前提交
96e0d31b52

+ 8 - 9
app/controller/deal_bills_controller.js

@@ -12,7 +12,6 @@ const fs = require('fs');
 const path = require('path');
 const path = require('path');
 const excel = require('node-xlsx');
 const excel = require('node-xlsx');
 const xlsx = require('js-xlsx');
 const xlsx = require('js-xlsx');
-const sendToWormhole = require('stream-wormhole');
 const loadExcelType = {
 const loadExcelType = {
     display: 1,
     display: 1,
     actual: 2,
     actual: 2,
@@ -73,15 +72,19 @@ module.exports = app => {
          * @return {Promise<void>}
          * @return {Promise<void>}
          */
          */
         async loadExcel(ctx) {
         async loadExcel(ctx) {
-            let stream;
             try {
             try {
                 await this.checkPermisision(ctx);
                 await this.checkPermisision(ctx);
-                stream = await ctx.getFileStream();
+
+                const file = ctx.request.files[0];
                 const create_time = Date.parse(new Date()) / 1000;
                 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;
                 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) {
                 if (loadType === loadExcelType.display) {
                     const wb = xlsx.readFile(fileName);
                     const wb = xlsx.readFile(fileName);
                     const name = wb.SheetNames[0];
                     const name = wb.SheetNames[0];
@@ -112,10 +115,6 @@ module.exports = app => {
                 ctx.body = {err: 0, msg: '', data: dealBills};
                 ctx.body = {err: 0, msg: '', data: dealBills};
             } catch (err) {
             } catch (err) {
                 this.log(err);
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.ajaxErrorBody(err, '导入数据失败');
                 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 };
                 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)
          * 填设计量(Ajax)

+ 0 - 1
app/controller/material_controller.js

@@ -17,7 +17,6 @@ const accountGroup = require('../const/account_group').group;
 const materialConst = require('../const/material');
 const materialConst = require('../const/material');
 const shenpiConst = require('../const/shenpi');
 const shenpiConst = require('../const/shenpi');
 const MaterialCalculator = require('../lib/material_calc');
 const MaterialCalculator = require('../lib/material_calc');
-const sendToWormhole = require('stream-wormhole');
 const fs = require('fs');
 const fs = require('fs');
 const path = require('path');
 const path = require('path');
 const _ = require('lodash');
 const _ = require('lodash');

+ 7 - 5
app/controller/profile_controller.js

@@ -13,7 +13,6 @@ const profileMenu = require('../../config/menu').profileMenu;
 const smsTypeConst = require('../const/sms_type');
 const smsTypeConst = require('../const/sms_type');
 const qr = require('qr-image');
 const qr = require('qr-image');
 const path = require('path');
 const path = require('path');
-const sendToWormhole = require('stream-wormhole');
 const loginWay = require('../const/setting').loginWay;
 const loginWay = require('../const/setting').loginWay;
 
 
 module.exports = app => {
 module.exports = app => {
@@ -322,13 +321,16 @@ module.exports = app => {
                 err: 0, msg: '', data: null,
                 err: 0, msg: '', data: null,
             };
             };
             try {
             try {
-                const stream = await ctx.getFileStream();
                 const create_time = Date.parse(new Date()) / 1000;
                 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 dirName = 'public/upload/sign';
                 const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + fileInfo.ext;
                 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 });
                 const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: ctx.session.sessionUser.accountId });
                 if (result) {
                 if (result) {
                     responseData.data = { sign_path: fileName };
                     responseData.data = { sign_path: fileName };

+ 6 - 4
app/controller/sign_controller.js

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

+ 19 - 24
app/controller/stage_controller.js

@@ -21,7 +21,6 @@ const measureType = tenderConst.measureType;
 const path = require('path');
 const path = require('path');
 const PayCalculator = require('../lib/pay_calc');
 const PayCalculator = require('../lib/pay_calc');
 const accountGroup = require('../const/account_group').group;
 const accountGroup = require('../const/account_group').group;
-const sendToWormhole = require('stream-wormhole');
 const billsPosConvert = require('../lib/bills_pos_convert');
 const billsPosConvert = require('../lib/bills_pos_convert');
 const fs = require('fs');
 const fs = require('fs');
 const stdConst = require('../const/standard');
 const stdConst = require('../const/standard');
@@ -669,12 +668,16 @@ module.exports = app => {
             try {
             try {
                 this._checkStageCanModify(ctx);
                 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) {
             } catch (err) {
                 this.log(err);
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
                 ctx.body = { err: 1, msg: err.toString(), data: null };
@@ -1489,42 +1492,34 @@ module.exports = app => {
                 msg: '',
                 msg: '',
                 data: [],
                 data: [],
             };
             };
-            let stream;
             try {
             try {
-                this._checkStageCanModifyRe(ctx);
-                stream = await ctx.getFileStream({ requireFile: false });
+                //this._checkStageCanModifyRe(ctx);
+
+                const file = ctx.request.files[0];
                 let fileData = {};
                 let fileData = {};
-                if (stream.filename !== undefined) {
+                if (file && file.filename !== undefined) {
                     const create_time = Date.parse(new Date()) / 1000;
                     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 dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
                     const fileName = 'stage' + create_time + fileInfo.ext;
                     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表
                     // 保存数据到att表
                     fileData = {
                     fileData = {
-                        filesize: stream.fields.size,
+                        filesize: ctx.request.body.size,
                         filepath: path.join(dirName, fileName),
                         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) {
                 if (!result) {
                     throw '导入数据库保存失败';
                     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');
                 attData.in_time = moment(attData.in_time * 1000).format('YYYY-MM-DD');
                 responseData.data = attData;
                 responseData.data = attData;
             } catch (err) {
             } catch (err) {
                 this.log(err);
                 this.log(err);
-                // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
                 this.setMessage(err.toString(), this.messageType.ERROR);
                 this.setMessage(err.toString(), this.messageType.ERROR);
                 responseData.err = 1;
                 responseData.err = 1;
                 responseData.msg = err.toString();
                 responseData.msg = err.toString();

+ 11 - 11
app/controller/tender_controller.js

@@ -19,7 +19,6 @@ const accountPermission = require('../const/account_permission');
 const measureType = require('../const/tender').measureType;
 const measureType = require('../const/tender').measureType;
 const billsPosConvert = require('../lib/bills_pos_convert');
 const billsPosConvert = require('../lib/bills_pos_convert');
 const path = require('path');
 const path = require('path');
-const sendToWormhole = require('stream-wormhole');
 
 
 module.exports = app => {
 module.exports = app => {
 
 
@@ -911,17 +910,18 @@ module.exports = app => {
          */
          */
         async saveCooperateSign(ctx) {
         async saveCooperateSign(ctx) {
             try {
             try {
-                const stream = await ctx.getFileStream();
                 const create_time = Date.parse(new Date()) / 1000;
                 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) {
             } catch (err) {
                 this.log(err);
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
                 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);
         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是否是指标模板数据
      * 检查code是否是指标模板数据
      * @param {String} code
      * @param {String} code