Sfoglia il codice sorgente

code tuning and sync db management

TonyKang 7 anni fa
parent
commit
26a96e7b63

+ 30 - 23
modules/reports/rpt_component/jpc_flow_tab.js

@@ -422,7 +422,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 }
                 if (isMix) {
                     //先处理上半部分
-                    private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], grpSeqInfo, counterRowRec, mixSplitPoint,me.page_seg_map, segIdx, pageIdx, grpPageInfo, false, null, 0);
+                    prePageLeftAutoHeightRecAmt = private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], grpSeqInfo, counterRowRec, mixSplitPoint,me.page_seg_map, segIdx, pageIdx, grpPageInfo, false, me.auto_height_info, prePageLeftAutoHeightRecAmt);
                     for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
                         private_chk_handle_rec_amt(dv, false);
                     }
@@ -439,7 +439,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                     }
                     me.dispValueIdxLst.splice(me.dispValueIdxLst.length - 1, 1);
                 } else if (isFollow) {
-                    private_addPageValue(me.dispValueIdxLst, followTabEx.segments[segIdx], null, counterRowRecEx, maxRowRec, me.page_seg_map, segIdx, pageIdx, null, true, null, 0);
+                    prePageLeftAutoHeightRecAmt = private_addPageValue(me.dispValueIdxLst, followTabEx.segments[segIdx], null, counterRowRecEx, maxRowRec, me.page_seg_map, segIdx, pageIdx, null, true, me.auto_height_info, prePageLeftAutoHeightRecAmt);
                     for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
                         private_chk_handle_rec_amt(dv, true);
                     }
@@ -472,9 +472,16 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 let ttlSegRecAmtNormal = me.segments[segIdx].length + grpRecAmt; //正常的segment下的数据长度累计(含grouping data)
                 let ttlSegRecAmt = (followTabEx)?(me.segments[segIdx].length + grpRecAmt + followTabEx.segments[segIdx].length + grpRecAmtEx):(me.segments[segIdx].length + grpRecAmt); //所有的segment下的数据长度累计(包括ex部分)
                 let adHocAutoHeightAmt = 0;
