test_tpl_09.js 4.3 KB

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