test_tpl_09_1.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 mongoose = require("mongoose");
  8. let fileUtils = require("../../../modules/common/fileUtils");
  9. let path = require('path');
  10. let dbm = require("../../../config/db/db_manager");
  11. let rpt_cfg = require('./rpt_cfg');
  12. dbm.connect();
  13. //统一引用models
  14. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  15. require(path.resolve(modelPath));
  16. });
  17. //config.setupCache();
  18. let cfgCacheUtil = require("../../../config/cacheCfg");
  19. cfgCacheUtil.setupDftCache();
  20. let fsUtil = require("../../../public/fsUtil");
  21. let demoPrjId = - 1;
  22. let demoRptId = 226, pagesize = "A4";
  23. let userId_Leng = 1142; //小冷User Id
  24. // demoPrjId = 720; //QA: DW3
  25. demoPrjId = 1626; //QA:
  26. //*/
  27. let userId_Dft = userId_Leng;
  28. /*/
  29. let userId_Dft = 76075;
  30. //*/
  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_construct_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. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  42. let rptDataUtil = new rptDataExtractor();
  43. rptDataUtil.initialize(rptTpl._doc);
  44. let filter = rptDataUtil.getDataRequestFilter();
  45. console.log(filter);
  46. //正常应该根据报表模板定义的数据类型来请求数据
  47. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  48. if (!err) {
  49. try {
  50. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.js");
  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. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  63. } else {
  64. console.log("oh! no pages were created!");
  65. }
  66. } catch (ex) {
  67. console.log(ex);
  68. t.pass('pass with exception!');
  69. t.end();
  70. }
  71. t.pass('pass succeeded!');
  72. t.end();
  73. } else {
  74. console.log(msg);
  75. t.pass('pass with error!');
  76. t.end();
  77. }
  78. })
  79. });
  80. });
  81. //*/
  82. /*/
  83. test('测试 - 保存小数位数问题: ', function (t) {
  84. require('./rpt_test_decimal');
  85. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  86. let num = 300000;
  87. let ID = 1;
  88. for (let i = 0.0001; i < 1; (i+=0.0001)) {
  89. let test_doc = {};
  90. test_doc.ID = ID;
  91. test_doc.Value1 = num + i;
  92. test_doc.Value2 = num + i + 0.1 + 0.2;
  93. test_doc.Value3 = parseFloat((num + i + 0.1 + 0.2).toFixed(5));
  94. rpt_decimal_mdl.create(test_doc);
  95. ID++;
  96. }
  97. t.pass('pass save decimal ok!');
  98. t.end();
  99. });
  100. //*/
  101. /*/
  102. test('测试 - 显示保存小数位数问题: ', function (t) {
  103. require('./rpt_test_decimal');
  104. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  105. rpt_decimal_mdl.find({}).then(function (rst) {
  106. //console.log(rst);
  107. if (rst.length > 0) {
  108. fsUtil.writeObjToFile(rst, "D:/GitHome/ConstructionCost/tmp/testDecimalResult.js");
  109. }
  110. t.pass('pass get decimal ok!');
  111. t.end();
  112. });
  113. });
  114. //*/
  115. test('close the connection', function (t) {
  116. setTimeout(function () {
  117. mongoose.disconnect();
  118. t.pass('closing db connection');
  119. t.end();
  120. }, 3000);
  121. // mongoose.disconnect();
  122. // t.pass('closing db connection');
  123. // t.end();
  124. });