test_summary_multi_prjs.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 pagesize = "A4";
  18. let userId_Leng = "5c3ffa9aa0a92732f41216e0"; //小冷User Id (养护的)
  19. // let userId_me = "5b6a60b1c4ba33000dd417c0"; //我的
  20. let userId_Dft = userId_Leng;
  21. //统一引用models
  22. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  23. require(path.resolve(modelPath));
  24. });
  25. //config.setupCache();
  26. let cfgCacheUtil = require("../../../config/cacheCfg");
  27. cfgCacheUtil.setupDftCache();
  28. let fsUtil = require("../../../public/fsUtil");
  29. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  30. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  31. import rptDataExtractor from "../../../modules/reports/util/rpt_yanghu_data_util";
  32. let fs = require('fs');
  33. //设置Date Format函数
  34. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  35. eval(data);
  36. });
  37. test('测试 - 测试模板啦: ', function (t) {
  38. rptTplDataFacade.getBudgetSummayDatas(demoPrjs).then(function(summaryRst) {
  39. //console.log(summaryRst);
  40. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  41. try {
  42. let dt = new Date();
  43. fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)原始数据.jsp");
  44. let rptDataUtil = new rptDataExtractor();
  45. rptDataUtil.initialize(rptTpl._doc);
  46. let tplData = rptDataUtil.assembleData(summaryRst);
  47. // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)整理后数据.jsp");
  48. // fsUtil.writeObjToFile(tplData, "D:/GitHome/YangHuCost/tmp/rptTplAssembledData_测试模板.jsp");
  49. //it's time to build the report!!!
  50. let printCom = JpcEx.createNew();
  51. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  52. let defProperties = rpt_cfg;
  53. let dftOption = JV.PAGING_OPTION_NORMAL;
  54. printCom.initialize(rptTpl);
  55. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
  56. let maxPages = printCom.totalPages;
  57. let customizeCfg = {"fillZero": true};
  58. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  59. if (pageRst) {
  60. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)page数据" + dt.getTime() + ".jsp");
  61. // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
  62. // console.log("excel uuid: " + uuidName);
  63. // });
  64. // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
  65. // console.log("pdf uuid: " + uuidName);
  66. // });
  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. });
  78. });
  79. });
  80. test('close the connection', function (t) {
  81. setTimeout(function () {
  82. mongoose.disconnect();
  83. t.pass('closing db connection');
  84. t.end();
  85. }, 1000);
  86. });