Преглед изворни кода

导出pdf乱码问题 + 内存表加字段key参数

TonyKang пре 5 година
родитељ
комит
0c51d6e283

+ 18 - 3
app/controller/report_controller.js

@@ -312,12 +312,14 @@ async function checkStg(ctx, params) {
         }
     }
 }
-async function getReportData(ctx, params, filters) {
+async function getReportData(ctx, params, filters, memFieldKeys) {
     const rst = {};
     const runnableRst = [];
     const runnableKey = []; // 这个配合runnableRst用,未来考虑并行查询优化
     // console.log('params');
     // console.log(params);
+    console.log('memFieldKeys');
+    console.log(memFieldKeys);
     for (const filter of filters) {
         if (runnableKey.indexOf(filter) < 0) {
             switch (filter) {
@@ -352,6 +354,7 @@ async function getReportData(ctx, params, filters) {
                     runnableKey.push('stage_pay');
                     break;
                 case 'mem_stage_im_zl':
+                    // memFieldKeys[filter]
                     runnableRst.push(ctx.service.reportMemory.getStageImZlData(params.tender_id, params.stage_id));
                     runnableKey.push('mem_stage_im_zl');
                     break;
@@ -398,7 +401,7 @@ async function getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDi
     // console.log(rptTpl);
     const filter = rptDataUtil.getDataRequestFilter();
     // console.log(filter.tables);
-    const rawDataObj = await getReportData(ctx, params, filter.tables);
+    const rawDataObj = await getReportData(ctx, params, filter.tables, filter.memFieldKeys);
     // console.log(rawDataObj);
     try {
         // console.log('before assemble');
@@ -450,6 +453,7 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
     }
     const rptDataUtil = new rptDataExtractor();
     const filterTables = [];
+    const memFieldKeys = {};
     if (rptTpls.length > 1) {
         rptTpls.sort(function(item1, item2) {
             const i1 = (item1._doc) ? item1._doc : item1;
@@ -467,10 +471,21 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
             if (filterTables.indexOf(table) < 0) {
                 filterTables.push(table);
             }
+            // memFieldKeys[table] = [];
+        }
+        for (const tableKeyProp in filter.memFieldKeys) {
+            if (!memFieldKeys.hasOwnProperty(tableKeyProp)) {
+                memFieldKeys[tableKeyProp] = [];
+            }
+            for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
+                if (memFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
+                    memFieldKeys[tableKeyProp].push(mfKey);
+                }
+            }
         }
     }
 
-    const rawDataObj = await getReportData(ctx, params, filterTables);
+    const rawDataObj = await getReportData(ctx, params, filterTables, memFieldKeys);
     try {
         const rptPageRstArray = [];
         // 1. 这里只用一份数据,根据实际应用情况,先备份

Разлика између датотеке није приказан због своје велике величине
+ 127 - 1
app/public/js/global.js


+ 12 - 10
app/public/report/js/rpt_main.js

@@ -539,17 +539,15 @@ let rptControlObj = {
     },
     getPDFPre: function () {
         let me = rptControlObj;
-        // $.bootstrapLoading.start();
+        // showWaitingView();
+        $.bootstrapLoading.start();
         if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
             me.getPDFEx();
         } else {
-            // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js');
-            // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', me.pdfFontSimsunCallBack);
-
             dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
             dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
-            // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', me.getPdfFontCallback('normal'));
-            // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', me.getPdfFontCallback('bold'));
+            // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', "normal", me.getPdfFontCallback('normal'));
+            // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', "normal", me.getPdfFontCallback('bold'));
         }
     },
     getPDFEx: function () {
@@ -564,7 +562,8 @@ let rptControlObj = {
                 delete params.orientation; // 打印时有勾选的话,不需要提供方向
                 CommonAjax.postXsrfEx("/tender/report_api/getMultiReports", params, 60000, true, getCookie('csrfToken'),
                     function(result){
-                        // $.bootstrapLoading.end();
+                        // closeWaitingView();
+                        $.bootstrapLoading.end();
                         let pageSize = rptControlObj.getCurrentPageSize();
                         for (const signatureRel of result.signatureRelInfo) {
                             signatureRelArr.push(JSON.parse(signatureRel.rel_content));
@@ -575,11 +574,13 @@ let rptControlObj = {
                         }
                     },
                     function(failRst){
-                        // $.bootstrapLoading.end();
+                        // closeWaitingView();
+                        $.bootstrapLoading.end();
                         console.log(failRst);
                     },
                     function(exceptionRst){
-                        // $.bootstrapLoading.end();
+                        // closeWaitingView();
+                        $.bootstrapLoading.end();
                         console.log(exceptionRst);
                     }
                 );
@@ -588,7 +589,8 @@ let rptControlObj = {
                 let pageSize = rptControlObj.getCurrentPageSize();
                 let pageData = zTreeOprObj.currentRptPageRst;
                 signatureRelArr.push(ROLE_REL_LIST);
-                // $.bootstrapLoading.end();
+                // closeWaitingView();
+                $.bootstrapLoading.end();
                 JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[0], signatureRelArr);
             }
         }

+ 17 - 1
app/reports/util/rpt_calculation_data_util.js

@@ -135,14 +135,29 @@ class Rpt_Data_Extractor {
     // 根据报表模板映射指标(非离散指标)的定义,罗列出所有需要用到的data对象key,作为数据请求的过滤依据
     getDataRequestFilter() {
         const rst = {};
+        const memFieldKeys = {}; // 内存表优化用,需要获得相关内存表的指标请求,因为有些额外指标需要花资源去获得
         const tables = []; // 记录需要查询哪些表
         // const filters = []; // 记录过滤条件(预处理中的过滤),目前先不处理
         const tpl = this.rptTpl;
+        const pri_func_split_mem_fieldKey = function(field) {
+            // 计量需要获取所有内存表指标的key,优化用
+            if (memFieldKeys[field.TableName] === undefined) {
+                memFieldKeys[field.TableName] = [];
+            }
+            const strs = field[JV.PROP_FIELD_EXP_MAP].split("', '");
+            if (strs.length === 2) {
+                const codeKey = strs[1].slice(0, strs[1].indexOf("'"));
+                if (field.TableName.indexOf('mem_') === 0 && memFieldKeys[field.TableName].indexOf(codeKey) < 0) {
+                    memFieldKeys[field.TableName].push(codeKey);
+                }
+            }
+        };
         const pri_func_chk_filter = function(field) {
             // 计量的机制有所不同,数据分开保存在不同的表里,
             if (field.TableName && tables.indexOf(field.TableName) < 0) {
                 tables.push(field.TableName);
             }
+            pri_func_split_mem_fieldKey(field);
         };
         const pri_setup_filter = function(FIELD_LIST_KEY) {
             // console.log(tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]);
@@ -169,6 +184,7 @@ class Rpt_Data_Extractor {
             }
         }
         rst.tables = tables;
+        rst.memFieldKeys = memFieldKeys;
         return rst;
     }
 
@@ -223,7 +239,7 @@ class Rpt_Data_Extractor {
         assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS_EX], rptDataObj[JV.DATA_DETAIL_DATA_EX], $PROJECT);
         // console.log(JV.DATA_DETAIL_DATA_EX);
         // console.log(rptDataObj[JV.DATA_DETAIL_DATA_EX]);
-        // fsUtil.writeObjToFile(rptDataObj, 'D:/GitHome/temp/insertedOriginalData.jsp');
+        fsUtil.writeObjToFile(rptDataObj, 'D:/GitHome/temp/insertedOriginalData.jsp');
         // fsUtil.writeObjToFile(rawDataObj, 'D:/GitHome/temp/insertedRawDataData.jsp');
         // fsUtil.writeObjToFile($PROJECT, 'D:/GitHome/temp/$PROJECTData.jsp');
         // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], 'D:/GitHome/temp/masterFieldsAfterAssemble.jsp');

+ 1 - 1
app/view/report/index.ejs

@@ -48,7 +48,7 @@
                                     <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                                         <button type="button" class="btn btn-outline-primary btn-sm" onclick="rptControlObj.checkAndGetExcel()"><i class="fa fa-file-excel-o"></i> Excel <span class="badge badge-secondary">0</span></button>
                                         <button type="button" class="btn btn-outline-primary btn-sm" id="show_excel_output_cfg" data-toggle="modal" data-target="#export_excel" style="display:none"></button>
-                                        <button type="button" class="btn btn-outline-primary btn-sm" onclick="rptControlObj.getPDFEx()"><i class="fa fa-file-pdf-o"></i> PDF <span class="badge badge-primary">0</span></button>
+                                        <button type="button" class="btn btn-outline-primary btn-sm" onclick="rptControlObj.getPDFPre()"><i class="fa fa-file-pdf-o"></i> PDF <span class="badge badge-primary">0</span></button>
                                     </div>
                                 </div>
                                 <div class="panel-foot text-muted">