|  | @@ -7,7 +7,8 @@ let mongoose = require('mongoose');
 | 
	
		
			
				|  |  |  let JV = require('../rpt_component/jpc_value_define');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  let Template = mongoose.model('rpt_templates');
 | 
	
		
			
				|  |  | -let demoTemplateData = mongoose.model('rpt_temp_tpl_data');
 | 
	
		
			
				|  |  | +let rptTplFacade = require('../facade/rpt_template_facade');
 | 
	
		
			
				|  |  | +let demoTemplateFacade = require('../facade/rpt_tpl_data_demo_facade');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  let JpcEx = require('../rpt_component/jpc_ex');
 | 
	
		
			
				|  |  |  let rptUtil = require("../util/rpt_util");
 | 
	
	
		
			
				|  | @@ -26,14 +27,13 @@ let callback = function(req, res, err, data){
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -function getAllPagesCommon(req, res, rpt_id, pageSize, cb) {
 | 
	
		
			
				|  |  | +function getAllPagesCommonOrg(req, res, rpt_id, pageSize, cb) {
 | 
	
		
			
				|  |  |      let rptTpl = null;
 | 
	
		
			
				|  |  | -    Template.findOne({ID: rpt_id}, '-_id').exec().then(function(rst) {
 | 
	
		
			
				|  |  | +    rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
 | 
	
		
			
				|  |  |          rptTpl = rst;
 | 
	
		
			
				|  |  |          if (rptTpl) {
 | 
	
		
			
				|  |  |              if (rptTpl.ID_KEY) {
 | 
	
		
			
				|  |  | -                //return demoTemplateData.getPromise(rptTpl.ID_KEY);
 | 
	
		
			
				|  |  | -                return demoTemplateData.findOne({"Data_Key": rptTpl.ID_KEY}).exec();
 | 
	
		
			
				|  |  | +                return demoTemplateFacade.getDemoData(rptTpl.ID_KEY);
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  callback(req, res, 'No report template data were found!', null);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -61,11 +61,42 @@ function getAllPagesCommon(req, res, rpt_id, pageSize, cb) {
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +function getAllPagesCommon(req, res, rpt_id, pageSize, cb) {
 | 
	
		
			
				|  |  | +    let rptTpl = null;
 | 
	
		
			
				|  |  | +    rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
 | 
	
		
			
				|  |  | +        rptTpl = rst;
 | 
	
		
			
				|  |  | +        if (rptTpl) {
 | 
	
		
			
				|  |  | +            let tplData = {};
 | 
	
		
			
				|  |  | +            if (rptTpl[JV.NODE_FIELD_MAP]) {
 | 
	
		
			
				|  |  | +                //1. 离散数据
 | 
	
		
			
				|  |  | +                if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS] && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS].leng > 0) {
 | 
	
		
			
				|  |  | +                    tplData[JV.DATA_DISCRETE_DATA] = [];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //2. 主数据
 | 
	
		
			
				|  |  | +                if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS] && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS].leng > 0) {
 | 
	
		
			
				|  |  | +                    tplData[JV.DATA_MASTER_DATA] = [];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //3. 从数据
 | 
	
		
			
				|  |  | +                if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].leng > 0) {
 | 
	
		
			
				|  |  | +                    tplData[JV.DATA_DETAIL_DATA] = [];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //return demoTemplateData.getPromise(rptTpl.ID_KEY);
 | 
	
		
			
				|  |  | +                //return demoTemplateData.findOne({"Data_Key": rptTpl.ID_KEY}).exec();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                callback(req, res, 'No report template data were found!', null);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            callback(req, res, 'No report template was found!', null);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  module.exports = {
 | 
	
		
			
				|  |  |      getReportAllPages: function(req, res){
 | 
	
		
			
				|  |  |          let rpt_id = req.body.ID;
 | 
	
		
			
				|  |  |          let pageSize = req.body.pageSize;
 | 
	
		
			
				|  |  | -        getAllPagesCommon(req, res, rpt_id, pageSize, function(pageRst){
 | 
	
		
			
				|  |  | +        getAllPagesCommonOrg(req, res, rpt_id, pageSize, function(pageRst){
 | 
	
		
			
				|  |  |              //fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
 | 
	
		
			
				|  |  |              callback(req, res, null, pageRst);
 | 
	
		
			
				|  |  |          })
 | 
	
	
		
			
				|  | @@ -76,7 +107,7 @@ module.exports = {
 | 
	
		
			
				|  |  |              rptName = req.params.rptName,
 | 
	
		
			
				|  |  |              isOneSheet = req.params.isOneSheet;
 | 
	
		
			
				|  |  |          ;
 | 
	
		
			
				|  |  | -        getAllPagesCommon(req, res, rpt_id, pageSize, function(pageRst){
 | 
	
		
			
				|  |  | +        getAllPagesCommonOrg(req, res, rpt_id, pageSize, function(pageRst){
 | 
	
		
			
				|  |  |              rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, function(newName){
 | 
	
		
			
				|  |  |                  res.setHeader('Content-Type', 'application/vnd.openxmlformats');
 | 
	
		
			
				|  |  |                  res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
 |