+                let adHocAutoHeightGrpStartIdx = 0;
                 if (me.auto_height_fields_idx.length > 0) {
                     for (let loop = 0; loop < me.auto_height_info[segIdx].length; loop++) {
                         adHocAutoHeightAmt += (me.auto_height_info[segIdx][loop] - 1);
+                        if (me.group_node_info && me.group_node_info[segIdx]) {
+                            if (me.group_node_info[segIdx][adHocAutoHeightGrpStartIdx] === loop) {
+                                me.group_node_info[segIdx][adHocAutoHeightGrpStartIdx] = me.group_node_info[segIdx][adHocAutoHeightGrpStartIdx] + adHocAutoHeightAmt;
+                                adHocAutoHeightGrpStartIdx++;
+                            }
+                        }
                     }
                     ttlSegRecAmtNormal += adHocAutoHeightAmt;
                     ttlSegRecAmt += adHocAutoHeightAmt;
@@ -484,15 +491,29 @@ JpcFlowTabSrv.prototype.createNew = function(){
                     if (currentRecAmt > 0) pageStatus[JV.STATUS_SEGMENT_START] = false;
                     if (pageIdx > 0) pageStatus[JV.STATUS_REPORT_START] = false;
                     //开始判断各种scenarios
+                    adHocAutoHeightAmt = 0;
+                    let recAmtForAdHocAutoHeight = 0;
+                    if (me.auto_height_fields_idx.length > 0) {
+                        adHocAutoHeightAmt -= prePageLeftAutoHeightRecAmt;
+                        //for (let loop = currentRecAmt; loop < me.auto_height_info[segIdx].length; loop++) {
+                        for (let loop = currentRecAmt; loop < currentRecAmt + maxRowRec; loop++) {
+                            if (me.auto_height_info[segIdx].length > loop) {
+                                adHocAutoHeightAmt += (me.auto_height_info[segIdx][loop] - 1);
+                                recAmtForAdHocAutoHeight++;
+                            } else {
+                                break;
+                            }
+                        }
+                    }
                     if ((ttlSegRecAmtNormal < ttlSegRecAmt) || (followTabEx != null)) {
                         //有流水拓展,并且是follow mode
-                        if (currentRecAmt + maxRowRec > ttlSegRecAmtNormal) {
-                            if (currentRecAmt >= ttlSegRecAmtNormal) {
+                        if (currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight + maxRowRec > ttlSegRecAmtNormal) {
+                            if (currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight >= ttlSegRecAmtNormal) {
                                 //纯 followTabEx 数据
-                                if (currentRecAmt + maxRowRec >= ttlSegRecAmt) {
+                                if (currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight + maxRowRec >= ttlSegRecAmt) {
                                     pageStatus[JV.STATUS_SEGMENT_END] = true;
                                     private_resetBandArea();
-                                    let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt, maxRowRec, me.isEx);
+                                    let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight, maxRowRec, me.isEx);
                                     if (hasAdHocRow) {
                                         //add page info(pre segment end)
                                         pageStatus[JV.STATUS_SEGMENT_END] = false;
@@ -506,10 +527,10 @@ JpcFlowTabSrv.prototype.createNew = function(){
                                 }
                             } else {
                                 //混合数据
-                                if (currentRecAmt + maxRowRec >= ttlSegRecAmt) {
+                                if (currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight + maxRowRec >= ttlSegRecAmt) {
                                     pageStatus[JV.STATUS_SEGMENT_END] = true;
                                     private_resetBandArea();
-                                    let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt, maxRowRec, me.isEx);
+                                    let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight, maxRowRec, me.isEx);
                                     if (hasAdHocRow) {
                                         //add page info(pre segment end)
                                         pageStatus[JV.STATUS_SEGMENT_END] = false;
@@ -517,7 +538,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                                     }
                                     //add page info
                                     pageStatus[JV.STATUS_SEGMENT_END] = true;
-                                    if (currentRecAmt >= ttlSegRecAmtNormal) {
+                                    if (currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight >= ttlSegRecAmtNormal) {
                                         //纯 followTabEx 数据啦
                                         private_addPage(segIdx, null, true, false, -1);
                                     } else {
@@ -533,20 +554,6 @@ JpcFlowTabSrv.prototype.createNew = function(){
                         }
                     } else {
                         //普通流水数据情况
-                        let adHocAutoHeightAmt = 0;
-                        let recAmtForAdHocAutoHeight = 0;
-                        if (me.auto_height_fields_idx.length > 0) {
-                            adHocAutoHeightAmt -= prePageLeftAutoHeightRecAmt;
-                            //for (let loop = currentRecAmt; loop < me.auto_height_info[segIdx].length; loop++) {
-                            for (let loop = currentRecAmt; loop < currentRecAmt + maxRowRec; loop++) {
-                                if (me.auto_height_info[segIdx].length > loop) {
-                                    adHocAutoHeightAmt += (me.auto_height_info[segIdx][loop] - 1);
-                                    recAmtForAdHocAutoHeight++;
-                                } else {
-                                    break;
-                                }
-                            }
-                        }
                         if ((currentRecAmt + adHocAutoHeightAmt + recAmtForAdHocAutoHeight + maxRowRec >= ttlSegRecAmt)
                              && (recAmtForAdHocAutoHeight + adHocAutoHeightAmt < 2 * maxRowRec) ) {
                             //备注: 理论上自动行高是没有上限的,有可能正常一页的数据可以拓展到3页及以上,在此极端情况下,必须做一些限制判断,否则会出现缺页情况。

+ 5 - 21
test/unit/reports/test_cover_01.js

@@ -11,42 +11,26 @@ let path = require('path');
 let dbm = require("../../../config/db/db_manager");
 let rpt_cfg = require('./rpt_cfg');
 dbm.connect();
-let consts = require('../../../modules/main/models/project_consts');
-let projectConsts = consts.projectConst;
-fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-});
 
-fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
     require(path.resolve(modelPath));
 });
 
-//引入报表模块
-fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-})
-
-//暂时引入其它模块的model
-require('../../../modules/fee_rates/models/fee_rates');
-// 引入人工系数模块
-require('../../../modules/main/models/labour_coe_model');
-require('../../../modules/main/models/calc_program_model');
 //config.setupCache();
 let cfgCacheUtil = require("../../../config/cacheCfg");
 cfgCacheUtil.setupDftCache();
 
 let fsUtil = require("../../../public/fsUtil");
 
-let prjMdl = require('../../../modules/pm/models/project_model');
-let projectDataMdl = require('../../../modules/main/models/project');
 let demoPrjId = - 1;
 let demoRptId = 223, pagesize = "A4";
 
-let userId_Leng = 1142; //小冷User Id
 demoPrjId = 1220; //QA:
-/*/
+/*
+ let userId_Leng = 1142; //小冷User Id
  let userId_Dft = userId_Leng;
- /*/
+/*/
 let userId_Dft = 76075;
 //*/
 

+ 2 - 18
test/unit/reports/test_cover_02.js

@@ -11,34 +11,18 @@ let path = require('path');
 let dbm = require("../../../config/db/db_manager");
 let rpt_cfg = require('./rpt_cfg');
 dbm.connect();
-let consts = require('../../../modules/main/models/project_consts');
-let projectConsts = consts.projectConst;
-fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-});
 
-fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
     require(path.resolve(modelPath));
 });
 
-//引入报表模块
-fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-})
-
-//暂时引入其它模块的model
-require('../../../modules/fee_rates/models/fee_rates');
-// 引入人工系数模块
-require('../../../modules/main/models/labour_coe_model');
-require('../../../modules/main/models/calc_program_model');
 //config.setupCache();
 let cfgCacheUtil = require("../../../config/cacheCfg");
 cfgCacheUtil.setupDftCache();
 
 let fsUtil = require("../../../public/fsUtil");
 
