test_tpl_09.js 4.0 KB

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