test_tpl_11.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Created by Tony on 2018/5/11.
  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 = 247, pagesize = "A4";
  25. // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了 QQ号
  26. let userId_Leng = "5acac1e885bf55000bd055ba"; //小冷User Id2
  27. // demoPrjId = 720; //QA: DW3
  28. //demoPrjId = 1626; //QA:
  29. demoPrjId = 2260; //QA:
  30. //*/
  31. let userId_Dft = userId_Leng;
  32. /*/
  33. let userId_Dft = "595328da1934dc327cad08eb";
  34. //*/
  35. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  36. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  37. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  38. let fs = require('fs');
  39. //设置Date Format函数
  40. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  41. eval(data);
  42. });
  43. test('测试 - 测试模板: 表-11 ', function (t) {
  44. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  45. let rptDataUtil = new rptDataExtractor();
  46. rptDataUtil.initialize(rptTpl._doc);
  47. let filter = rptDataUtil.getDataRequestFilter();
  48. console.log(filter);
  49. //正常应该根据报表模板定义的数据类型来请求数据
  50. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  51. if (!err) {
  52. try {
  53. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_建筑11表.jsp");
  54. let tplData = rptDataUtil.assembleData(rawDataObj);
  55. // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_建筑11表.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. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  63. let maxPages = printCom.totalPages;
  64. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  65. if (pageRst) {
  66. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_建筑11表.jsp");
  67. } else {
  68. console.log("oh! no pages were created!");
  69. }
  70. } catch (ex) {
  71. console.log(ex);
  72. t.pass('pass with exception!');
  73. t.end();
  74. }
  75. t.pass('pass succeeded!');
  76. t.end();
  77. } else {
  78. console.log(msg);
  79. t.pass('pass with error!');
  80. t.end();
  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. }, 1000);
  91. });