-let prjMdl = require('../../../modules/pm/models/project_model');
-let projectDataMdl = require('../../../modules/main/models/project');
 let demoPrjId = - 1;
 let demoRptId = 229, pagesize = "A4";
 

+ 106 - 0
test/unit/reports/test_get_prj_data.js

@@ -0,0 +1,106 @@
+/**
+ * Created by Tony on 2018/3/23.
+ */
+let test = require('tape');
+let mongoose = require("mongoose");
+let fileUtils = require("../../../modules/common/fileUtils");
+let path = require('path');
+let dbm = require("../../../config/db/db_manager");
+dbm.connect();
+let consts = require('../../../modules/main/models/project_consts');
+let projectConsts = consts.projectConst;
+
+//统一引用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 prjMdl = require('../../../modules/pm/models/project_model');
+let projectDataMdl = require('../../../modules/main/models/project');
+
+let demoPrjId = - 1;
+
+// demoPrjId = 720; //QA: DW3
+demoPrjId = 1626; //QA:
+//*/
+let userId_Leng = 1142; //小冷User Id
+let userId_Dft = userId_Leng;
+/*/
+let userId_Dft = 76075;
+//*/
+
+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('测试 - 获取project数据: ', function (t) {
+    projectDataMdl.getData(demoPrjId, function (err, message, result) {
+        if (!err) {
+            fsUtil.writeObjToFile(result, "D:/GitHome/ConstructionCost/tmp/ProjectDataFullObject.js");
+            t.pass('pass succeeded!');
+            t.end();
+        } else {
+            //callback(req, res, err, message, null);
+            t.pass('pass failed!');
+            t.end();
+        }
+    });
+});
+//*/
+
+//*/
+test('测试 - 获取project部分数据: ', function (t) {
+    let filter = [];
+    filter.push(projectConsts.BILLS);
+    filter.push(projectConsts.RATION);
+    filter.push(projectConsts.RATION_GLJ);
+    filter.push(projectConsts.PROJECTGLJ);
+    filter.push(projectConsts.FEERATE);
+    filter.push(projectConsts.CALC_PROGRAM);
+    prjMdl.project.getUserProject(userId_Dft, demoPrjId, function(err, msg, prjObj){
+        if (!err) {
+            projectDataMdl.getFilterData(demoPrjId, filter, function (results) {
+                if (results) {
+                    // let newData = [];
+                    // for (let item of results) {
+                    //     newData.push(JSON.stringify(item));
+                    // }
+                    // fsUtil.writeArrayToFile(newData, "D:/GitHome/ConstructionCost/tmp/getProjectData_partial.js");
+                    // fsUtil.writeObjToFile(prjObj, "D:/GitHome/ConstructionCost/tmp/getProjectObjectNew.js");
+                    fsUtil.writeObjToFile(results, "D:/GitHome/ConstructionCost/tmp/getProjectData_partialNew.js");
+                    t.pass('pass succeeded!');
+                    t.end();
+                } else {
+                    //callback(req, res, err, message, null);
+                    t.pass('get project data failed!');
+                    t.end();
+                }
+            });
+        } else {
+            t.pass('get project failed!');
+            t.end();
+        }
+    });
+});
+//*/
+
+test('close the connection', function (t) {
+    setTimeout(function () {
+        mongoose.disconnect();
+        t.pass('closing db connection');
+        t.end();
+    }, 3000);
+    // mongoose.disconnect();
+    // t.pass('closing db connection');
+    // t.end();
+});

