|
@@ -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();
|