|
@@ -408,23 +408,36 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async removeReportArchiveEncryption(ctx) {
|
|
|
+ async _removeReportArchiveEncryption(ctx) {
|
|
|
+ let rst = null;
|
|
|
try {
|
|
|
const prjId = ctx.params.prjId;
|
|
|
const stgId = ctx.params.stgId;
|
|
|
- const rptId = ctx.params.rptId;
|
|
|
- // const uuid = ctx.params.uuid;
|
|
|
+ const rptId = parseInt(ctx.params.rptId);
|
|
|
+ const uuid = ctx.params.orgName;
|
|
|
const orgArchiveList = await ctx.service.rptArchiveEncryption.getPrjStgArchiveEncryption(prjId, stgId);
|
|
|
if (orgArchiveList.length > 0) {
|
|
|
const contentArr = JSON.parse(orgArchiveList[0].content);
|
|
|
- for (let idx = 0; idx < contentArr.length; idx++) {
|
|
|
- if (contentArr[idx].rpt_id === rptId) {
|
|
|
+ for (let idx = contentArr.length - 1; idx >= 0; idx--) {
|
|
|
+ if (contentArr[idx].rpt_id === rptId && contentArr[idx].uuid === uuid) {
|
|
|
contentArr.splice(idx, 1);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- const updatedRst = await ctx.service.rptArchive.updateArchive(prjId, stgId, contentArr);
|
|
|
- ctx.body = { err: 0, msg: '', data: { updatedRst } };
|
|
|
+ // const updatedRst = await ctx.service.rptArchive.updateArchive(prjId, stgId, contentArr);
|
|
|
+ rst = await ctx.service.rptArchiveEncryption.updateArchiveEncryption(orgArchiveList[0].id, prjId, stgId, contentArr);
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ }
|
|
|
+
|
|
|
+ async removeReportArchiveEncryption(ctx) {
|
|
|
+ try {
|
|
|
+ const rst = await this._removeReportArchiveEncryption(ctx);
|
|
|
+ if (rst) {
|
|
|
+ ctx.body = { err: 0, msg: '', data: { updatedRst: rst } };
|
|
|
} else {
|
|
|
ctx.body = { err: 0, msg: '', data: { updatedRst: null } };
|
|
|
}
|
|
@@ -434,35 +447,19 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async removeReportArchive(ctx) {
|
|
|
+ async _removeReportArchive(ctx) {
|
|
|
+ let rst = null;
|
|
|
try {
|
|
|
const prjId = ctx.params.prjId;
|
|
|
const stgId = ctx.params.stgId;
|
|
|
const rptId = ctx.params.rptId;
|
|
|
const orgUuidName = ctx.params.orgName;
|
|
|
- const fileName = orgUuidName + '.PDF';
|
|
|
- console.log('removing fileName: ' + fileName);
|
|
|
- const fullName = path.join(this.app.baseDir, 'app', 'public/archive', fileName);
|
|
|
- // await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', 'public/archive', fileName));
|
|
|
- // fs.stat(fullName, function(err, data) {
|
|
|
- // if (err) {
|
|
|
- // console.log(err);
|
|
|
- // } else {
|
|
|
- // fs.unlink(fullName, function(err) {
|
|
|
- // if (err) {
|
|
|
- // console.log(err);
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
- // });
|
|
|
- const oss_result = await ctx.app.signPdfOss.delete('archive/' + fileName);
|
|
|
- if (!(oss_result && oss_result.res.status === 204)) {
|
|
|
- throw '删除归档文件失败';
|
|
|
- }
|
|
|
+ // const fileName = orgUuidName + '.PDF';
|
|
|
const orgArchiveList = await ctx.service.rptArchive.getPrjStgArchive(prjId, stgId);
|
|
|
if (orgArchiveList.length > 0) {
|
|
|
const contentArr = JSON.parse(orgArchiveList[0].content);
|
|
|
- for (const item of contentArr) {
|
|
|
+ for (let idx = contentArr.length - 1; idx >= 0; idx--) {
|
|
|
+ const item = contentArr[idx];
|
|
|
if (item.rpt_id === rptId) {
|
|
|
if (item.items && item.items.length > 0) {
|
|
|
for (const subIdx in item.items) {
|
|
@@ -471,12 +468,44 @@ module.exports = app => {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ if (item.items.length === 0) {
|
|
|
+ contentArr.splice(idx, 1);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- const updatedRst = await ctx.service.rptArchive.updateArchive(prjId, stgId, contentArr);
|
|
|
- ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updatedRst } };
|
|
|
+ rst = await ctx.service.rptArchive.updateArchive(orgArchiveList[0].id, prjId, stgId, contentArr);
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ }
|
|
|
+
|
|
|
+ async removeReportArchive(ctx) {
|
|
|
+ try {
|
|
|
+ const orgUuidName = ctx.params.orgName;
|
|
|
+ const fileName = orgUuidName + '.PDF';
|
|
|
+ // console.log(ctx.params);
|
|
|
+ console.log('removing fileName: ' + fileName);
|
|
|
+ // const fullName = path.join(this.app.baseDir, 'app', 'public/archive', fileName);
|
|
|
+ const oss_sign_result = await ctx.app.signPdfOss.delete(`archive/sign/${fileName}`);
|
|
|
+ if (oss_sign_result && oss_sign_result.res && oss_sign_result.res.status === 204) {
|
|
|
+ // console.log('删除归档的签名信息成功!');
|
|
|
+ const oss_result = await ctx.app.signPdfOss.delete(`archive/${fileName}`);
|
|
|
+ if (!(oss_result && oss_result.res.status === 204)) {
|
|
|
+ throw '删除归档文件失败';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw '删除归档签名文件失败';
|
|
|
+ }
|
|
|
+ // 还有加密签名信息
|
|
|
+ const archiveSignRemovedRst = await this._removeReportArchiveEncryption(ctx);
|
|
|
+ // console.log(archiveSignRemovedRst);
|
|
|
+ const archiveRemovedRst = await this._removeReportArchive(ctx);
|
|
|
+ if (archiveRemovedRst) {
|
|
|
+ ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updatedRst: archiveRemovedRst } };
|
|
|
} else {
|
|
|
ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updatedRst: null } };
|
|
|
}
|