123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /**
- * Created by Tony on 2017/3/13.
- */
- let fsUtil = require("../../public/fsUtil");
- const rpt_pdf_util = require("../output/rpt_pdf_util");
- const fs = require('fs') ;
- //统一回调函数
- let callback = function(req, res, err, data){
- if(err){
- res.json({success: false, error: err});
- }
- else{
- //res.send({success: true, data: data});
- res.json({success:true, data: data});
- }
- };
- module.exports = {
- restfulTestResponse: function (req, res) {
- console.log('you are calling restfulTestResponse.');
- callback(req, res, null, 'good!');
- },
- restfulTestResponsePost: function (req, res) {
- console.log('you are calling restfulTestResponse by POST way.');
- callback(req, res, null, 'good!');
- },
- createExcelFilesInOneBookEx: function (req, res) {
- //采用了优化策略
- let params = JSON.parse(req.body.params),
- rptPageRstArray = params.rptPageRstArray,
- uuid = params.uuid
- ;
- // if (rpt_ids && rpt_ids.length > 0) {
- // getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
- // if(err){
- // console.log('导出Excel错误(生成数据过程错误), userId: ' + user_id + ', prjId' + prj_id);
- // callback(req, res, '数据有误', null);
- // } else {
- // if ((rpt_bill_tpl_ids && rpt_bill_tpl_ids.length > 0) || (rpt_glj_tpl_ids && rpt_glj_tpl_ids.length > 0)) {
- // getSummaryComboPages(user_id, prjIds, rpt_bill_tpl_ids, rpt_glj_tpl_ids, pageSize, orientation, customizeCfg, option, JV.OUTPUT_TYPE_NORMAL, function (err, rptSumPageRstArray) {
- // rpt_xl_util.exportExcelInOneBook(rptPageRstArray.concat(rptSumPageRstArray), pageSize, rptName, function(uuidName){
- // let fileRst = {uuid: uuidName, reportName: rptName};
- // callback(req, res, err, fileRst);
- // });
- // });
- // } else {
- // rpt_xl_util.exportExcelInOneBook(rptPageRstArray, pageSize, rptName, function(uuidName){
- // let fileRst = {uuid: uuidName, reportName: rptName};
- // callback(req, res, err, fileRst);
- // });
- // }
- // }
- // });
- // }
- },
- createExcelFilesEx: function (req, res) {
- let params = JSON.parse(req.body.params),
- pageSize = params.pageSize,
- isOneSheet = params.isOneSheet,
- rptPageRstArray = params.rptPageRstArray
- ;
- // if (rpt_ids && rpt_ids.length > 0) {
- // getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
- // if (err) {
- // console.log('导出Excel错误(生成数据过程错误), userId: ' + user_id + ', prjId' + prj_id);
- // callback(req, res, '数据生成错误', null);
- // } else {
- // if ((rpt_bill_tpl_ids && rpt_bill_tpl_ids.length > 0) || (rpt_glj_tpl_ids && rpt_glj_tpl_ids.length > 0)) {
- // getSummaryComboPages(user_id, prjIds, rpt_bill_tpl_ids, rpt_glj_tpl_ids, pageSize, orientation, customizeCfg, option, JV.OUTPUT_TYPE_NORMAL, function (err, rptSumPageRstArray) {
- // let parallelFunctions = [];
- // pri_Add_Parallel_Functions(parallelFunctions, rptPageRstArray, rpt_names, err);
- // pri_Add_Parallel_Functions(parallelFunctions, rptSumPageRstArray, sum_rpt_names, err);
- // pri_Run_Parallel_Functions(parallelFunctions);
- // });
- // } else {
- // let parallelFunctions = [];
- // pri_Add_Parallel_Functions(parallelFunctions, rptPageRstArray, rpt_names, err);
- // pri_Run_Parallel_Functions(parallelFunctions);
- // }
- // }
- // });
- // } else if ((rpt_bill_tpl_ids && rpt_bill_tpl_ids.length > 0) || (rpt_glj_tpl_ids && rpt_glj_tpl_ids.length > 0)) {
- // getSummaryComboPages(user_id, prjIds, rpt_bill_tpl_ids, rpt_glj_tpl_ids, pageSize, orientation, customizeCfg, option, JV.OUTPUT_TYPE_NORMAL, function (err, rptSumPageRstArray) {
- // let parallelFunctions = [];
- // pri_Add_Parallel_Functions(parallelFunctions, rptSumPageRstArray, sum_rpt_names, err);
- // pri_Run_Parallel_Functions(parallelFunctions);
- // });
- // }
- },
- createPdfFilesEx: function (req, res) {
- let params = JSON.parse(req.body.params),
- pageSize = params.pageSize,
- rptPageRstArray = params.rptPageRstArray,
- uuidArray = params.uuids
- ;
- // console.log('start!');
- let msg = 'sent the export request!';
- let err = null;
- if (rptPageRstArray instanceof Array && rptPageRstArray.length > 0) {
- for (let rIdx = 0; rIdx < rptPageRstArray.length; rIdx++) {
- try {
- rpt_pdf_util.export_pdf_file(rptPageRstArray[rIdx], pageSize, uuidArray[rIdx], null); // 创建线程来实现build PDF,但无call back
- } catch (ex) {
- if (err) {
- err = err + 'Has error on: ' + rIdx + ' ';
- } else {
- err = 'Has error on: ' + rIdx + ' ';
- }
- }
- }
- }
- callback(req, res, err, msg);
- },
- getFileByUUID: function (req, res) {
- let uuid = req.params.uuid,
- rptName = req.params.rptName,
- suffix = "." + req.params.suffix
- ;
- // let user_id = req.session.sessionUser.id; //未来要校验user id
- try {
- res.setHeader('Content-Type', 'application/vnd.openxmlformats');
- let rptNameURI = encodeURI(rptName);
- res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix );
- let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuid + suffix);
- filestream.on('data', function(chunk) {
- res.write(chunk);
- });
- filestream.on('end', function() {
- res.end();
- });
- } catch (e) {
- console.log(e);
- }
- },
- };
|