test_tpl_05.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * Created by Tony on 2018/8/15.
  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. let consts = require('../../../modules/main/models/project_consts');
  15. dbm.connect(process.env.NODE_ENV);
  16. //统一引用models
  17. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  18. require(path.resolve(modelPath));
  19. });
  20. let cfgCacheUtil = require("../../../config/cacheCfg");
  21. cfgCacheUtil.setupDftCache();
  22. let fsUtil = require("../../../public/fsUtil");
  23. let demoPrjId = - 1;
  24. // let demoRptId = 551; //05
  25. let demoRptId = 626; //06
  26. let pagesize = "A4";
  27. // demoPrjId = 720; //QA: DW3
  28. demoPrjId = 4563; //QA:
  29. //*/
  30. // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
  31. let userId_Leng = "5b5a66c4a3c23e000dccdd77"; //海珠的 _id
  32. let userId_Dft = userId_Leng;
  33. /*/
  34. let userId_Dft = "595328da1934dc327cad08eb";
  35. //*/
  36. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  37. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  38. let pm_facade = require('../../../modules/pm/facade/pm_facade');
  39. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  40. let fs = require('fs');
  41. //设置Date Format函数
  42. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  43. eval(data);
  44. });
  45. //*
  46. test('测试 - 模板05汇总表: ', function (t) {
  47. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  48. let rptDataUtil = new rptDataExtractor();
  49. rptDataUtil.initialize(rptTpl._doc);
  50. let summaryRst = [];
  51. let filter = rptDataUtil.getDataRequestFilter(summaryRst);
  52. console.log(filter);
  53. console.log(summaryRst);
  54. let promiseArr = [null, null];
  55. if (summaryRst.length > 0) {
  56. if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
  57. promiseArr[0] = pm_facade.getSummaryInfoByTender(demoPrjId, pm_facade.projectType.project);
  58. }
  59. if (summaryRst.indexOf(`Segment`) >= 0 || summaryRst.indexOf(`SegmentDetail`) >= 0) {
  60. promiseArr[1] = pm_facade.getSummaryInfoByTender(demoPrjId, pm_facade.projectType.engineering);
  61. }
  62. }
  63. //*/
  64. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  65. if (!err) {
  66. //取汇总数据流程
  67. if (promiseArr[0] !== null) {
  68. promiseArr[0].then(function (rst) {
  69. rawDataObj.Construct = rst.parent;
  70. rawDataObj.ConstructDetail = rst.subList;
  71. if (promiseArr[1] !== null) {
  72. promiseArr[1].then(function (rst) {
  73. rawDataObj.Segment = rst.parent;
  74. rawDataObj.SegmentDetail = rst.subList;
  75. buildPageData(t, rawDataObj, rptDataUtil, rptTpl);
  76. });
  77. } else {
  78. buildPageData(t, rawDataObj, rptDataUtil, rptTpl);
  79. }
  80. });
  81. } else if (promiseArr[1] !== null) {
  82. promiseArr[1].then(function (rst) {
  83. rawDataObj.Segment = rst.parent;
  84. rawDataObj.SegmentDetail = rst.subList;
  85. buildPageData(t, rawDataObj, rptDataUtil, rptTpl);
  86. });
  87. } else {
  88. buildPageData(t, rawDataObj, rptDataUtil, rptTpl);
  89. }
  90. } else {
  91. console.log(msg);
  92. t.pass('pass with error!');
  93. t.end();
  94. }
  95. });
  96. //*/
  97. //正常应该根据报表模板定义的数据类型来请求数据
  98. });
  99. });
  100. //*/
  101. function buildPageData(t, rawDataObj, rptDataUtil, rptTpl) {
  102. try {
  103. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_汇总表.jsp");
  104. let tplData = rptDataUtil.assembleData(rawDataObj);
  105. fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataAfterCacl_汇总表.jsp");
  106. fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_汇总表.jsp");
  107. //it's time to build the report!!!
  108. let printCom = JpcEx.createNew();
  109. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  110. let defProperties = rpt_cfg;
  111. let dftOption = JV.PAGING_OPTION_NORMAL;
  112. printCom.initialize(rptTpl);
  113. // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptAssembledData_汇总表.jsp");
  114. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptRawDataAfterAssembled_汇总表.jsp");
  115. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  116. let maxPages = printCom.totalPages;
  117. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  118. if (pageRst) {
  119. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/rptPageResult_汇总表.jsp");
  120. } else {
  121. console.log("oh! no pages were created!");
  122. }
  123. } catch (ex) {
  124. console.log(ex);
  125. t.pass('pass with exception!');
  126. t.end();
  127. }
  128. t.pass('pass succeeded!');
  129. t.end();
  130. }
  131. test('close the connection', function (t) {
  132. setTimeout(function () {
  133. mongoose.disconnect();
  134. t.pass('closing db connection');
  135. t.end();
  136. }, 3000);
  137. // mongoose.disconnect();
  138. // t.pass('closing db connection');
  139. // t.end();
  140. });