test_summary_multi_prjs.js 6.5 KB

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