+ 3 - 70
test/unit/reports/test_tpl_09.js

@@ -11,41 +11,25 @@ let path = require('path');
 let dbm = require("../../../config/db/db_manager");
 let rpt_cfg = require('./rpt_cfg');
 dbm.connect();
-let consts = require('../../../modules/main/models/project_consts');
-let projectConsts = consts.projectConst;
-fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-});
 
-fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
     require(path.resolve(modelPath));
 });
 
-//引入报表模块
-fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-})
-
-//暂时引入其它模块的model
-require('../../../modules/fee_rates/models/fee_rates');
-// 引入人工系数模块
-require('../../../modules/main/models/labour_coe_model');
-require('../../../modules/main/models/calc_program_model');
 //config.setupCache();
 let cfgCacheUtil = require("../../../config/cacheCfg");
 cfgCacheUtil.setupDftCache();
 
 let fsUtil = require("../../../public/fsUtil");
 
-let prjMdl = require('../../../modules/pm/models/project_model');
-let projectDataMdl = require('../../../modules/main/models/project');
 let demoPrjId = - 1;
 let demoRptId = 232, pagesize = "A4";
 
-let userId_Leng = 1142; //小冷User Id
 // demoPrjId = 720; //QA: DW3
 demoPrjId = 1626; //QA:
 //*/
+let userId_Leng = 1142; //小冷User Id
 let userId_Dft = userId_Leng;
 /*/
 let userId_Dft = 76075;
@@ -62,57 +46,6 @@ fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.j
     eval(data);
 });
 
-/*/
- test('测试 - 获取project数据: ', function (t) {
- projectDataMdl.getData(demoPrjId, function (err, message, result) {
- if (!err) {
- fsUtil.writeObjToFile(result, "D:/GitHome/ConstructionCost/tmp/ProjectDataFullObject.js");
- t.pass('pass succeeded!');
- t.end();
- } else {
- //callback(req, res, err, message, null);
- t.pass('pass failed!');
- t.end();
- }
- });
- });
- //*/
-/*/
- test('测试 - 获取project部分数据: ', function (t) {
- let filter = [];
- filter.push(projectConsts.BILLS);
- filter.push(projectConsts.RATION);
- filter.push(projectConsts.RATION_GLJ);
- filter.push(projectConsts.PROJECTGLJ);
- filter.push(projectConsts.FEERATE);
- filter.push(projectConsts.CALC_PROGRAM);
- prjMdl.project.getUserProject(userId_Dft, demoPrjId, function(err, msg, prjObj){
- if (!err) {
- projectDataMdl.getFilterData(demoPrjId, filter, function (results) {
- if (results) {
- // let newData = [];
- // for (let item of results) {
- //     newData.push(JSON.stringify(item));
- // }
- // fsUtil.writeArrayToFile(newData, "D:/GitHome/ConstructionCost/tmp/getProjectData_partial.js");
- // fsUtil.writeObjToFile(prjObj, "D:/GitHome/ConstructionCost/tmp/getProjectObjectNew.js");
- fsUtil.writeObjToFile(results, "D:/GitHome/ConstructionCost/tmp/getProjectData_partialNew.js");
- t.pass('pass succeeded!');
- t.end();
- } else {
- //callback(req, res, err, message, null);
- t.pass('get project data failed!');
- t.end();
- }
- });
- } else {
- t.pass('get project failed!');
- t.end();
- }
- });
- });
- //*/
-
 //*
 test('测试 - 测试模板啦: ', function (t) {
     rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {

+ 2 - 70
test/unit/reports/test_tpl_09_1.js

@@ -10,35 +10,18 @@ let path = require('path');
 let dbm = require("../../../config/db/db_manager");
 let rpt_cfg = require('./rpt_cfg');
 dbm.connect();
-let consts = require('../../../modules/main/models/project_consts');
-let projectConsts = consts.projectConst;
-fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-});
 
-fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
+//统一引用models
+fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
     require(path.resolve(modelPath));
 });
 
