瀏覽代碼

归档加密信息调整

TonyKang 3 年之前
父節點
當前提交
435c943893
共有 2 個文件被更改,包括 55 次插入28 次删除
  1. 36 27
      app/controller/report_archive_controller.js
  2. 19 1
      app/public/report/js/rpt_archive.js

+ 36 - 27
app/controller/report_archive_controller.js

@@ -121,12 +121,17 @@ module.exports = app => {
             };
         }
 
+        async _updateReportArchiveEncryption(prjId, stgId, rptId, ttlPgs, uuid, content) {
+            //
+        }
+
         async addReportArchiveEncryption(ctx) {
             const params = JSON.parse(ctx.request.body.params);
             const prjId = params.prjId;
             const stgId = params.stgId;
             const rptId = params.rptId;
             const ttlPgs = params.ttlPgs;
+            const uuid = params.uuid;
             const content = params.content;
             const orgArchiveList = await ctx.service.rptArchiveEncryption.getPrjStgArchiveEncryption(prjId, stgId);
             if (orgArchiveList.length > 0) {
@@ -135,15 +140,18 @@ module.exports = app => {
                 for (const item of contentArr) {
                     if (item.rpt_id === rptId) {
                         // 考虑到报表模板的稳定性,只保留一项来记录位置就足够了,都不考虑用uuid了
-                        item.encryption = content;
-                        item.total_page = ttlPgs;
-                        hasArchive = true;
-                        break;
+                        if (item.uuid === uuid) {
+                            // 最后打脸了,还真的要考虑不同的uuid,不早说,TNND
+                            item.encryption = content;
+                            item.total_page = ttlPgs;
+                            hasArchive = true;
+                            break;
+                        }
                     }
                 }
                 if (!hasArchive) {
                     // 表示有新的要加
-                    contentArr.push({ rpt_id: rptId, total_page: ttlPgs, encryption: content });
+                    contentArr.push({ rpt_id: rptId, uuid, total_page: ttlPgs, encryption: content });
                 } else {
                     //
                 }
@@ -153,7 +161,7 @@ module.exports = app => {
             } else {
                 // 需要增加
                 const archiveArr = [];
-                archiveArr.push({ rpt_id: rptId, total_page: ttlPgs, encryption: content });
+                archiveArr.push({ rpt_id: rptId, uuid, total_page: ttlPgs, encryption: content });
                 const addedRst = await ctx.service.rptArchiveEncryption.createArchiveEncryption(prjId, stgId, archiveArr);
                 // console.log(addedRst);
                 ctx.body = { err: 0, msg: '', data: { addedRst: archiveArr } };
@@ -166,8 +174,8 @@ module.exports = app => {
                 const prjId = ctx.params.prjId;
                 const stgId = ctx.params.stgId;
                 const rptId = ctx.params.rptId;
-                const newName = uuidV1();
-                const fileName = newName + '.PDF';
+                const newUuidName = uuidV1();
+                const fileName = newUuidName + '.PDF';
                 // console.log('adding fileName: ' + fileName);
                 // await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', 'public/archive', fileName));
                 const oss_result = await ctx.oss.put('archive/' + fileName, stream);
@@ -211,25 +219,25 @@ module.exports = app => {
                                 await ctx.oss.delete('archive/' + item.items[rmIdx].uuid + '.PDF');
                                 item.items.splice(rmIdx, 1);
                             }
-                            const newItem = { uuid: newName, updateDate_time: dtStr };
+                            const newItem = { uuid: newUuidName, updateDate_time: dtStr };
                             item.items.push(newItem);
                             break;
                         }
                     }
                     if (!hasArchive) {
                         // 表示有新的模板需要添加
-                        contentArr.push({ rpt_id: rptId, items: [{ uuid: newName, updateDate_time: dtStr }] });
+                        contentArr.push({ rpt_id: rptId, items: [{ uuid: newUuidName, updateDate_time: dtStr }] });
                     }
                     const updatedRst = await ctx.service.rptArchive.updateArchive(orgArchiveList[0].id, prjId, stgId, contentArr);
                     // console.log(updatedRst);
-                    ctx.body = { err: 0, msg: '', data: { fileName, updateDate, addedRst: contentArr } };
+                    ctx.body = { err: 0, msg: newUuidName, data: { uuid: newUuidName, fileName, updateDate, addedRst: contentArr } };
                 } else {
                     // 需要增加
                     const archiveArr = [];
-                    archiveArr.push({ rpt_id: rptId, items: [{ uuid: newName, updateDate_time: dtStr }] });
+                    archiveArr.push({ rpt_id: rptId, items: [{ uuid: newUuidName, updateDate_time: dtStr }] });
                     const addedRst = await ctx.service.rptArchive.createArchive(prjId, stgId, archiveArr);
                     // console.log(addedRst);
-                    ctx.body = { err: 0, msg: '', data: { fileName, updateDate, addedRst: archiveArr } };
+                    ctx.body = { err: 0, msg: newUuidName, data: { uuid: newUuidName, fileName, updateDate, addedRst: archiveArr } };
                 }
             } catch (err) {
                 this.log(err);
@@ -248,8 +256,8 @@ module.exports = app => {
                 const prjId = ctx.params.prjId;
                 const stgId = ctx.params.stgId;
                 const rptId = ctx.params.rptId;
-                const orgName = ctx.params.orgName;
-                const fileName = orgName + '.PDF';
+                const orgUuidName = ctx.params.orgName;
+                const fileName = orgUuidName + '.PDF';
                 console.log('updating fileName: ' + fileName);
                 // await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', 'public/archive', fileName));
                 const oss_result = await ctx.oss.put('archive/' + fileName, stream);
@@ -257,11 +265,11 @@ module.exports = app => {
                     throw '上传文件失败';
                 }
                 // 判断是否存在已签名文档,存在则删除文档并删除签名记录
-                const pdfMsg = await ctx.curl(signConst.path.oss + '/sign/' + orgName + '.PDF');
+                const pdfMsg = await ctx.curl(signConst.path.oss + '/sign/' + orgUuidName + '.PDF');
                 if (pdfMsg && pdfMsg.status === 200) {
                     const oss_reuslt = await ctx.oss.delete('archive/sign/' + fileName);
                     if (oss_reuslt && oss_reuslt.res && oss_reuslt.res.status === 204) {
-                        const delSign_result = await ctx.service.netcasignLog.removeSign(orgName);
+                        const delSign_result = await ctx.service.netcasignLog.removeSign(orgUuidName);
                     } else {
                         throw '删除已签文档失败';
                     }
@@ -287,27 +295,27 @@ module.exports = app => {
                         if (item.rpt_id === rptId) {
                             if (item.items && item.items.length > 0) {
                                 for (const subItem of item.items) {
-                                    if (subItem.uuid === orgName) {
+                                    if (subItem.uuid === orgUuidName) {
                                         subItem.updateDate_time = dtStr;
                                         break;
                                     }
                                 }
                             } else {
-                                item.items = [{ uuid: orgName, updateDate_time: dtStr }];
+                                item.items = [{ uuid: orgUuidName, updateDate_time: dtStr }];
                             }
                             break;
                         }
                     }
                     const updatedRst = await ctx.service.rptArchive.updateArchive(orgArchiveList[0].id, prjId, stgId, contentArr);
                     // console.log(updatedRst);
-                    ctx.body = { err: 0, msg: '', data: { fileName, updateDate, updatedRst: contentArr } };
+                    ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updateDate, updatedRst: contentArr } };
                 } else {
                     // 需要增加
                     const archiveArr = [];
-                    archiveArr.push({ rpt_id: rptId, items: [{ uuid: orgName, updateDate_time: dtStr }] });
+                    archiveArr.push({ rpt_id: rptId, items: [{ uuid: orgUuidName, updateDate_time: dtStr }] });
                     const updatedRst = await ctx.service.rptArchive.createArchive(prjId, stgId, archiveArr);
                     // console.log(updatedRst);
-                    ctx.body = { err: 0, msg: '', data: { fileName, updateDate, updatedRst: archiveArr } };
+                    ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updateDate, updatedRst: archiveArr } };
                 }
             } catch (err) {
                 this.log(err);
@@ -320,6 +328,7 @@ module.exports = app => {
                 const prjId = ctx.params.prjId;
                 const stgId = ctx.params.stgId;
                 const rptId = ctx.params.rptId;
+                // const uuid = ctx.params.uuid;
                 const orgArchiveList = await ctx.service.rptArchiveEncryption.getPrjStgArchiveEncryption(prjId, stgId);
                 if (orgArchiveList.length > 0) {
                     const contentArr = JSON.parse(orgArchiveList[0].content);
@@ -345,8 +354,8 @@ module.exports = app => {
                 const prjId = ctx.params.prjId;
                 const stgId = ctx.params.stgId;
                 const rptId = ctx.params.rptId;
-                const orgName = ctx.params.orgName;
-                const fileName = orgName + '.PDF';
+                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));
@@ -372,7 +381,7 @@ module.exports = app => {
                         if (item.rpt_id === rptId) {
                             if (item.items && item.items.length > 0) {
                                 for (const subIdx in item.items) {
-                                    if (item.items[subIdx].uuid === orgName) {
+                                    if (item.items[subIdx].uuid === orgUuidName) {
                                         item.items.splice(subIdx, 1);
                                         break;
                                     }
@@ -382,9 +391,9 @@ module.exports = app => {
                         }
                     }
                     const updatedRst = await ctx.service.rptArchive.updateArchive(prjId, stgId, contentArr);
-                    ctx.body = { err: 0, msg: '', data: { fileName, updatedRst } };
+                    ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updatedRst } };
                 } else {
-                    ctx.body = { err: 0, msg: '', data: { fileName, updatedRst: null } };
+                    ctx.body = { err: 0, msg: orgUuidName, data: { fileName, updatedRst: null } };
                 }
             } catch (err) {
                 this.log(err);

+ 19 - 1
app/public/report/js/rpt_archive.js

@@ -523,13 +523,14 @@ let rptArchiveObj = {
                             ARCHIVE_LIST = result.addedRst;
                             rptArchiveObj.showArchivedItem(currentNode);
                             zTreeOprObj.refreshNodes();
-                            //第二步:增加
+                            //第二步:增加加密信息
                             let params = {};
                             params.prjId = PROJECT_ID;
                             params.stgId = current_stage_id;
                             params.rptId = currentNode.refId;
                             params.ttlPgs = currentRptPageRst.items.length;
                             params.content = pageEncryptInfo;
+                            params.uuid = result.uuid; //正确返回时,带着uuid回来
                             CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
                                 function(result){
                                     //
@@ -568,6 +569,23 @@ let rptArchiveObj = {
                                 ARCHIVE_LIST = result.updatedRst;
                                 rptArchiveObj.showArchivedItem(currentNode);
                                 zTreeOprObj.refreshNodes();
+                                //第二步:更新加密信息
+                                let params = {};
+                                params.prjId = PROJECT_ID;
+                                params.stgId = current_stage_id;
+                                params.rptId = currentNode.refId;
+                                params.ttlPgs = currentRptPageRst.items.length;
+                                params.content = pageEncryptInfo;
+                                params.uuid = orgName;
+                                CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
+                                    function(result){
+                                        //
+                                    }, function(err){
+                                        //
+                                    }, function(ex){
+                                        //
+                                    }
+                                );
                             } else {
                                 // 有冲突,需要删除
                                 CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),