test_tpl_09_1.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. let consts = require('../../../modules/main/models/project_consts');
  14. let projectConsts = consts.projectConst;
  15. fileUtils.getGlobbedFiles('../../../modules/complementary_glj_lib/models/*.js').forEach(function(modelPath) {
  16. require(path.resolve(modelPath));
  17. });
  18. fileUtils.getGlobbedFiles('../../../modules/ration_glj/models/*.js').forEach(function(modelPath) {
  19. require(path.resolve(modelPath));
  20. });
  21. //引入报表模块
  22. fileUtils.getGlobbedFiles('../../../modules/reports/models/*.js').forEach(function(modelPath) {
  23. require(path.resolve(modelPath));
  24. })
  25. //暂时引入其它模块的model
  26. require('../../../modules/fee_rates/models/fee_rates');
  27. // 引入人工系数模块
  28. require('../../../modules/main/models/labour_coe_model');
  29. require('../../../modules/main/models/calc_program_model');
  30. let fsUtil = require("../../../public/fsUtil");
  31. let prjMdl = require('../../../modules/pm/models/project_model');
  32. let projectDataMdl = require('../../../modules/main/models/project');
  33. let demoPrjId = - 1;
  34. let demoRptId = 226, pagesize = "A4";
  35. let userId_Leng = 1142; //小冷User Id
  36. demoPrjId = 720; //QA: DW3
  37. /*/
  38. let userId_Dft = userId_Leng;
  39. /*/
  40. let userId_Dft = 76075;
  41. //*/
  42. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  43. let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
  44. import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
  45. let fs = require('fs');
  46. //设置Date Format函数
  47. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  48. eval(data);
  49. });
  50. /*/
  51. test('测试 - 获取project数据: ', function (t) {
  52. projectDataMdl.getData(demoPrjId, function (err, message, result) {
  53. if (!err) {
  54. fsUtil.wirteObjToFile(result, "D:/GitHome/ConstructionCost/tmp/ProjectDataFullObject.js");
  55. t.pass('pass succeeded!');
  56. t.end();
  57. } else {
  58. //callback(req, res, err, message, null);
  59. t.pass('pass failed!');
  60. t.end();
  61. }
  62. });
  63. });
  64. //*/
  65. /*/
  66. test('测试 - 获取project部分数据: ', function (t) {
  67. let filter = [];
  68. filter.push(projectConsts.BILLS);
  69. filter.push(projectConsts.RATION);
  70. filter.push(projectConsts.RATION_GLJ);
  71. filter.push(projectConsts.PROJECTGLJ);
  72. filter.push(projectConsts.FEERATE);
  73. filter.push(projectConsts.CALC_PROGRAM);
  74. prjMdl.project.getUserProject(userId_Dft, demoPrjId, function(err, msg, prjObj){
  75. if (!err) {
  76. projectDataMdl.getFilterData(demoPrjId, filter, function (results) {
  77. if (results) {
  78. // let newData = [];
  79. // for (let item of results) {
  80. // newData.push(JSON.stringify(item));
  81. // }
  82. // fsUtil.writeArrayToFile(newData, "D:/GitHome/ConstructionCost/tmp/getProjectData_partial.js");
  83. fsUtil.wirteObjToFile(prjObj, "D:/GitHome/ConstructionCost/tmp/getProjectObjectNew.js");
  84. fsUtil.wirteObjToFile(results, "D:/GitHome/ConstructionCost/tmp/getProjectData_partialNew.js");
  85. t.pass('pass succeeded!');
  86. t.end();
  87. } else {
  88. //callback(req, res, err, message, null);
  89. t.pass('get project data failed!');
  90. t.end();
  91. }
  92. });
  93. } else {
  94. t.pass('get project failed!');
  95. t.end();
  96. }
  97. });
  98. });
  99. //*/
  100. //*
  101. test('测试 - 测试模板啦: ', function (t) {
  102. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  103. let rptDataUtil = new rptDataExtractor();
  104. rptDataUtil.initialize(rptTpl._doc);
  105. let filter = rptDataUtil.getDataRequestFilter();
  106. console.log(filter);
  107. //正常应该根据报表模板定义的数据类型来请求数据
  108. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filter, function (err, msg, rawDataObj) {
  109. if (!err) {
  110. try {
  111. let tplData = rptDataUtil.assembleData(rawDataObj);
  112. // fsUtil.wirteObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/rptTplRawDataObject.js");
  113. //it's time to build the report!!!
  114. let printCom = JpcEx.createNew();
  115. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  116. let defProperties = rpt_cfg;
  117. let dftOption = JV.PAGING_OPTION_NORMAL;
  118. printCom.initialize(rptTpl);
  119. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption);
  120. let maxPages = printCom.totalPages;
  121. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  122. if (pageRst) {
  123. fsUtil.wirteObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.js");
  124. } else {
  125. console.log("oh! no pages were created!")
  126. }
  127. } catch (ex) {
  128. console.log(ex);
  129. t.pass('pass with exception!');
  130. t.end();
  131. }
  132. t.pass('pass succeeded!');
  133. t.end();
  134. } else {
  135. console.log(msg);
  136. t.pass('pass with error!');
  137. t.end();
  138. }
  139. })
  140. });
  141. });
  142. //*/
  143. /*/
  144. test('测试 - 保存小数位数问题: ', function (t) {
  145. require('./rpt_test_decimal');
  146. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  147. let num = 300000;
  148. let ID = 1;
  149. for (let i = 0.0001; i < 1; (i+=0.0001)) {
  150. let test_doc = {};
  151. test_doc.ID = ID;
  152. test_doc.Value1 = num + i;
  153. test_doc.Value2 = num + i + 0.1 + 0.2;
  154. test_doc.Value3 = parseFloat((num + i + 0.1 + 0.2).toFixed(5));
  155. rpt_decimal_mdl.create(test_doc);
  156. ID++;
  157. }
  158. t.pass('pass save decimal ok!');
  159. t.end();
  160. });
  161. //*/
  162. /*/
  163. test('测试 - 显示保存小数位数问题: ', function (t) {
  164. require('./rpt_test_decimal');
  165. let rpt_decimal_mdl = mongoose.model("rpt_decimal_test");
  166. rpt_decimal_mdl.find({}).then(function (rst) {
  167. //console.log(rst);
  168. if (rst.length > 0) {
  169. fsUtil.wirteObjToFile(rst, "D:/GitHome/ConstructionCost/tmp/testDecimalResult.js");
  170. }
  171. t.pass('pass get decimal ok!');
  172. t.end();
  173. });
  174. });
  175. //*/
  176. test('close the connection', function (t) {
  177. setTimeout(function () {
  178. mongoose.disconnect();
  179. t.pass('closing db connection');
  180. t.end();
  181. }, 3000);
  182. // mongoose.disconnect();
  183. // t.pass('closing db connection');
  184. // t.end();
  185. });