test_summary_multi_prjs.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Created by Tony on 2019/3/27.
  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. let demoPrjs = [548,561]; //
  16. // let demoRptId = 68; //01-2
  17. let demoRptId = 79; //01-1
  18. // let demoRptId = 73; //02-2
  19. let pagesize = "A4";
  20. // let userId_Leng = "5c3ffa9aa0a92732f41216e0"; //小冷User Id (养护的)
  21. // let userId_me = "5b6a60b1c4ba33000dd417c0"; //我的
  22. // let userId_Dft = userId_Leng;
  23. let userId_Dft = "5c49353e9bda24000b44414e"; //曾沛文的ID
  24. //统一引用models
  25. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  26. require(path.resolve(modelPath));
  27. });
  28. //config.setupCache();
  29. let cfgCacheUtil = require("../../../config/cacheCfg");
  30. cfgCacheUtil.setupDftCache();
  31. let fsUtil = require("../../../public/fsUtil");
  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_yanghu_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. rptTplDataFacade.getBudgetSummayDatas(demoPrjs).then(function(summaryRst) {
  43. //console.log(summaryRst);
  44. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  45. try {
  46. let dt = new Date();
  47. fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_1)原始数据.jsp");
  48. let rptDataUtil = new rptDataExtractor();
  49. rptDataUtil.initialize(rptTpl._doc);
  50. let tplData = rptDataUtil.assembleData(summaryRst);
  51. // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)整理后数据.jsp");
  52. // fsUtil.writeObjToFile(tplData, "D:/GitHome/YangHuCost/tmp/rptTplAssembledData_测试模板.jsp");
  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. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
  60. let maxPages = printCom.totalPages;
  61. let customizeCfg = {"fillZero": true};
  62. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  63. if (pageRst) {
  64. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)page数据" + dt.getTime() + ".jsp");
  65. // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
  66. // console.log("excel uuid: " + uuidName);
  67. // });
  68. // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
  69. // console.log("pdf uuid: " + uuidName);
  70. // });
  71. } else {
  72. console.log("oh! no pages were created!");
  73. }
  74. } catch (ex) {
  75. console.log(ex);
  76. t.pass('pass with exception!');
  77. t.end();
  78. }
  79. t.pass('pass succeeded!');
  80. t.end();
  81. });
  82. });
  83. });
  84. /*/
  85. test('测试 - 测试工料机汇总: ', function (t) {
  86. rptTplDataFacade.getGLJSummayDatas(demoPrjs).then(function(summaryRst) {
  87. // console.log(summaryRst);
  88. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  89. try {
  90. let dt = new Date();
  91. // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/02_2原始数据.jsp");
  92. let rptDataUtil = new rptDataExtractor();
  93. rptDataUtil.initialize(rptTpl._doc);
  94. let tplData = rptDataUtil.assembleData(summaryRst);
  95. // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)整理后数据.jsp");
  96. // fsUtil.writeObjToFile(tplData, "D:/GitHome/YangHuCost/tmp/rptTplAssembledData_测试模板.jsp");
  97. //it's time to build the report!!!
  98. let printCom = JpcEx.createNew();
  99. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  100. let defProperties = rpt_cfg;
  101. let dftOption = JV.PAGING_OPTION_NORMAL;
  102. printCom.initialize(rptTpl);
  103. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
  104. let maxPages = printCom.totalPages;
  105. let customizeCfg = {"fillZero": true};
  106. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  107. if (pageRst) {
  108. fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(02_2)page数据" + dt.getTime() + ".jsp");
  109. // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
  110. // console.log("excel uuid: " + uuidName);
  111. // });
  112. // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
  113. // console.log("pdf uuid: " + uuidName);
  114. // });
  115. } else {
  116. console.log("oh! no pages were created!");
  117. }
  118. } catch (ex) {
  119. console.log(ex);
  120. t.pass('pass with exception!');
  121. t.end();
  122. }
  123. t.pass('pass succeeded!');
  124. t.end();
  125. });
  126. });
  127. });
  128. //*/
  129. test('close the connection', function (t) {
  130. setTimeout(function () {
  131. mongoose.disconnect();
  132. t.pass('closing db connection');
  133. t.end();
  134. }, 1000);
  135. });