|  | @@ -8,6 +8,8 @@ var TemplateData = require('../models/rpt_temp_data');
 | 
	
		
			
				|  |  |  var JpcEx = require('../rpt_component/JpcEx');
 | 
	
		
			
				|  |  |  //var cache = require('../../../public/cache/cacheUtil');
 | 
	
		
			
				|  |  |  var rptUtil = require("../util/rpt_util");
 | 
	
		
			
				|  |  | +var rpt_xl_util = require('../util/rpt_excel_util');
 | 
	
		
			
				|  |  | +var fs = require('fs');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //统一回调函数
 | 
	
		
			
				|  |  |  var callback = function(req, res, err, data){
 | 
	
	
		
			
				|  | @@ -54,6 +56,46 @@ module.exports = {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | +    getExcel: function(req, res) {
 | 
	
		
			
				|  |  | +        var grp_id = req.params.id, tpl_id = req.params.pm, pageSize = req.params.size, rptName = req.params.rptName;
 | 
	
		
			
				|  |  | +        var rptTpl = null;
 | 
	
		
			
				|  |  | +        Template.getPromise(grp_id, tpl_id).then(function(rst) {
 | 
	
		
			
				|  |  | +            rptTpl = rst;
 | 
	
		
			
				|  |  | +            if (rptTpl) {
 | 
	
		
			
				|  |  | +                return TemplateData.getPromise(tpl_id);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                callback(req, res, 'No report template was found!', null);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }).then(function(tplData){
 | 
	
		
			
				|  |  | +                if (tplData) {
 | 
	
		
			
				|  |  | +                    var printCom = JpcEx.createNew();
 | 
	
		
			
				|  |  | +                    rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
 | 
	
		
			
				|  |  | +                    var defProperties = rptUtil.getReportDefaultCache();
 | 
	
		
			
				|  |  | +                    printCom.initialize(rptTpl);
 | 
	
		
			
				|  |  | +                    printCom.analyzeData(rptTpl, tplData, defProperties);
 | 
	
		
			
				|  |  | +                    var maxPages = printCom.totalPages;
 | 
	
		
			
				|  |  | +                    var pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
 | 
	
		
			
				|  |  | +                    if (pageRst) {
 | 
	
		
			
				|  |  | +                        rpt_xl_util.exportExcel(pageRst, rptName, null, function(newName){
 | 
	
		
			
				|  |  | +                            res.setHeader('Content-Type', 'application/vnd.openxmlformats');
 | 
	
		
			
				|  |  | +                            res.setHeader("Content-Disposition", "attachment; filename=" + rptName + ".xlsx");
 | 
	
		
			
				|  |  | +                            var filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + newName + '.xlsx');
 | 
	
		
			
				|  |  | +                            filestream.on('data', function(chunk) {
 | 
	
		
			
				|  |  | +                                res.write(chunk);
 | 
	
		
			
				|  |  | +                            });
 | 
	
		
			
				|  |  | +                            filestream.on('end', function() {
 | 
	
		
			
				|  |  | +                                res.end();
 | 
	
		
			
				|  |  | +                            });
 | 
	
		
			
				|  |  | +                        });
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        callback(req, res, "Have errors while on going...", null);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    callback(req, res, 'No report data were found!', null);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |      getDummyExcel: function(req, res) {
 | 
	
		
			
				|  |  |          var nodeExcel = require('excel-export'); //关联excel-export模块
 | 
	
		
			
				|  |  |          console.log("req.params.id:" + req.params.id);
 |