rpt_controller.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Created by Tony on 2017/3/13.
  3. */
  4. var JV = require('../rpt_component/Jpc_ValueDefine');
  5. var Template = require('../models/rpt_template');
  6. var TemplateData = require('../models/rpt_temp_data');
  7. var JpcEx = require('../rpt_component/JpcEx');
  8. //var cache = require('../../../public/cache/cacheUtil');
  9. var rptUtil = require("../util/rpt_util");
  10. //统一回调函数
  11. var callback = function(req, res, err, data){
  12. if(err){
  13. //res.send({success: false, error: err});
  14. res.json({success: false, error: err});
  15. }
  16. else{
  17. //res.send({success: true, data: data});
  18. res.json({success:true, data: data});
  19. }
  20. };
  21. module.exports = {
  22. getReportAllPages: function(req, res){
  23. var grp_id = req.body.grp_id;
  24. var tpl_id = req.body.tpl_id;
  25. var pageSize = req.body.pageSize;
  26. var rptTpl = null;
  27. Template.getPromise(grp_id, tpl_id).then(function(rst) {
  28. rptTpl = rst;
  29. if (rptTpl) {
  30. return TemplateData.getPromise(tpl_id);
  31. } else {
  32. callback(req, res, 'No report template was found!', null);
  33. }
  34. }).then(function(tplData){
  35. if (tplData) {
  36. var printCom = JpcEx.createNew();
  37. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  38. var defProperties = rptUtil.getReportDefaultCache();
  39. printCom.initialize(rptTpl);
  40. printCom.analyzeData(rptTpl, tplData, defProperties);
  41. var maxPages = printCom.totalPages;
  42. var pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  43. if (pageRst) {
  44. callback(req, res, null, pageRst);
  45. } else {
  46. callback(req, res, "Have errors while on going...", null);
  47. }
  48. } else {
  49. callback(req, res, 'No report data were found!', null);
  50. }
  51. }
  52. );
  53. },
  54. remove: function(req, res){
  55. }
  56. };