瀏覽代碼

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

MaiXinRong 4 年之前
父節點
當前提交
cbc3483e43

+ 1 - 1
app/const/sign.js

@@ -10,7 +10,7 @@
 
 const path = {
     oss: 'https://measure-sign-pdf.oss-cn-shenzhen.aliyuncs.com/archive',
-    api: 'http://124.71.15.76:9091/eseal',
+    api: 'http://14.18.158.147:9091/eseal',
 };
 
 

+ 25 - 10
app/controller/report_archive_controller.js

@@ -490,7 +490,7 @@ module.exports = app => {
                         const postData = {
                             requestJson: JSON.stringify(data.requestJson),
                         };
-                        const result = await ctx.helper.sendRequest(netcaSignApi + '/assemblyDigest', postData, 'POST');
+                        const result = await ctx.helper.sendMoreRequest(netcaSignApi + '/assemblyDigest', postData, 'POST');
                         response.data = result;
                         break;
                     // 生成签名pdf
@@ -498,22 +498,37 @@ module.exports = app => {
                         const postData2 = {
                             requestJson: JSON.stringify(data.requestJson),
                         };
-                        const result2 = await ctx.helper.sendRequest(netcaSignApi + '/assemblyPdf', postData2, 'POST');
+                        const result2 = await ctx.helper.sendMoreRequest(netcaSignApi + '/assemblyPdf', postData2, 'POST');
+                        console.log(result2);
                         // 上传到oss
                         if (result2.code === 0) {
-                            const result3 = await ctx.curl(netcaSignApi + result2.data);
-                            const oss_reuslt = await ctx.oss.put('archive/sign/' + data.requestJson.fileName + '.PDF', result3.data);
+                            const result3 = await ctx.helper.sendMoreRequest(netcaSignApi + result2.data);
+                            const oss_reuslt = await ctx.oss.put('archive/sign/' + data.requestJson.fileName + '.PDF', result3);
                             if (oss_reuslt && oss_reuslt.res && oss_reuslt.res.status === 200) {
-                                const versionId = oss_reuslt.res.headers['x-oss-version-id'];
-                                // 记录签名和保存
-                                await ctx.service.netcasignLog.add(data.requestJson.fileName, data.role, ctx.session.sessionUser.accountId, versionId);
-                                const signLogList = await ctx.service.netcasignLog.getLogList(ctx.tender.id);
-                                response.data = signLogList;
+                                if (data.end) {
+                                    const versionId = oss_reuslt.res.headers['x-oss-version-id'];
+                                    // 记录签名和保存
+                                    await ctx.service.netcasignLog.add(data.requestJson.fileName, data.role, ctx.session.sessionUser.accountId, versionId);
+                                    const signLogList = await ctx.service.netcasignLog.getLogList(ctx.tender.id);
+                                    response.data = signLogList;
+                                } else {
+                                    // next page
+                                }
                             } else {
                                 throw '上传文件失败';
                             }
                         }
-
+                        break;
+                    // 移除签名和已签移除pdf
+                    case 'removeSign':
+                        const oss_reuslt = await ctx.oss.delete('archive/sign/' + data.uuid + '.PDF');
+                        if (oss_reuslt && oss_reuslt.res && oss_reuslt.res.status === 204) {
+                            const delSign_result = await ctx.service.netcasignLog.removeSign(ctx.session.sessionUser.accountId, data.uuid);
+                            const signLogList = await ctx.service.netcasignLog.getLogList(ctx.tender.id);
+                            response.data = signLogList;
+                        } else {
+                            throw '删除文件失败';
+                        }
                         break;
                     default:throw '参数有误';
                 }

+ 33 - 0
app/extend/helper.js

@@ -262,6 +262,39 @@ module.exports = {
     },
 
     /**
+     * 模拟多次发送请求(失败后再获取)
+     *
+     * @param {String} url - 请求地址
+     * @param {Object} data - 失败请求次数
+     * @param {String} type - 请求类型(POST) POST | GET
+     * @param {String} dataType - 数据类型 json|text
+     * @param {String} count - 重复次数
+     * @return {Object} - 请求结果
+     */
+    async sendMoreRequest(url, data = null, type = 'POST', dataType = 'json', count = 3) {
+        // 发起请求
+        try {
+            let response = data ? await this.ctx.curl(url, {
+                method: type,
+                data,
+                dataType,
+            }) : await this.ctx.curl(url);
+            console.log(response);
+            if (response.status !== 200) {
+                if (count > 0) {
+                    count = count - 1;
+                    response = await this.sendMoreRequest(url, data, type, dataType, count);
+                } else {
+                    throw '请求失败';
+                }
+            }
+            return response.data;
+        } catch (err) {
+            throw '请求失败';
+        }
+    },
+
+    /**
      * 深度验证数据
      *
      * @param {Object} rule - 数据规则

+ 20 - 5
app/public/report/js/rpt_archive.js

@@ -128,6 +128,7 @@ let rptArchiveObj = {
             try {
                 if (can_netcasign) {
                     const msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
+                    console.log(msgSign, me.currentArchiveUuid);
                     me.currentEncryptionList = msgSign;
                     const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
                     let html = '';
@@ -154,8 +155,15 @@ let rptArchiveObj = {
                     $('#role-list').html(html);
                     $('#page-list').html(pagetr);
                     $('#sign_num').text(uSignLogList.length);
+                    const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
+                    // 是否显示撤销按钮
+                    if(uHadSign && uHadSign.length > 0) {
+                        $('#show-removesign-modal-btn').show();
+                    } else {
+                        $('#show-removesign-modal-btn').hide();
+                    }
                     postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
-                        me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
+                        me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' + (uSignLogList.length !== 0 ? '?' + uSignLogList.length : '') : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
                         $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
                     }, function () {
                         me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF';
@@ -182,7 +190,8 @@ let rptArchiveObj = {
         me.currentArchiveDateStr = dom.innerHTML;
         if(can_netcasign) {
             postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
-                me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
+                const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
+                me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' + (uSignLogList.length !== 0 ? '?' + uSignLogList.length : '') : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
                 $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
                 me._buildeArchiveDateSelect();
             }, function () {
@@ -196,7 +205,6 @@ let rptArchiveObj = {
             $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
             me._buildeArchiveDateSelect();
         }
-
     },
 
     _buildeArchiveDateSelect: function () {
@@ -241,10 +249,17 @@ let rptArchiveObj = {
         }
         $('#page-list').html(pagetr);
         if (needFrame) {
-            me.currentArchivePdfPath = oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF';
-            $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
+            me.currentArchivePdfPath = uSignLogList.length > 0 ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
+            $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + (uSignLogList.length !== 0 ? '?' + uSignLogList.length : '') + '" height="750px" width="100%" style="border: none;"></iframe>');
         }
         $('#sign_num').text(uSignLogList.length);
+        const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
+        // 是否显示撤销按钮
+        if(uHadSign && uHadSign.length > 0) {
+            $('#show-removesign-modal-btn').show();
+        } else {
+            $('#show-removesign-modal-btn').hide();
+        }
     },
 
     _countChkedRptTpl: function () {

+ 4 - 0
app/service/netcasign_log.js

@@ -41,6 +41,10 @@ module.exports = app => {
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid];
             return await this.db.query(sql, sqlParam);
         }
+
+        async removeSign(uid, uuid) {
+            return await this.db.delete(this.tableName, { uid, uuid });
+        }
     }
 
     return NetcasignLog;

+ 0 - 2
app/service/project_account.js

@@ -248,8 +248,6 @@ module.exports = app => {
 
         async getPageShow(page_show) {
             const info = page_show ? JSON.parse(page_show) : {};
-            console.log(info);
-            console.log(pageShowConst);
             for (const pi in pageShowConst) {
                 info[pi] = !info[pi] || info[pi] === '' ? pageShowConst[pi] : parseInt(info[pi]);
                 this.ctx.helper._.defaults(info[pi], pageShowConst[pi]);

+ 44 - 14
app/view/report/index_sign.ejs

@@ -171,6 +171,8 @@
     const PROJECT_ID = <%- project_id %>;
     const TENDER_ID = <%- tender_id %>;
     const STAGE_ID = <%- stg_id %>;
+    const USER_ID = <%- ctx.session.sessionUser.accountId %>;
+    const USER_NAME = '<%- ctx.session.sessionUser.name %>';
     const STAGE_ORDER = <%- stg_order %>;
     const STAGE_LIST = <%- stage_list %>;
     const can_netcasign = <%- can_netcasign %>;
@@ -353,6 +355,7 @@
 
             const _self = $(this);
             const params={};
+            let curr_sign_page = 1;
             NetcaPKI.GetCertList(params)
                 .Then(function(res){
                     if (res && res.deviceCount === 0) {
@@ -384,13 +387,14 @@
                             } else {
                                 // 开始签名!
                                 const encrypt = rptArchiveObj.currentEncryptionList.encryption[val];
+                                console.log(encrypt);
                                 const requestJson = {
                                     width: encrypt.areas[0].width,
                                     height: encrypt.areas[0].height,
-                                    x: encrypt.areas[0].Top,
-                                    y: encrypt.areas[0].Left,
-                                    page: rptArchiveObj.currentEncryptionList.total_page ? rptArchiveObj.currentEncryptionList.total_page : 1,
-                                    // page: 0,
+                                    x: encrypt.areas[0].Left*0.75,
+                                    y: encrypt.areas[0].Top*0.75,
+                                    // page: rptArchiveObj.currentEncryptionList.total_page ? rptArchiveObj.currentEncryptionList.total_page : 1,
+                                    page: curr_sign_page,
                                     // url: 'https://measure-sign-pdf.oss-cn-shenzhen.aliyuncs.com/archive/'+ rptArchiveObj.currentArchiveUuid + '.PDF',
                                     url: rptArchiveObj.currentArchivePdfPath,
                                     hashAlgo: 'SHA256',
@@ -398,11 +402,12 @@
                                     imageBase64: netcaSignData.sign_base64,
                                     certContent: res.certCode,
                                 }
+                                console.log(requestJson);
                                 // 先获取摘要值
                                 postData('/tender/'+ TENDER_ID +'/signReport/post', { type: 'assemblyDigest', requestJson}, function (result) {
                                     if(result.code === 0) {
                                         signDigest = result.data;
-                                        signPdf();
+                                        signPdf(res);
                                     } else {
                                         failedCallBack(result);
                                     }
@@ -413,7 +418,7 @@
                                 })
                             }
                         }
-                        function signPdf() {
+                        function signPdf(res) {
                             const certEncode = "";
                             const tbs = utf8_to_b64(signDigest);
                             const _tsaURL = "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp";
@@ -433,9 +438,10 @@
                                 tsaURL: _tsaURL,
                                 includeCertOption: _includeCertOption//整数	包含证书的标识
                             };
+                            const curr_res = res;
                             NetcaPKI.signedDataSign(params)
                                 .Then(function (res) {
-                                    _self.text('签名中...');
+                                    _self.text('签名中,请勿关闭本页...');
                                     let retSignValue = res.signValue;
 
                                     //处理base填充问题,这里去掉Base64的填充内容
@@ -473,14 +479,28 @@
                                         p7Base64: retSignValue,
                                     }
                                     const encrypt = rptArchiveObj.currentEncryptionList.encryption[val];
+                                    // rptArchiveObj.currentEncryptionList.total_page = rptArchiveObj.currentEncryptionList.total_page ? rptArchiveObj.currentEncryptionList.total_page : 1;
+                                    const end = rptArchiveObj.currentEncryptionList.total_page === curr_sign_page;
                                     // 生成pdf
-                                    postData('/tender/'+ TENDER_ID +'/signReport/post', { type: 'assemblyPdf', requestJson: rJson, role: encrypt.name }, function (result) {
-                                        toastr.success("已成功签名");
-                                        signLogList = result;
-                                        rptArchiveObj._updateSignHtmlAndFrame(true);
-                                        $('#sign').modal('hide');
-                                        _self.attr('disabled', false);
-                                        _self.text('确定');
+                                    postData('/tender/'+ TENDER_ID +'/signReport/post', { type: 'assemblyPdf', requestJson: rJson, role: encrypt.name, end }, function (result) {
+                                        if (end) {
+                                            toastr.success("已成功签名");
+                                            signLogList = result;
+                                            signDigest = '';
+                                            rptArchiveObj._updateSignHtmlAndFrame(true);
+                                            $('#sign').modal('hide');
+                                            _self.attr('disabled', false);
+                                            _self.text('确定');
+                                        } else {
+                                            signDigest = '';
+                                            rptArchiveObj.currentArchivePdfPath = oss_path + '/sign/'+ rptArchiveObj.currentArchiveUuid +'.PDF';
+                                            let uhtml = ' <span class="text-success"><i class="fa fa-check"></i> '+ encrypt.name +'('+ USER_NAME +')</span>';
+                                            $('#page-list tr').eq(curr_sign_page - 1).children('td').eq(2).append(uhtml);
+                                            ++curr_sign_page;
+                                            setTimeout(function () {
+                                                successGetCertEncodeCallBack(curr_res);
+                                            }, 3000);
+                                        }
                                     }, function () {
                                         _self.attr('disabled', false);
                                         _self.text('确定');
@@ -516,6 +536,16 @@
                     return false;
                 });
         })
+
+        $('#sign-remove').click(function () {
+            // 移除签名并更新
+            postData('/tender/'+ TENDER_ID +'/signReport/post', { type: 'removeSign', uuid: rptArchiveObj.currentArchiveUuid }, function (result) {
+                signLogList = result;
+                rptArchiveObj._updateSignHtmlAndFrame(true);
+                $('#sign2').modal('hide');
+            }, function () {
+            })
+        })
     })
 
     rptArchiveObj.iniPage();

+ 22 - 1
app/view/report/index_sign_modal.ejs

@@ -54,7 +54,7 @@
                 </div>
             </div>
             <div class="modal-footer">
-                <!--<a href="" class="btn btn-sm btn-danger mr-5" data-toggle="modal" data-target="#sign2" data-dismiss="modal">撤销签名</a>-->
+                <a href="javascript:void(0)" style="display: none" id="show-removesign-modal-btn" class="btn btn-sm btn-danger mr-5" data-toggle="modal" data-target="#sign2" data-dismiss="modal">撤销签名</a>
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
                 <button type="button" id="sign_pdf" class="btn btn-sm btn-primary">确定</button>
             </div>
@@ -102,3 +102,24 @@
         </form>
     </div>
 </div>
+<!--弹出批量电子签名-->
+<div class="modal fade" id="sign2" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">撤销签名</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <p>撤销签名,可以重新选择签名归档版本;</p>
+                <p>撤销签名,所有签名都需要重新签名,请谨慎操作。</p>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                <button id="sign-remove" class="btn btn-sm btn-danger">确定撤销</button>
+            </div>
+        </div>
+    </div>
+</div>