test_svg_data.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Created by Tony on 2018/7/5.
  3. */
  4. let test = require('tape');
  5. const JpcEx = require("../../../modules/reports/rpt_component/jpc_ex");
  6. const JV = require("../../../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. //统一引用models
  16. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  17. require(path.resolve(modelPath));
  18. });
  19. let cfgCacheUtil = require("../../../config/cacheCfg");
  20. cfgCacheUtil.setupDftCache();
  21. let fsUtil = require("../../../public/fsUtil");
  22. let demoPrjId = - 1;
  23. let demoRptId = 232, pagesize = "A4";
  24. // demoPrjId = 720; //QA: DW3
  25. demoPrjId = 2260; //QA:
  26. //*/
  27. // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
  28. let userId_Leng = "5acac1e885bf55000bd055ba";
  29. let userId_Dft = userId_Leng;
  30. /*/
  31. let userId_Dft = "595328da1934dc327cad08eb";
  32. //*/
  33. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  34. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  35. const rptDataExtractor = require("../../../modules/reports/util/rpt_construct_data_util");
  36. const rpt_svg_util = require("../../../modules/reports/util/rpt_svg_util");
  37. let fs = require('fs');
  38. //设置Date Format函数
  39. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  40. eval(data);
  41. });
  42. test('测试 - 测试模板啦: ', function (t) {
  43. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  44. let rptDataUtil = new rptDataExtractor();
  45. rptDataUtil.initialize(rptTpl._doc);
  46. let filter = rptDataUtil.getDataRequestFilter();
  47. //正常应该根据报表模板定义的数据类型来请求数据
  48. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  49. if (!err) {
  50. try {
  51. let tplData = rptDataUtil.assembleData(rawDataObj);
  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);
  59. let maxPages = printCom.totalPages;
  60. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  61. if (pageRst) {
  62. let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
  63. fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_转SVG前.jsp");
  64. fsUtil.writeObjToFile(svgRstStrArr, "D:/GitHome/ConstructionCost/tmp/rptPageResult_SVG格式.jsp");
  65. } else {
  66. console.log("oh! no pages were created!");
  67. }
  68. } catch (ex) {
  69. console.log(ex);
  70. t.pass('pass with exception!');
  71. t.end();
  72. }
  73. t.pass('pass succeeded!');
  74. t.end();
  75. } else {
  76. console.log(msg);
  77. t.pass('pass with error!');
  78. t.end();
  79. }
  80. })
  81. });
  82. });
  83. test('close the connection', function (t) {
  84. setTimeout(function () {
  85. mongoose.disconnect();
  86. t.pass('closing db connection');
  87. t.end();
  88. }, 3000);
  89. });