|  | @@ -13,10 +13,15 @@ let rptExtCodeModel = mongoose.model("rpt_ext_code_tpl");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  let rptCustCfgFacade = require("../facade/rpt_cust_cfg_facade");
 | 
	
		
			
				|  |  |  let costIndexModel = mongoose.model("costIndexReport");
 | 
	
		
			
				|  |  | +let Rpt_Map_Fld_Mdl = mongoose.model("rpt_mapping_field");
 | 
	
		
			
				|  |  | +let rpt_cfg_mdl = mongoose.model("rpt_cfg");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import JV from "../rpt_component/jpc_value_define";
 | 
	
		
			
				|  |  |  import rttFacade from "../facade/rpt_tpl_tree_node_facade";
 | 
	
		
			
				|  |  |  import CompilationModel from "../../users/models/compilation_model";
 | 
	
		
			
				|  |  | +import fs from "fs";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +let JSZip = require("jszip");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //统一回调函数
 | 
	
		
			
				|  |  |  let callback = function (req, res, err, message, data) {
 | 
	
	
		
			
				|  | @@ -410,6 +415,7 @@ let mExport = {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        });
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    updateRptTpl: function (req, res) {
 | 
	
		
			
				|  |  |      let params = JSON.parse(req.body.params),
 | 
	
		
			
				|  |  |        rptTpl = JSON.parse(params.rptTpl);
 | 
	
	
		
			
				|  | @@ -478,6 +484,51 @@ let mExport = {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        });
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | +  // 导出所有的报表数据
 | 
	
		
			
				|  |  | +  getAllBackupData: async function (req, res) {
 | 
	
		
			
				|  |  | +    try {
 | 
	
		
			
				|  |  | +      const filePath = "./public/highWay_reportBackup.zip";
 | 
	
		
			
				|  |  | +      let rptTemplate = [];
 | 
	
		
			
				|  |  | +      let rptTplTree = [];
 | 
	
		
			
				|  |  | +      let rptConfig = [];
 | 
	
		
			
				|  |  | +      let rptField = [];
 | 
	
		
			
				|  |  | +      await new Promise(async function (resolve) {
 | 
	
		
			
				|  |  | +        rptTemplate = await RptTplModel.find({}, "-_id");
 | 
	
		
			
				|  |  | +        resolve();
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      await new Promise(async function (resolve) {
 | 
	
		
			
				|  |  | +        rptTplTree = await TreeNodeModel.find({}, "-_id");
 | 
	
		
			
				|  |  | +        resolve();
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +      await new Promise(async function (resolve) {
 | 
	
		
			
				|  |  | +        rptConfig = await rpt_cfg_mdl.find({}, "-_id");
 | 
	
		
			
				|  |  | +        resolve();
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +      await new Promise(async function (resolve) {
 | 
	
		
			
				|  |  | +        rptField = await Rpt_Map_Fld_Mdl.find({}, "-_id");
 | 
	
		
			
				|  |  | +        resolve();
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      var zip = new JSZip();
 | 
	
		
			
				|  |  | +      zip.file("报表模板备份.txt", JSON.stringify(rptTemplate));
 | 
	
		
			
				|  |  | +      zip.file("报表树备份.txt", JSON.stringify(rptTplTree));
 | 
	
		
			
				|  |  | +      zip.file("报表配置备份.txt", JSON.stringify(rptConfig));
 | 
	
		
			
				|  |  | +      zip.file("报表指标备份.txt", JSON.stringify(rptField));
 | 
	
		
			
				|  |  | +      // 将Zip打包成Blob对象
 | 
	
		
			
				|  |  | +      zip
 | 
	
		
			
				|  |  | +        .generateNodeStream({ type: "nodebuffer", streamFiles: true })
 | 
	
		
			
				|  |  | +        .pipe(fs.createWriteStream(filePath))
 | 
	
		
			
				|  |  | +        .on("finish", function () {
 | 
	
		
			
				|  |  | +          // JSZip generates a readable stream with a "end" event,
 | 
	
		
			
				|  |  | +          // but is piped here in a writable stream which emits a "finish" event.
 | 
	
		
			
				|  |  | +          console.log("报表模板备份已导出");
 | 
	
		
			
				|  |  | +          callback(req, res, false, "", filePath);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    } catch (e) {
 | 
	
		
			
				|  |  | +      callback(req, res, true, "no result", null);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  function copyRptCfg(src, dest) {
 |