test_rpt_test_template.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Created by Tony on 2018/6/12.
  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 config = require("../../../config/config.js");
  8. config.setupDb(process.env.NODE_ENV);
  9. let mongoose = require("mongoose");
  10. let fileUtils = require("../../../modules/common/fileUtils");
  11. let path = require('path');
  12. let dbm = require("../../../config/db/db_manager");
  13. let rpt_cfg = require('./rpt_cfg');
  14. dbm.connect(process.env.NODE_ENV);
  15. //统一引用models
  16. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  17. require(path.resolve(modelPath));
  18. });
  19. //config.setupCache();
  20. let cfgCacheUtil = require("../../../config/cacheCfg");
  21. cfgCacheUtil.setupDftCache();
  22. let fsUtil = require("../../../public/fsUtil");
  23. let demoPrjId = - 1;
  24. // let demoRptId = 279;
  25. let demoRptId = 275; //测试模板-流水式
  26. // let demoRptId = 337; //19表
  27. let pagesize = "A4";
  28. //288: 11-2表(新)
  29. //279: 04
  30. // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了 QQ号
  31. let userId_Leng = "5acac1e885bf55000bd055ba"; //小冷User Id2
  32. // demoPrjId = 720; //QA: DW3
  33. //demoPrjId = 1626; //QA:
  34. demoPrjId = 2260; //QA:
  35. //*/
  36. let userId_Dft = userId_Leng;
  37. /*/
  38. let userId_Dft = "595328da1934dc327cad08eb";
  39. //*/
  40. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  41. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  42. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  43. let fs = require('fs');
  44. //设置Date Format函数
  45. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  46. eval(data);
  47. });
  48. test('测试 - 测试模板啦: ', function (t) {
  49. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  50. let rptDataUtil = new rptDataExtractor();
  51. rptDataUtil.initialize(rptTpl._doc);
  52. let filter = rptDataUtil.getDataRequestFilter();
  53. console.log(filter);
  54. //正常应该根据报表模板定义的数据类型来请求数据
  55. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  56. if (!err) {
  57. try {
  58. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_测试模板.jsp");
  59. let tplData = rptDataUtil.assembleData(rawDataObj);
  60. fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataAfterCacl_测试模板.jsp");
  61. // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_测试模板.jsp");
  62. //it's time to build the report!!!
  63. let printCom = JpcEx.createNew();
  64. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  65. let defProperties = rpt_cfg;
  66. let dftOption = JV.PAGING_OPTION_NORMAL;
  67. printCom.initialize(rptTpl);
  68. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  69. let maxPages = printCom.totalPages;
  70. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  71. if (pageRst) {
  72. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_测试模板.jsp");
  73. } else {
  74. console.log("oh! no pages were created!");
  75. }
  76. } catch (ex) {
  77. console.log(ex);
  78. t.pass('pass with exception!');
  79. t.end();
  80. }
  81. t.pass('pass succeeded!');
  82. t.end();
  83. } else {
  84. console.log(msg);
  85. t.pass('pass with error!');
  86. t.end();
  87. }
  88. })
  89. });
  90. });
  91. test('close the connection', function (t) {
  92. setTimeout(function () {
  93. mongoose.disconnect();
  94. t.pass('closing db connection');
  95. t.end();
  96. }, 1000);
  97. // mongoose.disconnect();
  98. // t.pass('closing db connection');
  99. // t.end();
  100. });