test_tpl_10.js 4.0 KB

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