Просмотр исходного кода

feat: 增加报表模板:重设交叉列数 特性

Tony Kang 10 часов назад
Родитель
Сommit
dc91f090ec

+ 36 - 15
app/reports/rpt_component/jpc_cross_tab.js

@@ -322,7 +322,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
         // console.log('me.row_sum_fields_value_total');
         // console.log(me.row_sum_fields_value_total);
     };
-    JpcCrossTabResult.preSetupPages = function(rptTpl, defProperties, option) {
+    JpcCrossTabResult.preSetupPages = function(rptTpl, defProperties, option, $CURRENT_RPT, dataObj, $CTX_HELPER) {
         const me = this;
         let rst = 0;
         me.paging_option = option || JV.PAGING_OPTION_NORMAL;
@@ -336,10 +336,13 @@ JpcCrossTabSrv.prototype.createNew = function() {
         const pageStatus = [true, true, false, true, false, false, false, false];
         // 2. calculate the page info one by one
         let bands = JpcBand.createNew(rptTpl, defProperties);
-        function private_resetBandArea() {
+        function private_resetBandArea(segIdx) {
             JpcBandHelper.setBandArea(bands, rptTpl, pageStatus);
             maxRowRec = JpcCrossTabHelper.getMaxRowsPerPage(bands, rptTpl);
             maxColRec = JpcCrossTabHelper.getMaxColsPerPage(bands, rptTpl);
+            const $CACHE_OBJ = { newColAmt: maxColRec };
+            me.resetCrossColsEvent(JV.RUN_TYPE_RESET_CROSS_COLUMNS, $CURRENT_RPT, dataObj, segIdx, maxColRec, $CACHE_OBJ, $CTX_HELPER);
+            maxColRec = $CACHE_OBJ.newColAmt;
         }
         JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT][JV.PROP_CROSS_FIELDS], null, me.row_extension_fields_idx);
         JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT][JV.PROP_CROSS_FIELDS], null, me.row_sum_extension_fields_idx);
