|
@@ -0,0 +1,170 @@
|
|
|
+/**
|
|
|
+ * Created by Tony on 2017/12/20.
|
|
|
+ */
|
|
|
+
|
|
|
+let test = require('tape');
|
|
|
+import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
|
|
|
+import JV from "../../../modules/reports/rpt_component/jpc_value_define";
|
|
|
+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();
|
|
|
+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) {
|
|
|
+ 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 = 1296; //QA:
|
|
|
+//*/
|
|
|
+let userId_Dft = userId_Leng;
|
|
|
+/*/
|
|
|
+ let userId_Dft = 76075;
|
|
|
+ //*/
|
|
|
+
|
|
|
+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('测试 - 获取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) {
|
|
|
+ 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.js");
|
|
|
+ let tplData = rptDataUtil.assembleData(rawDataObj);
|
|
|
+ //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.js");
|
|
|
+ } 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();
|
|
|
+ }, 3000);
|
|
|
+ // mongoose.disconnect();
|
|
|
+ // t.pass('closing db connection');
|
|
|
+ // t.end();
|
|
|
+});
|