test_tpl_09_1.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Created by Tony on 2017/10/18.
  3. */
  4. let test = require('tape');
  5. import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
  6. import JV from "../../../modules/reports/rpt_component/jpc_value_define";
  7. let mongoose = require("mongoose");
  8. let fileUtils = require("../../../modules/common/fileUtils");
  9. let path = require('path');
  10. let dbm = require("../../../config/db/db_manager");
  11. let rpt_cfg = require('./rpt_cfg');
  12. dbm.connect();
  13. let consts = require('../../../modules/main/models/project_consts');
  14. let projectConsts = consts.projectConst;
  15. fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
  16. require(path.resolve(modelPath));
  17. });
  18. fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
  19. require(path.resolve(modelPath));
  20. });
  21. //引入报表模块
  22. fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
  23. require(path.resolve(modelPath));
  24. })
  25. //暂时引入其它模块的model
  26. require('../../../modules/fee_rates/models/fee_rates');
  27. // 引入人工系数模块
  28. require('../../../modules/main/models/labour_coe_model');
  29. require('../../../modules/main/models/calc_program_model');
  30. let fsUtil = require("../../../public/fsUtil");
  31. let prjMdl = require('../../../modules/pm/models/project_model');
  32. let projectDataMdl = require('../../../modules/main/models/project');
  33. let demoPrjId = - 1;
  34. let demoRptId = 226, pagesize = "A4";
  35. let userId_Leng = 1142; //小冷User Id
  36. demoPrjId = 720; //QA: DW3
  37. /*/
  38. let userId_Dft = userId_Leng;
  39. /*/
  40. let userId_Dft = 76075;
  41. //*/
  42. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  43. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  44. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  45. let fs = require('fs');
  46. //设置Date Format函数
  47. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  48. eval(data);
  49. });
  50. /*/
  51. test('测试 - 获取project数据: ', function (t) {
  52. projectDataMdl.getData(demoPrjId, function (err, message, result) {
  53. if (!err) {
  54. fsUtil.wirteObjToFile(result, "D:/GitHome/ConstructionCost/tmp/ProjectDataFullObject.js");
  55. t.pass('pass succeeded!');
  56. t.end();
  57. } else {
  58. //callback(req, res, err, message, null);
  59. t.pass('pass failed!');
  60. t.end();
  61. }
  62. });
  63. });
  64. //*/
  65. /*/
  66. test('测试 - 获取project部分数据: ', function (t) {
  67. let filter = [];
  68. filter.push(projectConsts.BILLS);
  69. filter.push(projectConsts.RATION);
  70. filter.push(projectConsts.RATION_GLJ);
  71. filter.push(projectConsts.PROJECTGLJ);
  72. filter.push(projectConsts.FEERATE);
  73. filter.push(projectConsts.CALC_PROGRAM);
  74. prjMdl.project.getUserProject(userId_Dft, demoPrjId, function(err, msg, prjObj){
  75. if (!err) {
  76. projectDataMdl.getFilterData(demoPrjId, filter, function (results) {
  77. if (results) {
  78. // let newData = [];
  79. // for (let item of results) {
  80. // newData.push(JSON.stringify(item));
  81. // }
  82. // fsUtil.writeArrayToFile(newData, "D:/GitHome/ConstructionCost/tmp/getProjectData_partial.js");
  83. fsUtil.wirteObjToFile(prjObj, "D:/GitHome/ConstructionCost/tmp/getProjectObjectNew.js");
  84. fsUtil.wirteObjToFile(results, "D:/GitHome/ConstructionCost/tmp/getProjectData_partialNew.js");
  85. t.pass('pass succeeded!');
  86. t.end();
  87. } else {
  88. //callback(req, res, err, message, null);
  89. t.pass('get project data failed!');
  90. t.end();
  91. }
  92. });
  93. } else {
  94. t.pass('get project failed!');
  95. t.end();
  96. }
  97. });
  98. });
  99. //*/
  100. //*
  101. test('测试 - 测试模板啦: ', function (t) {
  102. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  103. let rptDataUtil = new rptDataExtractor();
  104. rptDataUtil.initialize(rptTpl._doc);
  105. let filter = rptDataUtil.getDataRequestFilter();
  106. console.log(filter);
  107. //正常应该根据报表模板定义的数据类型来请求数据
  108. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  109. if (!err) {
  110. let tplData = rptDataUtil.assembleData(rawDataObj);
  111. // fsUtil.wirteObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.js");
  112. //it's time to build the report!!!
  113. let printCom = JpcEx.createNew();
  114. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  115. let defProperties = rpt_cfg;
  116. let dftOption = JV.PAGING_OPTION_NORMAL;
  117. printCom.initialize(rptTpl);
  118. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  119. let maxPages = printCom.totalPages;
  120. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  121. if (pageRst) {
  122. fsUtil.wirteObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.js");
  123. } else {
  124. console.log("oh! no pages were created!")
  125. }
  126. t.pass('pass succeeded!');
  127. t.end();
  128. } else {
  129. console.log(msg);
  130. t.pass('pass with error!');
  131. t.end();
  132. }
  133. })
  134. });
  135. });
  136. //*/
  137. test('close the connection', function (t) {
  138. setTimeout(function () {
  139. mongoose.disconnect();
  140. t.pass('closing db connection');
  141. t.end();
  142. }, 3000);
  143. // mongoose.disconnect();
  144. // t.pass('closing db connection');
  145. // t.end();
  146. });