TonyKang 7 éve
szülő
commit
505d89e1b7

+ 30 - 1
modules/reports/controllers/rpt_controller.js

@@ -92,7 +92,7 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, option, cb) {
                     let maxPages = printCom.totalPages;
                     let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
                     if (pageRst) {
-                        //fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.js");
+                        //fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
                         cb(null, pageRst);
                     } else {
                         cb('Have errors while on going...', null);
@@ -108,7 +108,36 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, option, cb) {
     })
 }
 
+function getPreViewPage(rpt_id, pageSize, cb) {
+    let rptTpl = null;
+    rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
+        rptTpl = rst;
+        if (rptTpl) {
+            let printCom = JpcEx.createNew();
+            let defProperties = rptUtil.getReportDefaultCache();
+            rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
+            printCom.initialize(rptTpl);
+            let pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
+            if (pageRst) {
+                //fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/previewPageResult.jsp");
+                cb(null, pageRst);
+            } else {
+                cb('Have errors while on going...', null);
+            }
+        } else {
+            cb('No report template was found!', null);
+        }
+    });
+}
+
 module.exports = {
+    getPreviewPage: function(req, res) {
+        let rpt_id = params.rpt_tpl_id,
+            pageSize = params.pageSize;
+        getPreViewPage(rpt_id, pageSize, function (err, pageRst) {
+            callback(req, res, err, pageRst);
+        });
+    },
     getReportAllPages: function (req, res) {
         let params = JSON.parse(req.body.params),
             rpt_id = params.rpt_tpl_id,

+ 22 - 4
modules/reports/rpt_component/helper/jpc_helper_discrete.js

@@ -10,7 +10,7 @@ let JpcDiscreteHelper = {
         if (discreteArray && dataObj) {
             for (let i = 0; i < discreteArray.length; i++) {
                 let band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
-                if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] == true) {
+                if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
                     if (discreteArray[i][JV.PROP_TEXT]) {
                         rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx));
                     }
@@ -25,7 +25,7 @@ let JpcDiscreteHelper = {
                             let value = "";
                             if (df[JV.PROP_FIELD_ID]) {
                                 let field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
-                                if (field.DataSeq != JV.BLANK_FIELD_INDEX) {
+                                if (field.DataSeq !== JV.BLANK_FIELD_INDEX) {
                                     let data = dataObj[field.DataNodeName][field.DataSeq];
                                     if (data && data.length > 0) {
                                         if (data.length > segIdx) {
@@ -35,8 +35,9 @@ let JpcDiscreteHelper = {
                                         }
                                     }
                                 } else {
-                                    if (field[JV.PROP_AD_HOC_DATA] && field[JV.PROP_AD_HOC_DATA].length > 0) value = field[JV.PROP_AD_HOC_DATA][0]
-                                    else value = "";
+                                    if (field[JV.PROP_AD_HOC_DATA] && field[JV.PROP_AD_HOC_DATA].length > 0) {
+                                        value = field[JV.PROP_AD_HOC_DATA][0]
+                                    } else value = "";
                                 }
                             } else if (df[JV.PROP_PARAM_ID]) {
                                 let param = JE.P(df[JV.PROP_PARAM_ID], $CURRENT_RPT);
@@ -52,6 +53,23 @@ let JpcDiscreteHelper = {
             }
         }
         return rst;
+    },
+    outputPreviewDiscreteInfo: function (discreteArray, bands, unitFactor, pageStatus) {
+        let rst = [];
+        for (let i = 0; i < discreteArray.length; i++) {
+            let band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
+            if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
+                if (discreteArray[i][JV.PROP_TEXT]) {
+                    rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                }
+                if (discreteArray[i][JV.PROP_TEXTS]) {
+                    for (let j = 0; j < discreteArray[i][JV.PROP_TEXTS].length; j++) {
+                        rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                    }
+                }
+            }
+        }
+        return rst;
     }
 }
 

+ 26 - 0
modules/reports/rpt_component/jpc_bill_tab.js

@@ -40,6 +40,32 @@ JpcBillTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
+    JpcBillTabResult.outputAsPreviewPage = function (rptTpl, bands, controls, $CURRENT_RPT) {
+        let me = this, rst = [], vIdx = [];
+        //只预览第一页的数据
+        let pageStatus = [true, true, false, true, false, false, false, false];
+        JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
+        let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
+        let tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];
+        let band = bands[tab[JV.PROP_BAND_NAME]];
+        if (band) {
+            if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
+                if (tab[JV.PROP_TEXT]) {
+                    rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                }
+                if (tab[JV.PROP_TEXTS]) {
+                    for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
+                        rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
+                    }
+                }
+                if (tab[JV.NODE_DISCRETE_INFO]) {
+                    rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus, page - 1, 1, 0));
+                }
+            }
+        }
+        rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
+        return rst;
+    };
     JpcBillTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, $CURRENT_RPT) {
         let me = this, rst = [], tabRstLst = [];
         //1 calculate the band position

+ 5 - 0
modules/reports/rpt_component/jpc_cross_tab.js

@@ -320,6 +320,11 @@ JpcCrossTabSrv.prototype.createNew = function(){
         bands = null;
         return rst;
     };
+    JpcCrossTabResult.outputAsPreviewPage = function (rptTpl, bands, controls, $CURRENT_RPT) {
+        let me = this, rst = [];
+        //...
+        return rst;
+    };
     JpcCrossTabResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, page, bands, controls, $CURRENT_RPT) {
         let me = this, rst = [], tabRstLst = [];
         let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);

