ソースを参照

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 3 年 前
コミット
65bd8b9505

+ 59 - 30
app/controller/report_archive_controller.js

@@ -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 } };
                 }

+ 75 - 0
app/public/report/js/rpt_archive.js

@@ -694,6 +694,72 @@ let rptArchiveObj = {
         } else {
             alert('请选择打开一个报表!');
         }
+    },
+    
+    _getOneValidLeafNode: function(node) {
+        let rst = null;
+        let me = rptArchiveObj;
+        if (node) {
+            const preNode = node.getPreNode();
+            if (preNode) {
+                rst = preNode;
+            } else {
+                const nodes = me.treeObj.getNodes();
+                for (let dtlNode of nodes) {
+                    if (dtlNode !== node && dtlNode.nodeType === 2) {
+                        rst = dtlNode;
+                        break;
+                    }
+                }
+            }
+        }
+        return rst;
+    },
+
+    removeArchive: function() {
+        let me = rptArchiveObj;
+        const bkRefId = parseInt(me.currentNode.refId);
+        const bkUuid = me.currentArchiveUuid;
+        if (me.currentNode && me.currentArchiveUuid) {
+            const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
+            CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
+                function(result){
+                    // console.log(result.data);
+                    let hasRemovedAll = false;
+                    for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
+                        if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
+                            for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
+                                if (ARCHIVE_LIST[idx].items[dtIdx].uuid = bkUuid) {
+                                    ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
+                                    break;
+                                }
+                            }
+                            if (ARCHIVE_LIST[idx].items.length === 0) {
+                                ARCHIVE_LIST.splice(idx, 0);
+                                hasRemovedAll = true;
+                                break;
+                            }
+                        }
+                    }
+                    //要刷新当前归档
+                    if (hasRemovedAll) {
+                        const validNode = me._getOneValidLeafNode(me.currentNode);
+                        // me.iniPage();
+                        me.treeObj.removeNode(me.currentNode);
+                        if (validNode) {
+                            me.currentNode = validNode;
+                            me.onClick(null, null, me.currentNode);
+                            me.treeObj.selectNode(me.currentNode, false);
+                        }
+                    } else {
+                        me.currentArchiveUuid = null;
+                        me.currentArchiveDateStr = null;
+                        me.currentArchivePdfPath = null;
+                        me.onClick(null, null, me.currentNode);
+                    }
+                }
+            );
+        }
     }
 };
 
@@ -789,4 +855,13 @@ $(function () {
             alert('请选择打开一个报表!');
         }
     });
+
+    $('#delete_file').click(function () {
+        if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
+            console.log(rptArchiveObj.currentArchivePdfPath);
+            rptArchiveObj.removeArchive();
+        } else {
+            alert('请选择打开一个报表!');
+        }
+    });
 })

+ 10 - 0
app/view/report/index_archive.ejs

@@ -76,6 +76,16 @@
                                     历史归档
                                 </div>
                             </div>
+                            <div class="panel">
+                                <div class="panel-body" id="delete_div">
+                                    <div class="btn-group" role="group">
+                                        <button class="btn btn-outline-primary btn-sm" type="button" id="delete_file">
+                                            <i class="fa fa-remove"></i><br>
+                                            删除归档
+                                        </button>
+                                    </div>
+                                </div>
+                            </div>
                         </div>
                     </div>
                     <div class="print-view form-view">