|
@@ -19,6 +19,7 @@ const sendToWormhole = require('stream-wormhole');
|
|
|
const fs = require('fs');
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
const PermissionCheck = require('../const/account_permission').PermissionCheck;
|
|
const PermissionCheck = require('../const/account_permission').PermissionCheck;
|
|
|
|
|
+const InspectionAttachment = require('../lib/inspection_attachment');
|
|
|
|
|
|
|
|
module.exports = app => {
|
|
module.exports = app => {
|
|
|
class QualityController extends app.BaseController {
|
|
class QualityController extends app.BaseController {
|
|
@@ -609,7 +610,7 @@ module.exports = app => {
|
|
|
filter.count[filter.status.checkStop] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.checkStop);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
|
|
filter.count[filter.status.checkStop] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.checkStop);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
|
|
|
const inspectionList = await ctx.service.qualityInspection.getListByStatus(ctx.tender.id, status, 1, sorts, orders);
|
|
const inspectionList = await ctx.service.qualityInspection.getListByStatus(ctx.tender.id, status, 1, sorts, orders);
|
|
|
const total = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, status);
|
|
const total = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, status);
|
|
|
- const allAttList = inspectionList.length > 0 ? await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.helper._.map(inspectionList, 'id')) : [];
|
|
|
|
|
|
|
+ const allAttList = inspectionList.length > 0 ? await new InspectionAttachment(ctx, 'quality').getFiles(ctx.helper._.map(inspectionList, 'id')) : [];
|
|
|
for (const c of inspectionList) {
|
|
for (const c of inspectionList) {
|
|
|
c.attList = ctx.helper._.filter(allAttList, { qiid: c.id });
|
|
c.attList = ctx.helper._.filter(allAttList, { qiid: c.id });
|
|
|
c.curAuditors = await ctx.service.qualityInspectionAudit.getAuditorsByStatus(c.id, c.status, c.times);
|
|
c.curAuditors = await ctx.service.qualityInspectionAudit.getAuditorsByStatus(c.id, c.status, c.times);
|
|
@@ -735,7 +736,7 @@ module.exports = app => {
|
|
|
const tender = await ctx.service.tender.getDataById(ctx.tender.id);
|
|
const tender = await ctx.service.tender.getDataById(ctx.tender.id);
|
|
|
await this._getInspectionAuditViewData(ctx);
|
|
await this._getInspectionAuditViewData(ctx);
|
|
|
// 获取附件列表
|
|
// 获取附件列表
|
|
|
- const fileList = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
|
|
|
|
|
|
|
+ const fileList = await new InspectionAttachment(ctx, 'quality').getFiles(ctx.inspection.id);
|
|
|
// 获取用户人验证手机号
|
|
// 获取用户人验证手机号
|
|
|
const renderData = {
|
|
const renderData = {
|
|
|
moment,
|
|
moment,
|
|
@@ -898,26 +899,23 @@ module.exports = app => {
|
|
|
*/
|
|
*/
|
|
|
async uploadInspectionFile(ctx) {
|
|
async uploadInspectionFile(ctx) {
|
|
|
let stream;
|
|
let stream;
|
|
|
|
|
+ const files = [];
|
|
|
|
|
+ let saved = false;
|
|
|
try {
|
|
try {
|
|
|
- if (ctx.inspection.flow_version === 1 && !ctx.inspection.canUpload) throw '当前不可上传附件';
|
|
|
|
|
|
|
+ const attachment = new InspectionAttachment(ctx, 'quality');
|
|
|
|
|
+ if (!attachment.canUpload(ctx.inspection)) throw '当前不可上传附件';
|
|
|
const parts = this.ctx.multipart({
|
|
const parts = this.ctx.multipart({
|
|
|
autoFields: true,
|
|
autoFields: true,
|
|
|
});
|
|
});
|
|
|
- const files = [];
|
|
|
|
|
- const create_time = Date.parse(new Date()) / 1000;
|
|
|
|
|
- let idx = 0;
|
|
|
|
|
- const extra_upload = ctx.inspection.status === auditConst.inspection.status.checked;
|
|
|
|
|
while ((stream = await parts()) !== undefined) {
|
|
while ((stream = await parts()) !== undefined) {
|
|
|
if (!stream.filename) {
|
|
if (!stream.filename) {
|
|
|
- // 如果没有传入直接返回
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ throw '请选择附件';
|
|
|
}
|
|
}
|
|
|
const fileInfo = path.parse(stream.filename);
|
|
const fileInfo = path.parse(stream.filename);
|
|
|
- const filepath = `app/public/upload/${this.ctx.tender.id.toString()}/quality_inspection/fujian_${create_time + idx.toString() + fileInfo.ext}`;
|
|
|
|
|
|
|
+ const filepath = `app/public/upload/${this.ctx.tender.id.toString()}/quality_inspection/fujian_${ctx.app.uuid.v4()}${fileInfo.ext}`;
|
|
|
// await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
|
|
// await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
|
|
|
await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
|
|
await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
|
|
|
files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
|
|
files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
|
|
|
- ++idx;
|
|
|
|
|
stream && (await sendToWormhole(stream));
|
|
stream && (await sendToWormhole(stream));
|
|
|
}
|
|
}
|
|
|
const in_time = new Date();
|
|
const in_time = new Date();
|
|
@@ -937,17 +935,27 @@ module.exports = app => {
|
|
|
filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
|
|
filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
|
|
|
filepath: file.filepath,
|
|
filepath: file.filepath,
|
|
|
upload_time: in_time,
|
|
upload_time: in_time,
|
|
|
- extra_upload,
|
|
|
|
|
};
|
|
};
|
|
|
return newFile;
|
|
return newFile;
|
|
|
});
|
|
});
|
|
|
// 执行文件信息写入数据库
|
|
// 执行文件信息写入数据库
|
|
|
- await ctx.service.qualityInspectionAtt.saveFileMsgToDb(payload);
|
|
|
|
|
|
|
+ await attachment.saveFiles(payload, JSON.parse(parts.field.flowContext || 'null'));
|
|
|
|
|
+ saved = true;
|
|
|
// 将最新的当前标段的所有文件信息返回
|
|
// 将最新的当前标段的所有文件信息返回
|
|
|
- const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
|
|
|
|
|
|
|
+ const data = await attachment.getFiles(ctx.inspection.id);
|
|
|
ctx.body = { err: 0, msg: '', data };
|
|
ctx.body = { err: 0, msg: '', data };
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
stream && (await sendToWormhole(stream));
|
|
stream && (await sendToWormhole(stream));
|
|
|
|
|
+ // 流程已变更或保存失败时,仅清理本次未入库的上传文件。
|
|
|
|
|
+ if (!saved) {
|
|
|
|
|
+ for (const file of files) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + file.filepath);
|
|
|
|
|
+ } catch (cleanupError) {
|
|
|
|
|
+ this.log(cleanupError);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
this.log(err);
|
|
this.log(err);
|
|
|
ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
|
}
|
|
}
|
|
@@ -959,22 +967,10 @@ module.exports = app => {
|
|
|
*/
|
|
*/
|
|
|
async deleteInspectionFile(ctx) {
|
|
async deleteInspectionFile(ctx) {
|
|
|
try {
|
|
try {
|
|
|
- const { id } = JSON.parse(ctx.request.body.data);
|
|
|
|
|
- const fileInfo = await ctx.service.qualityInspectionAtt.getDataById(id);
|
|
|
|
|
- if (ctx.inspection.flow_version === 1) {
|
|
|
|
|
- if (!fileInfo || fileInfo.qiid !== ctx.inspection.id || !ctx.inspection.canUpload || fileInfo.uid !== ctx.session.sessionUser.accountId) throw '您无权删除该附件';
|
|
|
|
|
- if (ctx.inspection.status === qualityInspectionConst.status.checked && !fileInfo.extra_upload && !PermissionCheck.delFile(ctx.session.sessionUser.permission)) throw '该附件不可删除';
|
|
|
|
|
- }
|
|
|
|
|
- if (fileInfo && Object.keys(fileInfo).length) {
|
|
|
|
|
- // 先删除文件
|
|
|
|
|
- // await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
|
|
|
|
|
- await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + fileInfo.filepath);
|
|
|
|
|
- // 再删除数据库
|
|
|
|
|
- await ctx.service.qualityInspectionAtt.delete(id);
|
|
|
|
|
- } else {
|
|
|
|
|
- throw '不存在该文件';
|
|
|
|
|
- }
|
|
|
|
|
- const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
|
|
|
|
|
|
|
+ const { id, flowContext } = JSON.parse(ctx.request.body.data);
|
|
|
|
|
+ const attachment = new InspectionAttachment(ctx, 'quality');
|
|
|
|
|
+ await attachment.deleteFile(id, flowContext);
|
|
|
|
|
+ const data = await attachment.getFiles(ctx.inspection.id);
|
|
|
ctx.body = { err: 0, msg: '请求成功', data };
|
|
ctx.body = { err: 0, msg: '请求成功', data };
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
this.log(err);
|