@@ -367,30 +370,30 @@ JpcCrossTabSrv.prototype.createNew = function() {
         } else {
             for (let segIdx = 0; segIdx < segCnt; segIdx++) {
                 // 2.1. seg level initialize
-                private_resetBandArea();
+                private_resetBandArea(segIdx);
                 const orgMaxRowRec = maxRowRec;
                 const orgMaxColRec = maxColRec;
                 let rowSplitCnt = Math.ceil(1.0 * me.sortedRowSequence[segIdx].length / maxRowRec);
                 let colSplitCnt = Math.ceil(1.0 * me.sortedColSequence[segIdx].length / maxColRec);
                 pageStatus[JV.STATUS_CROSS_ROW_END] = true;
-                private_resetBandArea();
+                private_resetBandArea(segIdx);
                 let hasAdHocRow = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_SUM, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
                 if (hasAdHocRow) {
                     hasAdHocRow = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_EXT, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
                 }
                 pageStatus[JV.STATUS_CROSS_ROW_END] = false;
                 pageStatus[JV.STATUS_CROSS_COL_END] = true;
-                private_resetBandArea();
+                private_resetBandArea(segIdx);
                 const hasAdHocCol = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_COL_SUM, rptTpl, bands, me.sortedColSequence, segIdx, (colSplitCnt - 1) * orgMaxColRec, maxColRec);
                 pageStatus[JV.STATUS_CROSS_COL_END] = false;
-                private_resetBandArea();
+                private_resetBandArea(segIdx);
                 if (hasAdHocRow) rowSplitCnt++;
                 if (hasAdHocCol) colSplitCnt++;
                 // 2.2
                 if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_CROSS_DISPLAY_ORDER] === JV.PAGE_ORIENTATION_H_FIRST) {
                     for (let rowIdx = 0; rowIdx < rowSplitCnt; rowIdx++) {
                         pageStatus[JV.STATUS_CROSS_ROW_END] = (rowIdx === (rowSplitCnt - 1));
-                        private_resetBandArea();
+                        private_resetBandArea(segIdx);
                         counterRowRec = orgMaxRowRec * rowIdx;
                         let currentSortedRowSequence = me.sortedRowSequence;
                         let currentSortedContentSequence = me.sortedContentSequence;
@@ -404,7 +407,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                             let needOneMoreRptEnd = false;
                             if ((segIdx === segCnt - 1) && pageStatus[JV.STATUS_CROSS_ROW_END] && pageStatus[JV.STATUS_CROSS_COL_END]) {
                                 pageStatus[JV.STATUS_REPORT_END] = true;
-                                private_resetBandArea();
+                                private_resetBandArea(segIdx);
                                 const hasAdHocColEnd = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_COL_SUM, rptTpl, bands, me.sortedColSequence, segIdx, (colSplitCnt - 1) * orgMaxColRec, maxColRec);
                                 const hasAdHocRowEnd = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_SUM, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
                                 if (hasAdHocColEnd || hasAdHocRowEnd) {
@@ -412,7 +415,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                                     pageStatus[JV.STATUS_REPORT_END] = false;
                                 }
                             }
-                            private_resetBandArea();
+                            private_resetBandArea(segIdx);
                             counterColRec = orgMaxColRec * colIdx;
                             let currentSortedColSequence = me.sortedColSequence;
                             if (hasAdHocCol && colIdx === (colSplitCnt - 1)) {
@@ -430,7 +433,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                             // 处理report end情况
                             if (needOneMoreRptEnd) {
                                 pageStatus[JV.STATUS_REPORT_END] = true;
-                                private_resetBandArea();
+                                private_resetBandArea(segIdx);
                                 currentSortedColSequence = null;
                                 currentSortedContentSequence = null;
                                 counterColRec = 0;
@@ -447,7 +450,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                 } else {
                     for (let colIdx = 0; colIdx < colSplitCnt; colIdx++) {
                         pageStatus[JV.STATUS_CROSS_COL_END] = (colIdx === (colSplitCnt - 1));
-                        private_resetBandArea();
+                        private_resetBandArea(segIdx);
                         counterColRec = orgMaxColRec * colIdx;
                         let currentSortedContentSequence = me.sortedContentSequence;
                         let currentSortedColSequence = me.sortedColSequence;
@@ -461,7 +464,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                             let needOneMoreRptEnd = false;
                             if ((segIdx === segCnt - 1) && pageStatus[JV.STATUS_CROSS_ROW_END] && pageStatus[JV.STATUS_CROSS_COL_END]) {
                                 pageStatus[JV.STATUS_REPORT_END] = true;
-                                private_resetBandArea();
+                                private_resetBandArea(segIdx);
                                 const hasAdHocColEnd = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_COL_SUM, rptTpl, bands, me.sortedColSequence, segIdx, (colSplitCnt - 1) * orgMaxColRec, maxColRec);
                                 const hasAdHocRowEnd = !JpcCrossTabHelper.chkTabEnd(JV.NODE_CROSS_ROW_SUM, rptTpl, bands, me.sortedRowSequence, segIdx, (rowSplitCnt - 1) * orgMaxRowRec, maxRowRec);
                                 if (hasAdHocColEnd || hasAdHocRowEnd) {
@@ -469,7 +472,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                                     pageStatus[JV.STATUS_REPORT_END] = false;
                                 }
                             }
-                            private_resetBandArea();
+                            private_resetBandArea(segIdx);
                             me.pageStatusLst.push(pageStatus.slice(0));
                             pageIdx++;
                             counterRowRec = orgMaxRowRec * rowIdx;
@@ -487,7 +490,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
                             // 处理report end情况
                             if (needOneMoreRptEnd) {
                                 pageStatus[JV.STATUS_REPORT_END] = true;
-                                private_resetBandArea();
+                                private_resetBandArea(segIdx);
                                 currentSortedRowSequence = null;
                                 currentSortedContentSequence = null;
                                 counterRowRec = 0;
@@ -594,7 +597,7 @@ JpcCrossTabSrv.prototype.createNew = function() {
         }
         return rst;
     };
-    JpcCrossTabResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, page, bands, controls, fonts, $CURRENT_RPT, customizeCfg) {
+    JpcCrossTabResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, page, bands, controls, fonts, $CURRENT_RPT, customizeCfg, $CTX_HELPER) {
         const me = this;
         let rst = [];
         const tabRstLst = [];
@@ -675,6 +678,24 @@ JpcCrossTabSrv.prototype.createNew = function() {
             }
         }
     };
+    JpcCrossTabResult.resetCrossColsEvent = function($RUN_TYPE, $CURRENT_RPT, $CURRENT_DATA, $SEG_IDX, $ORG_COLS, $CACHE_OBJ, $CTX_HELPER) {
+        if ($CURRENT_RPT.formulas) {
+            for (let execFmlIdx = 0; execFmlIdx < $CURRENT_RPT.formulas.length; execFmlIdx++) {
+                if ($CURRENT_RPT.formulas[execFmlIdx][JV.PROP_RUN_TYPE] === $RUN_TYPE) {
+                    const expression = $CURRENT_RPT.formulas[execFmlIdx][JV.PROP_EXPRESSION];
+                    if (expression) {
+                        const $ME = $CURRENT_RPT.formulas[execFmlIdx];
+                        const $JE = JE;
+                        try {
+                            eval(expression);
+                        } catch (ex) {
+                            console.log(ex);
+                        }
+                    }
+                }
+            }
+        }
+    };
     JpcCrossTabResult.outputRowTabCommon = function(rptTpl, dataObj, page, bands, tabStr, rowFieldsIdxArr, unitFactor, controls, $CURRENT_RPT, customizeCfg) {
         const me = this;
         const rst = [];

+ 6 - 6
app/reports/rpt_component/jpc_ex.js

@@ -216,12 +216,12 @@ JpcExSrv.prototype.createNew = function() {
             me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_PAGING, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties);
         }
         // 4. paging
-        me.paging(rptTpl, dataObj, defProperties, dftPagingOption, outputType);
+        me.paging(rptTpl, dataObj, defProperties, dftPagingOption, outputType, $CTX_HELPER);
         // alert('analyzeData was completed!');
         // for garbage collection:
         dataHelper = null;
     };
