/**
 * Created by Tony on 2018/8/15.
 */

let test = require('tape');
//const JpcEx = require("../../../modules/reports/rpt_component/jpc_ex");
//const JV = require("../../../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);

//统一引用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 pm_facade = require('../../../modules/pm/facade/pm_facade');

let demoPrjId = - 1;
// let demoRptId = 279;
// let demoRptId = 275; //测试模板-流水式
// let demoRptId = 337; //19表
// let demoRptId = 361; //封1
// let demoRptId = 279; //表04
// let demoRptId = 261; //封3
// let demoRptId = 232; //09
// let demoRptId = 280; //11-1 暂列金
// let demoRptId = 551; //表05
let demoRptId = 710; //表01
// let demoRptId = 2260; //测试基本信息
let pagesize = "A4";
//288: 11-2表(新)
//279: 04

// let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了 QQ号
let userId_Leng = "5acac1e885bf55000bd055ba"; //小冷User Id2
// demoPrjId = 720; //QA: DW3
//demoPrjId = 1626; //QA:
// demoPrjId = 2260; //QA:
// demoPrjId = 4552; //QA:
demoPrjId = 6776; //prod:
//*/
let userId_Dft = userId_Leng;
// let userId_Dft = "5a025c4c15074d134c2b9689";
/*/
 let userId_Dft = "595328da1934dc327cad08eb";
 //*/

let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");

let rptDataExtractor = require("../../../modules/reports/util/rpt_construct_data_util");
let rpt_xl_util = require("../../../modules/reports/util/rpt_excel_util");
let rpt_pdf_util = require("../../../modules/reports/util/rpt_pdf_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) {
    // let s1 = pm_facade.getSummaryInfoByTender(demoPrjId, pm_facade.projectType.engineering);
    let s2 = pm_facade.getSummaryInfoByTender(demoPrjId, pm_facade.projectType.project);
    // s1.then(function (rst1) {
    //     console.log(rst1);
    // });
    s2.then(function (rst2) {
        console.log(rst2);
        t.pass('pass ok!');
        t.end();
    });
});

test('close the connection', function (t) {
    setTimeout(function () {
        mongoose.disconnect();
        t.pass('closing db connection');
        t.end();
    }, 1000);
    // mongoose.disconnect();
    // t.pass('closing db connection');
    // t.end();
});