| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /**
- * Created by Tony on 2019/3/27.
- */
- let test = require('tape');
- import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
- import JV from "../../../modules/reports/rpt_component/jpc_value_define";
- let config = require("../../../config/config.js");
- config.setupDb(process.env.NODE_ENV);
- let mongoose = require("mongoose");
- let fileUtils = require("../../../modules/common/fileUtils");
- let path = require('path');
- let dbm = require("../../../config/db/db_manager");
- let rpt_cfg = require('./rpt_cfg');
- dbm.connect(process.env.NODE_ENV);
- let demoPrjs = [1510, 1511]; //
- // let demoRptId = 68; //01-2
- let demoRptId = 72; //01-1
- // let demoRptId = 73; //02-2
- let pagesize = "A4";
- let userId_Leng = "5c3ffa9aa0a92732f41216e0"; //小冷User Id (养护的)
- // let userId_me = "5b6a60b1c4ba33000dd417c0"; //我的
- let userId_Dft = userId_Leng;
- //统一引用models
- fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
- require(path.resolve(modelPath));
- });
- //config.setupCache();
- let cfgCacheUtil = require("../../../config/cacheCfg");
- cfgCacheUtil.setupDftCache();
- let fsUtil = require("../../../public/fsUtil");
- let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
- let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
- import rptDataExtractor from "../../../modules/reports/util/rpt_yanghu_data_util";
- let fs = require('fs');
- //设置Date Format函数
- fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
- eval(data);
- });
- //*
- test('测试 - 测试清单汇总: ', function (t) {
- rptTplDataFacade.getBudgetSummayDatas(demoPrjs).then(function(summaryRst) {
- //console.log(summaryRst);
- rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
- try {
- let dt = new Date();
- fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)原始数据.jsp");
- let rptDataUtil = new rptDataExtractor();
- rptDataUtil.initialize(rptTpl._doc);
- let tplData = rptDataUtil.assembleData(summaryRst);
- // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)整理后数据.jsp");
- // fsUtil.writeObjToFile(tplData, "D:/GitHome/YangHuCost/tmp/rptTplAssembledData_测试模板.jsp");
- //it's time to build the report!!!
- let printCom = JpcEx.createNew();
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
- let defProperties = rpt_cfg;
- let dftOption = JV.PAGING_OPTION_NORMAL;
- printCom.initialize(rptTpl);
- printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
- let maxPages = printCom.totalPages;
- let customizeCfg = {"fillZero": true};
- let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
- if (pageRst) {
- // fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)page数据" + dt.getTime() + ".jsp");
- // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
- // console.log("excel uuid: " + uuidName);
- // });
- // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
- // console.log("pdf uuid: " + uuidName);
- // });
- } else {
- console.log("oh! no pages were created!");
- }
- } catch (ex) {
- console.log(ex);
- t.pass('pass with exception!');
- t.end();
- }
- t.pass('pass succeeded!');
- t.end();
- });
- });
- });
- /*/
- test('测试 - 测试工料机汇总: ', function (t) {
- rptTplDataFacade.getGLJSummayDatas(demoPrjs).then(function(summaryRst) {
- // console.log(summaryRst);
- rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
- try {
- let dt = new Date();
- // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/02_2原始数据.jsp");
- let rptDataUtil = new rptDataExtractor();
- rptDataUtil.initialize(rptTpl._doc);
- let tplData = rptDataUtil.assembleData(summaryRst);
- // fsUtil.writeObjToFile(summaryRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(01_2)整理后数据.jsp");
- // fsUtil.writeObjToFile(tplData, "D:/GitHome/YangHuCost/tmp/rptTplAssembledData_测试模板.jsp");
- //it's time to build the report!!!
- let printCom = JpcEx.createNew();
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
- let defProperties = rpt_cfg;
- let dftOption = JV.PAGING_OPTION_NORMAL;
- printCom.initialize(rptTpl);
- printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
- let maxPages = printCom.totalPages;
- let customizeCfg = {"fillZero": true};
- let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
- if (pageRst) {
- fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/多清单汇总表(02_2)page数据" + dt.getTime() + ".jsp");
- // rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
- // console.log("excel uuid: " + uuidName);
- // });
- // rpt_pdf_util.export_pdf_file(pageRst, pagesize, 'local_test_rpt_pdf', function(uuidName){
- // console.log("pdf uuid: " + uuidName);
- // });
- } else {
- console.log("oh! no pages were created!");
- }
- } catch (ex) {
- console.log(ex);
- t.pass('pass with exception!');
- t.end();
- }
- t.pass('pass succeeded!');
- t.end();
- });
- });
- });
- //*/
- test('close the connection', function (t) {
- setTimeout(function () {
- mongoose.disconnect();
- t.pass('closing db connection');
- t.end();
- }, 1000);
- });
|