+ 40 - 0
modules/reports/rpt_component/jpc_ex.js

@@ -227,6 +227,46 @@ JpcExSrv.prototype.createNew = function(){
             }
         }
     };
+    JpcResult.outputAsPreviewPage= function(rptTpl, defProperties) {
+        let me = this, rst = {};
+        rst[JV.NODE_CONTROL_COLLECTION] = private_buildDftControls(rptTpl, (defProperties === null)?null:defProperties.ctrls);
+        rst[JV.NODE_STYLE_COLLECTION] = private_buildDftStyles(rptTpl, (defProperties === null)?null:defProperties.styles);
+        rst[JV.NODE_FONT_COLLECTION] = private_buildDftFonts(rptTpl, (defProperties === null)?null:defProperties.fonts);
+        rst[JV.NODE_PAGE_INFO] = {};
+        rst[JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MAIN_INFO_RPT_NAME];
+        rst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE] = JpcCommonHelper.getPageSize(rptTpl);
+        rst[JV.NODE_PAGE_INFO][JV.NODE_MARGINS] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS];
+        rst.items = [];
+        let bands = JpcBand.createNew(rptTpl, defProperties);
+        try {
+            //1.
+            let rstPage = {};
+            rstPage[JV.PROP_PAGE_SEQ] = 1;
+            if (me.flowTab) {
+                rstPage[JV.PROP_CELLS] = me.flowTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
+            } else if (me.crossTab) {
+                rstPage[JV.PROP_CELLS] = me.crossTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
+            } else if (me.billTab) {
+                rstPage[JV.PROP_CELLS] = me.billTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
+            }
+            rst.items.push(rstPage);
+            //2.
+            if (bands[JV.BAND_PROP_MERGE_BAND]) {
+                let mergedBand = {}, band = bands[JV.BAND_PROP_MERGE_BAND];
+                mergedBand[JV.PROP_LEFT] = parseInt(band[JV.PROP_LEFT].toFixed(0));
+                mergedBand[JV.PROP_RIGHT] = parseInt(band[JV.PROP_RIGHT].toFixed(0));
+                mergedBand[JV.PROP_TOP] = parseInt(band[JV.PROP_TOP].toFixed(0));
+                mergedBand[JV.PROP_BOTTOM] = parseInt(band[JV.PROP_BOTTOM].toFixed(0));
+                mergedBand[JV.BAND_PROP_STYLE] = band[JV.BAND_PROP_STYLE];
+                rst[JV.BAND_PROP_MERGE_BAND] = mergedBand;
+            }
+        } catch(exception) {
+            console.log(exception);
+        } finally {
+            bands = null;
+        }
+        return rst;
+    };
     JpcResult.outputAsSimpleJSONPageArray = function(rptTpl, dataObj, startPage, endPage, defProperties) {
         let me = this, rst = {};
         if ((startPage > 0) && (startPage <= endPage) && (endPage <= me.totalPages)) {

+ 29 - 0
modules/reports/rpt_component/jpc_flow_tab.js

@@ -594,6 +594,35 @@ JpcFlowTabSrv.prototype.createNew = function(){
         return rst;
     };
 
+    JpcFlowTabResult.outputAsPreviewPage = function (rptTpl, bands, controls, $CURRENT_RPT) {
+        let me = this, rst = [], vIdx = [];
+        //只预览第一页的数据
+        let pageStatus = [true, true, false, true, false, false, false, false];
+        JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
+        let maxRowRec = JpcFlowTabHelper.getMaxRowsPerPage(bands, rptTpl, false);
+        for (let i = 0; i < maxRowRec; i++) {
+            vIdx.push([-1, JV.DISPLAY_VAL_TYPE_NORMAL, JV.BLANK_VALUE_INDEX]);
+        }
+        let bkdispValueIdxLst = me.dispValueIdxLst;
+        me.pageStatusLst = [];
+        me.pageStatusLst.push(pageStatus);
+        me.dispValueIdxLst = [];
+        me.dispValueIdxLst.push(vIdx);
+        let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
+        // 2.2 Column tab
+        rst.push(me.outputColumn(rptTpl, null, 1, 0, bands, unitFactor, controls, 0));
+        // 2.1 Content-Tab
+        // rst.push(me.outputContent(rptTpl, null, 1, bands, unitFactor, controls, 0, $CURRENT_RPT));
+        // 2.3 Sum Seg
+        // rst.push(me.outputSegSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
+        // 2.4 Sum Page
+        // rst.push(me.outputPageSum(rptTpl, dataObj, 1, 0, bands, unitFactor, controls));
+        // 2.5 Group
+        // 2.6 Discrete
+        rst.push(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
+        me.dispValueIdxLst = bkdispValueIdxLst;
+        return rst;
+    };
     JpcFlowTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, adHocMergePos, $CURRENT_RPT) {
         let me = this, rst = [], tabRstLst = [];
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;

+ 90 - 0
test/unit/reports/test_preview_page.js

@@ -0,0 +1,90 @@
+/**
+ * Created by Tony on 2018/4/8.
+ */
+let test = require('tape');
+import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
+import JV from "../../../modules/reports/rpt_component/jpc_value_define";
+let config = require("../../../config/config.js");
+config.setupDb(process.env.NODE_ENV);
+let mongoose = require("mongoose");
+let fileUtils = require("../../../modules/common/fileUtils");
+let path = require('path');
+let dbm = require("../../../config/db/db_manager");
+let rpt_cfg = require('./rpt_cfg');
+dbm.connect(process.env.NODE_ENV);
+
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
+    require(path.resolve(modelPath));
+});
+
+let cfgCacheUtil = require("../../../config/cacheCfg");
+cfgCacheUtil.setupDftCache();
+
+let fsUtil = require("../../../public/fsUtil");
+
+// let demoPrjId = - 1;
+let demoRptId = 232; //重庆09年建筑 09表
+// let demoRptId = 229; //重庆09年建筑 封2表
+
+let pagesize = "A4";
+
+// demoPrjId = 720; //QA: DW3
+// demoPrjId = 1626; //QA:
+//*/
+let userId_Leng = 1142; //小冷User Id
+let userId_Dft = userId_Leng;
+/*/
+ let userId_Dft = 76075;
+ //*/
+
+let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
+
+let fs = require('fs');
+//设置Date Format函数
+fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
+    eval(data);
+});
+
+//*
+test('测试 - 预览: ', function (t) {
+    rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
+        if (rptTpl) {
+            try {
+                let printCom = JpcEx.createNew();
+                let defProperties = rpt_cfg;
+                rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
+                printCom.initialize(rptTpl);
+                let pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
+                if (pageRst) {
+                    fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/previewPageResult.jsp");
+                    t.pass('pass with succeed!');
+                    t.end();
+                } else {
+                    console.log("oh! no pages were created!");
+                    t.pass('pass with no page!');
+                    t.end();
+                }
+            } catch (ex) {
+                console.log(ex);
+                t.pass('pass with exception!');
+                t.end();
+            }
+        } else {
+            t.pass('no template was found!');
+            t.end();
+        }
+    });
+});
+//*/
+
+test('close the connection', function (t) {
+    setTimeout(function () {
+        mongoose.disconnect();
+        t.pass('closing db connection');
+        t.end();
+    }, 1000);
+    // mongoose.disconnect();
+    // t.pass('closing db connection');
+    // t.end();
+});