|  | @@ -2,6 +2,7 @@
 | 
	
		
			
				|  |  |   * Created by Tony on 2017/3/13.
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import UserModel from "../../users/models/user_model";
 | 
	
		
			
				|  |  |  import mongoose from "mongoose";
 | 
	
		
			
				|  |  |  import async from "async";
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -37,7 +38,7 @@ let callback = function(req, res, err, data){
 | 
	
		
			
				|  |  |  const WATERMARK_FONT = {
 | 
	
		
			
				|  |  |      "Name": "宋体",
 | 
	
		
			
				|  |  |      "FontHeight": "32",
 | 
	
		
			
				|  |  | -    "FontColor": "CYAN",
 | 
	
		
			
				|  |  | +    "FontColor": "GOLD",
 | 
	
		
			
				|  |  |      "FontBold": "T",
 | 
	
		
			
				|  |  |      "FontItalic": "F",
 | 
	
		
			
				|  |  |      "FontUnderline": "F",
 | 
	
	
		
			
				|  | @@ -361,8 +362,8 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, custo
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  function fillWaterMark(pageRstArray) {
 | 
	
		
			
				|  |  |      for (const pageRst of pageRstArray) {
 | 
	
		
			
				|  |  | -        if (!pageRst[JV.NODE_FONT_COLLECTION].hasOwnProperty('WaterMark')) {
 | 
	
		
			
				|  |  | -            pageRst[JV.NODE_FONT_COLLECTION]['WaterMark'] = WATERMARK_FONT;
 | 
	
		
			
				|  |  | +        if (!pageRst[JV.NODE_FONT_COLLECTION].hasOwnProperty(JV.PROP_WATERMARK)) {
 | 
	
		
			
				|  |  | +            pageRst[JV.NODE_FONT_COLLECTION][JV.PROP_WATERMARK] = WATERMARK_FONT;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          for (const page of pageRst.items) {
 | 
	
		
			
				|  |  |              const warterCell = {
 | 
	
	
		
			
				|  | @@ -377,12 +378,12 @@ function fillWaterMark(pageRstArray) {
 | 
	
		
			
				|  |  |                      "Bottom": 500
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  | -            page.cells.push(warterCell);
 | 
	
		
			
				|  |  | +            //page.cells.push(warterCell);
 | 
	
		
			
				|  |  | +            page.cells.unshift(warterCell);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  module.exports = {
 | 
	
		
			
				|  |  |      getReportAllPages: function (req, res) {
 | 
	
		
			
				|  |  |          let params = JSON.parse(req.body.params),
 | 
	
	
		
			
				|  | @@ -395,7 +396,22 @@ module.exports = {
 | 
	
		
			
				|  |  |          // req.session.sessionUser.ssoId
 | 
	
		
			
				|  |  |          let user_id = req.session.sessionUser.id;
 | 
	
		
			
				|  |  |          getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
 | 
	
		
			
				|  |  | -            callback(req, res, err, pageRst);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                let userModel = new UserModel();
 | 
	
		
			
				|  |  | +                // console.log('req.session.sessionUser.ssoId: ' + req.session.sessionUser.ssoId);
 | 
	
		
			
				|  |  | +                userModel.isFree(req.session.sessionUser.ssoId, params.compilation).then(function(rst) {
 | 
	
		
			
				|  |  | +                    // console.log('is Free user? ' + rst);
 | 
	
		
			
				|  |  | +                    if (rst) {
 | 
	
		
			
				|  |  | +                        //加水印!
 | 
	
		
			
				|  |  | +                        // fillWaterMark([pageRst]);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    callback(req, res, err, pageRst);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            } catch (error) {
 | 
	
		
			
				|  |  | +                //
 | 
	
		
			
				|  |  | +            } finally {
 | 
	
		
			
				|  |  | +                //callback(req, res, err, pageRst);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      getMultiReports: function (req, res) {
 | 
	
	
		
			
				|  | @@ -698,105 +714,6 @@ module.exports = {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          })
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    },
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    getTestReportAllPages: function(req, res){
 | 
	
		
			
				|  |  | -        let rpt_id = req.body.ID;
 | 
	
		
			
				|  |  | -        let pageSize = req.body.pageSize;
 | 
	
		
			
				|  |  | -        getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
 | 
	
		
			
				|  |  | -            //fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
 | 
	
		
			
				|  |  | -            callback(req, res, err, pageRst);
 | 
	
		
			
				|  |  | -        })
 | 
	
		
			
				|  |  | -    },
 | 
	
		
			
				|  |  | -    getTestExcel: function(req, res) {
 | 
	
		
			
				|  |  | -        let rpt_id = req.params.id,
 | 
	
		
			
				|  |  | -            pageSize = req.params.size,
 | 
	
		
			
				|  |  | -            rptName = req.params.rptName,
 | 
	
		
			
				|  |  | -            isOneSheet = req.params.isOneSheet,
 | 
	
		
			
				|  |  | -            option = req.params.option;
 | 
	
		
			
				|  |  | -        let dftOption = option||JV.PAGING_OPTION_NORMAL;
 | 
	
		
			
				|  |  | -        getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function(err, pageRst){
 | 
	
		
			
				|  |  | -            fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
 | 
	
		
			
				|  |  | -            try {
 | 
	
		
			
				|  |  | -                rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, null, null, function(uuidName){
 | 
	
		
			
				|  |  | -                    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/' + uuidName + '.xlsx');
 | 
	
		
			
				|  |  | -                    filestream.on('data', function(chunk) {
 | 
	
		
			
				|  |  | -                        res.write(chunk);
 | 
	
		
			
				|  |  | -                    });
 | 
	
		
			
				|  |  | -                    filestream.on('end', function() {
 | 
	
		
			
				|  |  | -                        res.end();
 | 
	
		
			
				|  |  | -                    });
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -            } catch (e) {
 | 
	
		
			
				|  |  | -                console.log(e);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        })
 | 
	
		
			
				|  |  | -    },
 | 
	
		
			
				|  |  | -    getTestExcelInOneBook: function(req, res) {
 | 
	
		
			
				|  |  | -        let rpt_ids = req.params.ids.split(','),
 | 
	
		
			
				|  |  | -            pageSize = req.params.size,
 | 
	
		
			
				|  |  | -            rptName = req.params.rptName,
 | 
	
		
			
				|  |  | -            option = req.params.option;
 | 
	
		
			
				|  |  | -        let parallelFunctions = [];
 | 
	
		
			
				|  |  | -        let dftOption = option||JV.PAGING_OPTION_NORMAL;
 | 
	
		
			
				|  |  | -        for (let id of rpt_ids) {
 | 
	
		
			
				|  |  | -            parallelFunctions.push((function (rpt_id) {
 | 
	
		
			
				|  |  | -                return function (cb) {
 | 
	
		
			
				|  |  | -                    getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function (err, pageRst) {
 | 
	
		
			
				|  |  | -                        if(err){
 | 
	
		
			
				|  |  | -                            cb(err);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        else{
 | 
	
		
			
				|  |  | -                            cb(null, pageRst);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    })
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            })(parseInt(id)));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        async.parallel(parallelFunctions, function (err, pageRstArray) {
 | 
	
		
			
				|  |  | -            if (err) {
 | 
	
		
			
				|  |  | -                callback(req, res, '数据有误', null);
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(tmpFilePath){
 | 
	
		
			
				|  |  | -                    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/' + tmpFilePath + '.xlsx');
 | 
	
		
			
				|  |  | -                    filestream.on('data', function(chunk) {
 | 
	
		
			
				|  |  | -                        res.write(chunk);
 | 
	
		
			
				|  |  | -                    });
 | 
	
		
			
				|  |  | -                    filestream.on('end', function() {
 | 
	
		
			
				|  |  | -                        res.end();
 | 
	
		
			
				|  |  | -                    });
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -                //callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        })
 | 
	
		
			
				|  |  | -    },
 | 
	
		
			
				|  |  | -    getTestPDF:function (req, res) {
 | 
	
		
			
				|  |  | -        let rpt_id = req.params.id,
 | 
	
		
			
				|  |  | -            pageSize = req.params.size,
 | 
	
		
			
				|  |  | -            rptName = req.params.rptName;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
 | 
	
		
			
				|  |  | -            rpt_pdf_util.export_pdf_file(pageRst, pageSize, rptName,function (uuidName) {
 | 
	
		
			
				|  |  | -                res.setHeader('Content-Type', 'application/vnd.openxmlformats');
 | 
	
		
			
				|  |  | -                // res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".pdf");
 | 
	
		
			
				|  |  | -                let rptNameURI = encodeURI(rptName);
 | 
	
		
			
				|  |  | -                res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".pdf\"; filename*=utf-8''" + rptNameURI + ".pdf"  );
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.pdf');
 | 
	
		
			
				|  |  | -                filestream.on('data', function(chunk) {
 | 
	
		
			
				|  |  | -                    res.write(chunk);
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -                filestream.on('end', function() {
 | 
	
		
			
				|  |  | -                    res.end();
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -            })
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        })
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 |