|
@@ -23,77 +23,64 @@ let callback = function(req, res, err, data){
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-module.exports = {
|
|
|
- getReportAllPages: function(req, res){
|
|
|
- let grp_id = req.body.grp_id;
|
|
|
- let tpl_id = req.body.tpl_id;
|
|
|
- let pageSize = req.body.pageSize;
|
|
|
- let rptTpl = null;
|
|
|
- Template.findOne({GROUP_KEY: grp_id, ID_KEY: tpl_id}, '-_id').exec().then(function(rst) {
|
|
|
- rptTpl = rst;
|
|
|
- if (rptTpl) {
|
|
|
- return TemplateData.getPromise(tpl_id);
|
|
|
+function getAllPagesCommon(req, res, rpt_id, pageSize, cb) {
|
|
|
+ let rptTpl = null;
|
|
|
+ Template.findOne({ID: rpt_id}, '-_id').exec().then(function(rst) {
|
|
|
+ rptTpl = rst;
|
|
|
+ if (rptTpl) {
|
|
|
+ if (rptTpl.ID_KEY) {
|
|
|
+ return TemplateData.getPromise(rptTpl.ID_KEY);
|
|
|
} else {
|
|
|
- callback(req, res, 'No report template was found!', null);
|
|
|
+ callback(req, res, 'No report template data were found!', null);
|
|
|
}
|
|
|
- }).then(function(tplData){
|
|
|
- if (tplData) {
|
|
|
- let printCom = JpcEx.createNew();
|
|
|
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
|
|
|
- let defProperties = rptUtil.getReportDefaultCache();
|
|
|
- printCom.initialize(rptTpl);
|
|
|
- printCom.analyzeData(rptTpl, tplData, defProperties);
|
|
|
- let maxPages = printCom.totalPages;
|
|
|
- let 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 template was found!', null);
|
|
|
+ }
|
|
|
+ }).then(function(tplData){
|
|
|
+ if (tplData) {
|
|
|
+ let printCom = JpcEx.createNew();
|
|
|
+ rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
|
|
|
+ let defProperties = rptUtil.getReportDefaultCache();
|
|
|
+ printCom.initialize(rptTpl);
|
|
|
+ printCom.analyzeData(rptTpl, tplData, defProperties);
|
|
|
+ let maxPages = printCom.totalPages;
|
|
|
+ let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
|
|
|
+ if (pageRst) {
|
|
|
+ cb(pageRst);
|
|
|
} else {
|
|
|
- callback(req, res, 'No report data were found!', null);
|
|
|
+ callback(req, res, "Have errors while on going...", null);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ callback(req, res, 'No report data were 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){
|
|
|
+ callback(req, res, null, pageRst);
|
|
|
+ })
|
|
|
},
|
|
|
getExcel: function(req, res) {
|
|
|
- let grp_id = req.params.id, tpl_id = req.params.pm, pageSize = req.params.size, rptName = req.params.rptName;
|
|
|
- let rptTpl = null;
|
|
|
- Template.findOne({GROUP_KEY: grp_id, ID_KEY: tpl_id}, '-_id').exec().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) {
|
|
|
- let printCom = JpcEx.createNew();
|
|
|
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
|
|
|
- let defProperties = rptUtil.getReportDefaultCache();
|
|
|
- printCom.initialize(rptTpl);
|
|
|
- printCom.analyzeData(rptTpl, tplData, defProperties);
|
|
|
- let maxPages = printCom.totalPages;
|
|
|
- let 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=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
|
|
|
- let 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);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
+ let rpt_id = req.params.id,
|
|
|
+ pageSize = req.params.size,
|
|
|
+ rptName = req.params.rptName;
|
|
|
+ getAllPagesCommon(req, res, rpt_id, pageSize, function(pageRst){
|
|
|
+ rpt_xl_util.exportExcel(pageRst, rptName, null, function(newName){
|
|
|
+ res.setHeader('Content-Type', 'application/vnd.openxmlformats');
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
|
|
|
+ let 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();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ })
|
|
|
}
|
|
|
};
|