|
@@ -544,8 +544,7 @@ module.exports = app => {
|
|
|
renderData.whiteList = this.ctx.app.config.multipart.whitelist;
|
|
|
|
|
|
// 用户有无权限上传和删除附件
|
|
|
- renderData.uploadPermission = (ctx.stage.status === auditConst.status.uncheck && ctx.session.sessionUser.accountId === ctx.stage.user_id) ||
|
|
|
- (ctx.stage.status === auditConst.status.checking && ctx.session.sessionUser.accountId === ctx.stage.user_id) ||
|
|
|
+ renderData.uploadPermission = ((ctx.stage.status === auditConst.status.uncheck || ctx.stage.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === ctx.stage.user_id) ||
|
|
|
(ctx.stage.status === auditConst.status.checkNoPre && ctx.session.sessionUser.accountId === ctx.stage.curAuditor.aid) ||
|
|
|
(ctx.stage.status === auditConst.status.checking && ctx.stage.curAuditor && ctx.stage.curAuditor.aid === ctx.session.sessionUser.accountId);
|
|
|
|
|
@@ -1004,35 +1003,50 @@ module.exports = app => {
|
|
|
};
|
|
|
let stream;
|
|
|
try {
|
|
|
- stream = await ctx.getFileStream();
|
|
|
- const create_time = Date.parse(new Date()) / 1000;
|
|
|
- const fileInfo = path.parse(stream.filename);
|
|
|
- const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
|
|
|
- const fileName = 'stage' + create_time + fileInfo.ext;
|
|
|
+ const parts = ctx.multipart({ autoFields: true });
|
|
|
+ const files = [];
|
|
|
+ let index = 0;
|
|
|
+ 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 create_time = Date.parse(new Date()) / 1000;
|
|
|
+ const fileInfo = path.parse(stream.filename);
|
|
|
+ const fileName = 'stage' + 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));
|
|
|
- // 保存数据到att表
|
|
|
- const fileData = {
|
|
|
- tid: ctx.params.id,
|
|
|
- sid: ctx.params.order,
|
|
|
- in_time: create_time,
|
|
|
- filename: fileInfo.name,
|
|
|
- fileext: fileInfo.ext,
|
|
|
- filesize: stream.fields.size,
|
|
|
- filepath: path.join(dirName, fileName),
|
|
|
- };
|
|
|
- const result = await ctx.service.stageAtt.save(stream.fields, fileData, ctx.session.sessionUser.accountId);
|
|
|
- if (!result) {
|
|
|
- throw '导入数据库保存失败';
|
|
|
+ // 保存文件
|
|
|
+ await ctx.helper.saveStreamFile(stream, path.join(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: path.join(dirName, fileName),
|
|
|
+ };
|
|
|
+ const result = await ctx.service.stageAtt.save(parts.field, 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;
|
|
|
}
|
|
|
- const attData = await ctx.service.stageAtt.getDataByFid(result.insertId);
|
|
|
- attData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
|
|
|
- responseData.data = attData;
|
|
|
+ responseData.data = files;
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
|
// 失败需要消耗掉stream 以防卡死
|
|
@@ -1188,34 +1202,45 @@ module.exports = app => {
|
|
|
};
|
|
|
let stream;
|
|
|
try {
|
|
|
- stream = await ctx.getFileStream();
|
|
|
+ const parts = ctx.multipart({ autoFields: true });
|
|
|
+ const files = [];
|
|
|
+ let index = 0;
|
|
|
const create_time = Date.parse(new Date()) / 1000;
|
|
|
- const fileInfo = path.parse(stream.filename);
|
|
|
- const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
|
|
|
- const fileName = 'pay' + create_time + fileInfo.ext;
|
|
|
+ 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));
|
|
|
- // 插入到stage_pay对应的附件列表中
|
|
|
- const attData = {
|
|
|
- filename: fileInfo.name,
|
|
|
- fileext: fileInfo.ext,
|
|
|
- filesize: stream.fields.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(stream.fields.pay_id, attData);
|
|
|
- if (!result) {
|
|
|
- throw '导入数据库保存失败';
|
|
|
+ // 判断文件夹是否存在,不存在则直接创建文件夹
|
|
|
+ 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 '导入数据库保存失败';
|
|
|
+ }
|
|
|
+ delete attData.filepath;
|
|
|
+ attData.username = ctx.session.sessionUser.name;
|
|
|
+ files.length !== 0 ? files.unshift(attData) : files.push(attData);
|
|
|
+ ++index;
|
|
|
}
|
|
|
- delete attData.filepath
|
|
|
- attData.username = ctx.session.sessionUser.name;
|
|
|
- responseData.data = attData;
|
|
|
+ responseData.data = files;
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
|
// 失败需要消耗掉stream 以防卡死
|