/** * Created by Tony on 2017/3/13. */ var JV = require('../rpt_component/Jpc_ValueDefine'); var Template = require('../models/rpt_template'); 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 callback = function(req, res, err, data){ if(err){ //res.send({success: false, error: err}); res.json({success: false, error: err}); } else{ //res.send({success: true, data: data}); res.json({success:true, data: data}); } }; module.exports = { getReportAllPages: function(req, res){ var grp_id = req.body.grp_id; var tpl_id = req.body.tpl_id; var pageSize = req.body.pageSize; 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) { callback(req, res, null, pageRst); } else { callback(req, res, "Have errors while on going...", null); } } else { callback(req, res, 'No report data were found!', null); } } ); }, remove: function(req, res){ } };