test_tpl_09_1.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * Created by Tony on 2017/10/18.
  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. //统一引用models
  16. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  17. require(path.resolve(modelPath));
  18. });
  19. //config.setupCache();
  20. let cfgCacheUtil = require("../../../config/cacheCfg");
  21. cfgCacheUtil.setupDftCache();
  22. let fsUtil = require("../../../public/fsUtil");
  23. let demoPrjId = - 1;
  24. let demoRptId = 226, pagesize = "A4";
  25. let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
  26. // demoPrjId = 720; //QA: DW3
  27. demoPrjId = 1626; //QA:
  28. //*/
  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. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  36. let fs = require('fs');
  37. //设置Date Format函数
  38. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  39. eval(data);
  40. });
  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. console.log(filter);
  48. //正常应该根据报表模板定义的数据类型来请求数据
  49. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  50. if (!err) {
  51. try {
  52. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject_建筑09-1表.jsp");
  53. let tplData = rptDataUtil.assembleData(rawDataObj);
  54. // fsUtil.writeObjToFile(tplData, "D:/GitHome/ConstructionCost/tmp/rptTplAssembledData_建筑09-1表.jsp");
  55. //it's time to build the report!!!
  56. let printCom = JpcEx.createNew();
  57. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  58. let defProperties = rpt_cfg;
  59. let dftOption = JV.PAGING_OPTION_NORMAL;
  60. printCom.initialize(rptTpl);
  61. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  62. let maxPages = printCom.totalPages;
  63. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  64. if (pageRst) {
  65. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_建筑09-1表.jsp");
  66. } else {
  67. console.log("oh! no pages were created!");
  68. }
  69. } catch (ex) {
  70. console.log(ex);
  71. t.pass('pass with exception!');
  72. t.end();
  73. }
  74. t.pass('pass succeeded!');
  75. t.end();
  76. } else {
  77. console.log(msg);
  78. t.pass('pass with error!');
  79. t.end();
  80. }
  81. })
  82. });
  83. });
  84. //*/
  85. /*/
  86. test('测试 - 保存小数位数问题: ', function (t) {
  87. require('./rpt_test_decimal');
  88. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  89. let num = 300000;
  90. let ID = 1;
  91. for (let i = 0.0001; i < 1; (i+=0.0001)) {
  92. let test_doc = {};
  93. test_doc.ID = ID;
  94. test_doc.Value1 = num + i;
  95. test_doc.Value2 = num + i + 0.1 + 0.2;
  96. test_doc.Value3 = parseFloat((num + i + 0.1 + 0.2).toFixed(5));
  97. rpt_decimal_mdl.create(test_doc);
  98. ID++;
  99. }
  100. t.pass('pass save decimal ok!');
  101. t.end();
  102. });
  103. //*/
  104. /*/
  105. test('测试 - 显示保存小数位数问题: ', function (t) {
  106. require('./rpt_test_decimal');
  107. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  108. rpt_decimal_mdl.find({}).then(function (rst) {
  109. //console.log(rst);
  110. if (rst.length > 0) {
  111. fsUtil.writeObjToFile(rst, "D:/GitHome/ConstructionCost/tmp/testDecimalResult.jsp");
  112. }
  113. t.pass('pass get decimal ok!');
  114. t.end();
  115. });
  116. });
  117. //*/
  118. test('close the connection', function (t) {
  119. setTimeout(function () {
  120. mongoose.disconnect();
  121. t.pass('closing db connection');
  122. t.end();
  123. }, 1000);
  124. // mongoose.disconnect();
  125. // t.pass('closing db connection');
  126. // t.end();
  127. });