test_summary_multi_prjs.js 4.1 KB

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