test_tpl_09.js 3.8 KB

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