-//引入报表模块
-fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
-    require(path.resolve(modelPath));
-})
-
-//暂时引入其它模块的model
-require('../../../modules/fee_rates/models/fee_rates');
-// 引入人工系数模块
-require('../../../modules/main/models/labour_coe_model');
-require('../../../modules/main/models/calc_program_model');
-
 //config.setupCache();
 let cfgCacheUtil = require("../../../config/cacheCfg");
 cfgCacheUtil.setupDftCache();
 
 let fsUtil = require("../../../public/fsUtil");
 
-let prjMdl = require('../../../modules/pm/models/project_model');
-let projectDataMdl = require('../../../modules/main/models/project');
 let demoPrjId = - 1;
 let demoRptId = 226, pagesize = "A4";
 
@@ -62,57 +45,6 @@ fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.j
     eval(data);
 });
 
-/*/
-test('测试 - 获取project数据: ', function (t) {
-    projectDataMdl.getData(demoPrjId, function (err, message, result) {
-        if (!err) {
-            fsUtil.writeObjToFile(result, "D:/GitHome/ConstructionCost/tmp/ProjectDataFullObject.js");
-            t.pass('pass succeeded!');
-            t.end();
-        } else {
-            //callback(req, res, err, message, null);
-            t.pass('pass failed!');
-            t.end();
-        }
-    });
-});
-//*/
-/*/
-test('测试 - 获取project部分数据: ', function (t) {
-    let filter = [];
-    filter.push(projectConsts.BILLS);
-    filter.push(projectConsts.RATION);
-    filter.push(projectConsts.RATION_GLJ);
-    filter.push(projectConsts.PROJECTGLJ);
-    filter.push(projectConsts.FEERATE);
-    filter.push(projectConsts.CALC_PROGRAM);
-    prjMdl.project.getUserProject(userId_Dft, demoPrjId, function(err, msg, prjObj){
-        if (!err) {
-            projectDataMdl.getFilterData(demoPrjId, filter, function (results) {
-                if (results) {
-                    // let newData = [];
-                    // for (let item of results) {
-                    //     newData.push(JSON.stringify(item));
-                    // }
-                    // fsUtil.writeArrayToFile(newData, "D:/GitHome/ConstructionCost/tmp/getProjectData_partial.js");
-                    // fsUtil.writeObjToFile(prjObj, "D:/GitHome/ConstructionCost/tmp/getProjectObjectNew.js");
-                    fsUtil.writeObjToFile(results, "D:/GitHome/ConstructionCost/tmp/getProjectData_partialNew.js");
-                    t.pass('pass succeeded!');
-                    t.end();
-                } else {
-                    //callback(req, res, err, message, null);
-                    t.pass('get project data failed!');
-                    t.end();
-                }
-            });
-        } else {
-            t.pass('get project failed!');
-            t.end();
-        }
-    });
-});
-//*/
-
 //*
 test('测试 - 测试模板啦: ', function (t) {
     rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {