瀏覽代碼

1. 普通流水表的分组问题。 2. 指标的getProperty方法支持深度搜索

TonyKang 7 年之前
父節點
當前提交
3a0b4ee37e

+ 9 - 3
modules/reports/rpt_component/jpc_flow_tab.js

@@ -107,10 +107,16 @@ JpcFlowTabSrv.prototype.createNew = function(){
                     if (couldBreak) break;
                 } else {
                     //备注: 在有group的情况下,如果grpPageInfo[JV.PROP_SEG_GRP_IDX] 范围大于 grpSequenceInfo.length,则表示已经到最后了,不要再加空白数据了
+                    //      !!!但这是在有ex数据的情况下!!!
                     if (grpPageInfo[JV.PROP_SEG_GRP_IDX] < grpSequenceInfo.length) {
                         if (private_normal_add_rec(vi)) break;
                     } else {
-                        break;
+                        //还得判断是否是普通的流水数据情况,这里可以用isFollow来进行判断,暂时不需要特意加新参数(以后如isFollow的意义有变化则需要调整)
+                        if (!isFollow) {
+                            if (private_normal_add_rec(vi)) break;
+                        } else {
+                            break;
+                        }
                     }
                 }
             } else {
@@ -197,7 +203,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 }
                 let sumV = 0;
                 for (let si = preGrpIdx; si <= nexGrpIdx; si++) {
-                    sumV += JpcFieldHelper.getValue(data_field, segDataIdx[si]);
+                    sumV += parseFloat(JpcFieldHelper.getValue(data_field, segDataIdx[si]));
                 }
                 // me.group_sum_values[segIdx][j].push(sumV);
                 me.group_sum_values[segIdx][me.group_sum_fields[j][JV.PROP_SUM_KEY]].push(sumV);
@@ -587,7 +593,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                             }
                             //add page info
                             pageStatus[JV.STATUS_SEGMENT_END] = true;
-                            pageStatus[JV.STATUS_REPORT_END] = true;
+                            pageStatus[JV.STATUS_REPORT_END] = (segIdx === me.segments.length - 1);
                             private_addPage(segIdx, grpSeqInfo, false, false, -1);
                         } else {
                             private_addPage(segIdx, grpSeqInfo, false, false, -1);

+ 13 - 1
modules/reports/util/rpt_construct_data_util.js

@@ -1029,6 +1029,7 @@ function ext_getPropety(propKey) {
         for (let dItem of getActDataArr(dtObj)) {
             let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
             if (propKey instanceof Array) {
+                //备注:这里的key数组表示取value的优先级
                 for (let pi = 0; pi < propKey.length; pi++) {
                     if (doc.hasOwnProperty("property")) {
                         if (doc["property"].hasOwnProperty(propKey[pi])) {
@@ -1038,6 +1039,16 @@ function ext_getPropety(propKey) {
                     } else if (doc.hasOwnProperty(propKey[pi])) {
                         rst.push(doc[propKey[pi]]);
                         break;
+                    } else {
+                        let lenBefore = rst.length;
+                        getDeepProperty(propKey[pi], doc, rst);
+                        if (rst.length === (lenBefore + 1)) {
+                            if (rst[lenBefore] !== null && rst[lenBefore] !== undefined && rst[lenBefore] !== "") {
+                                break;
+                            } else {
+                                rst.splice(-1, 1); //删除末尾一条数据,给后面留空间
+                            }
+                        }
                     }
                     if (pi === propKey.length - 1) rst.push('');
                 }
@@ -1047,7 +1058,8 @@ function ext_getPropety(propKey) {
                 } else if (doc.hasOwnProperty(propKey)) {
                     rst.push(doc[propKey]);
                 } else {
-                    rst.push('');
+                    // rst.push('');
+                    getDeepProperty(propKey, doc, rst);
                 }
             }
         }

+ 2 - 2
test/unit/reports/test_rpt_11_2.js

@@ -62,8 +62,8 @@ test('测试 - 测试模板啦: ', function (t) {
                 try {
                     // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_建筑11-2表.jsp");
                     let tplData = rptDataUtil.assembleData(rawDataObj);
-                    fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataAfterCacl_建筑11-2表.jsp");
-                    // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_建筑11-2表.jsp");
+                    // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataAfterCacl_建筑11-2表.jsp");
+                    fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_建筑11-2表.jsp");
                     //it's time to build the report!!!
                     let printCom = JpcEx.createNew();
                     rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;

+ 107 - 0
test/unit/reports/test_rpt_test_template.js

@@ -0,0 +1,107 @@
+/**
+ * Created by Tony on 2018/6/12.
+ */
+
+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));
+});
+
+//config.setupCache();
+let cfgCacheUtil = require("../../../config/cacheCfg");
+cfgCacheUtil.setupDftCache();
+
+let fsUtil = require("../../../public/fsUtil");
+
+let demoPrjId = - 1;
+let demoRptId = 275, pagesize = "A4"; //11-2表(新)
+
+// let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了 QQ号
+let userId_Leng = "5acac1e885bf55000bd055ba"; //小冷User Id2
+// demoPrjId = 720; //QA: DW3
+//demoPrjId = 1626; //QA:
+demoPrjId = 2260; //QA:
+//*/
+let userId_Dft = userId_Leng;
+/*/
+ let userId_Dft = "595328da1934dc327cad08eb";
+ //*/
+
+let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
+let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
+
+import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
+
+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) {
+        let rptDataUtil = new rptDataExtractor();
+        rptDataUtil.initialize(rptTpl._doc);
+        let filter = rptDataUtil.getDataRequestFilter();
+        console.log(filter);
+        //正常应该根据报表模板定义的数据类型来请求数据
+        rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
+            if (!err) {
+                try {
+                    // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_测试模板.jsp");
+                    let tplData = rptDataUtil.assembleData(rawDataObj);
+                    // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataAfterCacl_测试模板.jsp");
+                    // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_测试模板.jsp");
+                    //it's time to build the report!!!
+                    let printCom = JpcEx.createNew();
+                    rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
+                    let defProperties = rpt_cfg;
+                    let dftOption = JV.PAGING_OPTION_NORMAL;
+                    printCom.initialize(rptTpl);
+                    printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
+                    let maxPages = printCom.totalPages;
+                    let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
+                    if (pageRst) {
+                        // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_测试模板.jsp");
+                    } else {
+                        console.log("oh! no pages were created!");
+                    }
+                } catch (ex) {
+                    console.log(ex);
+                    t.pass('pass with exception!');
+                    t.end();
+                }
+
+                t.pass('pass succeeded!');
+                t.end();
+            } else {
+                console.log(msg);
+                t.pass('pass with error!');
+                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();
+});