-    JpcResult.paging = function(rptTpl, dataObj, defProperties, option, outputType) {
+    JpcResult.paging = function(rptTpl, dataObj, defProperties, option, outputType, $CTX_HELPER) {
         const me = this;
         const dftPagingOption = option || JV.PAGING_OPTION_NORMAL;
         if (me.flowTab) {
@@ -237,7 +237,7 @@ JpcExSrv.prototype.createNew = function() {
             }
         } else if (me.crossTab) {
             // me.totalPages = me.crossTab.preSetupPages(rptTpl, defProperties, dftPagingOption);
-            me.totalPages = me.crossTab.preSetupPages(rptTpl, defProperties, JV.PAGING_OPTION_NORMAL); // infinity对交叉表来说无意义
+            me.totalPages = me.crossTab.preSetupPages(rptTpl, defProperties, JV.PAGING_OPTION_NORMAL, me, dataObj, $CTX_HELPER); // infinity对交叉表来说无意义
         } else if (me.billTab) {
             me.totalPages = me.billTab.paging(rptTpl, dataObj);
         }
@@ -371,7 +371,7 @@ JpcExSrv.prototype.createNew = function() {
                 for (let page = startPage; page <= endPage; page++) {
                     me.runTimePageData.currentPage = page;
                     me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_OUTPUT, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties);
-                    rst.items.push(me.outputAsSimpleJSONPage(rptTpl, dataObj, bands, page, rst[JV.NODE_CONTROL_COLLECTION], rst[JV.NODE_FONT_COLLECTION], customizeCfg));
+                    rst.items.push(me.outputAsSimpleJSONPage(rptTpl, dataObj, bands, page, rst[JV.NODE_CONTROL_COLLECTION], rst[JV.NODE_FONT_COLLECTION], customizeCfg, $CTX_HELPER));
                 }
                 if (bands[JV.BAND_PROP_MERGE_BAND]) {
                     const mergedBand = {};
@@ -391,7 +391,7 @@ JpcExSrv.prototype.createNew = function() {
         }
         return rst;
     };
-    JpcResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, bands, page, controls, fonts, customizeCfg) {
+    JpcResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, bands, page, controls, fonts, customizeCfg, $CTX_HELPER) {
         const me = this;
         let rst = null;
         function getPageMergeBorder() {
@@ -441,7 +441,7 @@ JpcExSrv.prototype.createNew = function() {
                     }
                 }
             } else if (me.crossTab) {
-                rst[JV.PROP_CELLS] = me.crossTab.outputAsSimpleJSONPage(rptTpl, dataObj, page, bands, controls, fonts, me, customizeCfg);
+                rst[JV.PROP_CELLS] = me.crossTab.outputAsSimpleJSONPage(rptTpl, dataObj, page, bands, controls, fonts, me, customizeCfg, $CTX_HELPER);
                 rst[JV.PROP_SIGNATURE_CELLS] = me.crossTab.signatureRst;
                 rst[JV.PROP_SIGNATURE_DATE_CELLS] = me.crossTab.signatureDateRst;
                 rst[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.crossTab.signatureAuditRst;

+ 3 - 1
app/reports/rpt_component/jpc_field.js

@@ -50,7 +50,9 @@ const JpcField = {
         return JpcFieldResult;
     },
     createSingle(fieldNode, parentObj, rptTpl, dataNodeName, sequence) {
-        if (fieldNode && fieldNode[JV.PROP_ID]) {
+        if (fieldNode) {
+            // 考虑到实际应用真的有指标不给ID,在jpc_rte增加了以指标名称查询的方法
+        // if (fieldNode && fieldNode[JV.PROP_ID]) {
             const item = {};
             item[JV.PROP_ID] = fieldNode[JV.PROP_ID];
             item[JV.PROP_NAME] = fieldNode[JV.PROP_NAME];

+ 23 - 0
app/reports/rpt_component/jpc_rte.js

@@ -30,6 +30,29 @@ const JE = {
         }
         return rst;
     },
+    F_NAME(fNAME, $CURRENT_RPT) {
+        // 临时顶用方法,通过名称找指标
+        const getFieldFrom = fCollections => {
+            let fRst = null;
+            if (fCollections) {
+                for (const prop in fCollections) {
+                    if (fCollections[prop] && fCollections[prop].Name === fNAME) {
+                        fRst = fCollections[prop];
+                        break;
+                    }
+                }
+            }
+            return fRst;
+        };
+        let rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_DETAIL_FIELDS]);
+        if (!rst) rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_MASTER_FIELDS]);
+        if (!rst) rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_DETAIL_FIELDS_EX]);
+        if (!rst) rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_DISCRETE_FIELDS]);
+        if (!rst) rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_NO_MAPPING_FIELDS]);
+        if (!rst) rst = getFieldFrom($CURRENT_RPT.fields[JV.NODE_SIGNATURE_FIELDS]);
+        if (!rst) rst = { msg: 'the Field-ID is not valid, no result could be found!' };
+        return rst;
+    },
     P(pID, $CURRENT_RPT) {
         let rst = null;
         if ($CURRENT_RPT && ($CURRENT_RPT.params[JV.PROP_ID + '_' + pID])) {

+ 2 - 0
app/reports/rpt_component/jpc_value_define.js

@@ -232,6 +232,8 @@ module.exports = {
 
     RUN_TYPE_BEFORE_GROUP_TEXT_OUT: 'before_group_text_output',
 
+    RUN_TYPE_RESET_CROSS_COLUMNS: 'reset_cross_columns',
+
     SIGNATURE_NAME_DUMMY: 'dummy_pic',
     SIGNATURE_NAME_DUMMY_WATER_MARK: 'dummy_pic_warter_mark',