rpt_controller.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /**
  2. * Created by Tony on 2017/3/13.
  3. */
  4. import mongoose from "mongoose";
  5. import async from "async";
  6. import JV from "../rpt_component/jpc_value_define";
  7. let Template = mongoose.model('rpt_templates');
  8. let rptTplDataFacade = require("../facade/rpt_tpl_data_facade");
  9. let fsUtil = require("../../../public/fsUtil");
  10. let pm_facade = require('../../../modules/pm/facade/pm_facade');
  11. import rptTplFacade from "../facade/rpt_template_facade";
  12. import demoTemplateFacade from "../facade/rpt_tpl_data_demo_facade";
  13. import JpcEx from "../rpt_component/jpc_ex";
  14. import rptUtil from "../util/rpt_util";
  15. import rpt_xl_util from "../util/rpt_excel_util";
  16. import rpt_pdf_util from "../util/rpt_pdf_util";
  17. import rpt_svg_util from "../util/rpt_svg_util";
  18. import fs from "fs";
  19. import strUtil from "../../../public/stringUtil";
  20. import rptDataExtractor from "../util/rpt_yanghu_data_util";
  21. //统一回调函数
  22. let callback = function(req, res, err, data){
  23. if(err){
  24. res.json({success: false, error: err});
  25. }
  26. else{
  27. //res.send({success: true, data: data});
  28. res.json({success:true, data: data});
  29. }
  30. };
  31. function getAllPagesCommonOrg(rpt_id, pageSize, option, cb) {
  32. let rptTpl = null;
  33. rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
  34. rptTpl = rst;
  35. if (rptTpl) {
  36. if (rptTpl.ID_KEY) {
  37. return demoTemplateFacade.getDemoData(rptTpl.ID_KEY);
  38. } else {
  39. //callback(req, res, 'No report template data were found!', null);
  40. cb('No report template data were found!', null);
  41. }
  42. } else {
  43. //callback(req, res, 'No report template was found!', null);
  44. cb('No report template was found!', null);
  45. }
  46. }).then(function(tplData){
  47. if (tplData) {
  48. let printCom = JpcEx.createNew();
  49. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  50. let defProperties = rptUtil.getReportDefaultCache();
  51. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  52. printCom.initialize(rptTpl);
  53. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_NORMAL);
  54. let maxPages = printCom.totalPages;
  55. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  56. if (pageRst) {
  57. cb(null, pageRst);
  58. } else {
  59. //callback(req, res, "Have errors while on going...", null);
  60. cb('Have errors while on going...', null);
  61. }
  62. } else {
  63. //callback(req, res, 'No report data were found!', null);
  64. cb('No report data were found!', null);
  65. }
  66. }
  67. );
  68. }
  69. function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
  70. let tmpObj = {};
  71. //1. 字体
  72. let newFonts = [];
  73. for (let font of defProperties.fonts) {
  74. let copyFont = {};
  75. copyFont.ID = font.ID;
  76. for (let fontProp of JV.FONT_PROPS) {
  77. copyFont[fontProp] = font[fontProp];
  78. }
  79. newFonts.push(copyFont);
  80. tmpObj[font.ID] = copyFont;
  81. }
  82. let private_setup_font = function (propStr, newFont) {
  83. if (tmpObj[propStr]) {
  84. tmpObj[propStr].Name = newFont.Name;
  85. tmpObj[propStr].FontHeight = String(newFont.FontHeight);
  86. tmpObj[propStr].FontBold = newFont.FontBold;
  87. tmpObj[propStr].FontItalic = newFont.FontItalic;
  88. tmpObj[propStr].FontUnderline = newFont.FontUnderline;
  89. }
  90. };
  91. for (let custFont of customizeCfg.fonts) {
  92. switch (custFont.CfgDispName) {
  93. case "表标题":
  94. private_setup_font("ReportTitle_Main", custFont);
  95. break;
  96. case "列标题":
  97. private_setup_font("HeaderColumn", custFont);
  98. private_setup_font("FooterColumn", custFont);
  99. break;
  100. case "正文内容":
  101. private_setup_font("Content", custFont);
  102. break;
  103. case "合计":
  104. private_setup_font("GrandTotal", custFont);
  105. private_setup_font("SectionTotal", custFont);
  106. break;
  107. case "表眉/表脚":
  108. private_setup_font("Header", custFont);
  109. private_setup_font("Footer", custFont);
  110. break;
  111. }
  112. }
  113. // 1.1 窄体
  114. if (tmpObj["Content_Narrow"]) {
  115. if (customizeCfg.isNarrow) {
  116. tmpObj["Content_Narrow"].Name = "Arial Narrow";
  117. } else {
  118. if (tmpObj["Content"]) {
  119. tmpObj["Content_Narrow"].Name = tmpObj["Content"].Name;
  120. } else {
  121. tmpObj["Content_Narrow"].Name = "宋体";
  122. }
  123. }
  124. }
  125. defProperties.fonts = newFonts;
  126. //2. 页边距
  127. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = customizeCfg.margins[JV.PROP_LEFT] / 10;
  128. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = customizeCfg.margins[JV.PROP_RIGHT] / 10;
  129. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = customizeCfg.margins[JV.PROP_TOP] / 10;
  130. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = customizeCfg.margins[JV.PROP_BOTTOM] / 10;
  131. //3. 边框竖线
  132. if (!(customizeCfg.showVerticalLine)) {
  133. let private_copy_border = function (src) {
  134. let rst = {};
  135. rst.Position = src.Position;
  136. rst.LineWeight = src.LineWeight;
  137. rst.DashStyle = src.DashStyle;
  138. rst.Color = src.Color;
  139. return rst;
  140. };
  141. let newStyles = [];
  142. for (let i =0 ; i < defProperties.styles.length; i++) {
  143. let style = defProperties.styles[i];
  144. newStyles.push(style);
  145. if (style.ID === "BORDER_ALL_AROUND") {
  146. let newStyle = {};
  147. newStyle.ID = style.ID;
  148. newStyle.CfgDispName = style.CfgDispName;
  149. newStyle.border_style = [];
  150. for (let border of style.border_style) {
  151. let newBorder = private_copy_border(border);
  152. newStyle.border_style.push(newBorder);
  153. if (border.Position === "Left" || border.Position === "Right") {
  154. newBorder.LineWeight = 0;
  155. }
  156. }
  157. newStyles[newStyles.length - 1] = newStyle;
  158. }
  159. }
  160. defProperties.styles = newStyles;
  161. }
  162. //4. 补0
  163. let private_Setup_Format = function(tabFields) {
  164. if (tabFields) {
  165. for (let tabField of tabFields) {
  166. if (tabField[JV.PROP_FORMAT]) {
  167. tabField[JV.PROP_FORMAT] = tabField[JV.PROP_FORMAT].replace(new RegExp("#","gm"),"0");
  168. }
  169. }
  170. }
  171. };
  172. if (customizeCfg.fillZero) {
  173. if (rptTpl[JV.NODE_FLOW_INFO]) {
  174. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
  175. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
  176. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
  177. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES])
  178. private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  179. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  180. for (let discrete of rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  181. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  182. }
  183. }
  184. if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
  185. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
  186. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
  187. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
  188. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_SUM_FIELDS]);
  189. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES])
  190. private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  191. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  192. for (let discrete of rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  193. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  194. }
  195. }
  196. }
  197. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  198. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT][JV.PROP_BILL_FIELDS]);
  199. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  200. for (let discrete of rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  201. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  202. }
  203. }
  204. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  205. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT][JV.TAB_CROSS_FIELDS]);
  206. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW][JV.TAB_CROSS_FIELDS]);
  207. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL][JV.TAB_CROSS_FIELDS]);
  208. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM][JV.TAB_CROSS_FIELDS]);
  209. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT][JV.TAB_CROSS_FIELDS]);
  210. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT][JV.TAB_CROSS_FIELDS]);
  211. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  212. for (let discrete of rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  213. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  214. }
  215. }
  216. }
  217. }
  218. }
  219. function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
  220. let rptTpl = null;
  221. rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
  222. rptTpl = rst;
  223. if (rptTpl) {
  224. let rptDataUtil = new rptDataExtractor();
  225. rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
  226. let summaryRst = [];
  227. let filter = rptDataUtil.getDataRequestFilter(summaryRst);
  228. let promiseArr = [null, null];
  229. if (summaryRst.length > 0) {
  230. if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
  231. promiseArr[0] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.project);
  232. }
  233. if (summaryRst.indexOf(`Segment`) >= 0 || summaryRst.indexOf(`SegmentDetail`) >= 0) {
  234. promiseArr[1] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.engineering);
  235. }
  236. }
  237. rptTplDataFacade.prepareProjectData(user_id, prj_id, filter, function (err, msg, rawDataObj) {
  238. if (!err) {
  239. let buildPageData = function() {
  240. try {
  241. let tplData = rptDataUtil.assembleData(rawDataObj);
  242. let printCom = JpcEx.createNew();
  243. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  244. //console.log("orientation: " + (orientation === 'null'));
  245. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  246. let defProperties = rptUtil.getReportDefaultCache();
  247. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  248. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  249. printCom.initialize(rptTpl);
  250. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  251. let maxPages = printCom.totalPages;
  252. let pageRst = null;
  253. if (maxPages > 0) {
  254. pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  255. } else {
  256. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  257. }
  258. if (pageRst) {
  259. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  260. cb(null, pageRst);
  261. } else {
  262. cb('Have errors while on going...', null);
  263. }
  264. } catch (ex) {
  265. console.log("报表数据异常: userId " + user_id + ", project id: " + prj_id);
  266. console.log(ex);
  267. cb('Exception occurs while on going...', null);
  268. }
  269. };
  270. //*/
  271. //取汇总数据流程
  272. if (promiseArr[0] !== null) {
  273. promiseArr[0].then(function (rst) {
  274. rawDataObj.Construct = rst.parent;
  275. rawDataObj.ConstructDetail = rst.subList;
  276. if (promiseArr[1] !== null) {
  277. promiseArr[1].then(function (rst) {
  278. rawDataObj.Segment = rst.parent;
  279. rawDataObj.SegmentDetail = rst.subList;
  280. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  281. });
  282. } else {
  283. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  284. }
  285. });
  286. } else if (promiseArr[1] !== null) {
  287. promiseArr[1].then(function (rst) {
  288. rawDataObj.Segment = rst.parent;
  289. rawDataObj.SegmentDetail = rst.subList;
  290. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  291. });
  292. } else {
  293. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  294. }
  295. /*/
  296. let tplData = rptDataUtil.assembleData(rawDataObj);
  297. let printCom = JpcEx.createNew();
  298. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  299. //console.log("orientation: " + (orientation === 'null'));
  300. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  301. let defProperties = rptUtil.getReportDefaultCache();
  302. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  303. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  304. printCom.initialize(rptTpl);
  305. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  306. let maxPages = printCom.totalPages;
  307. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  308. if (pageRst) {
  309. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  310. cb(null, pageRst);
  311. } else {
  312. cb('Have errors while on going...', null);
  313. }
  314. //*/
  315. } else {
  316. cb('No report data were found!', null);
  317. }
  318. });
  319. } else {
  320. cb('No report template was found!', null);
  321. }
  322. });
  323. }
  324. function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, option, outputType, cb) {
  325. for (let idx = 0; idx < rpt_ids.length; idx++) {
  326. rpt_ids[idx] = parseInt(rpt_ids[idx]); //转换一下,以防万一
  327. }
  328. rptTplFacade.getRptTemplates(rpt_ids).then(function(rptTpls) {
  329. let rptDataUtil = new rptDataExtractor();
  330. let filters = [];
  331. for (let rptTpl of rptTpls) {
  332. rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
  333. let filter = rptDataUtil.getDataRequestFilter();
  334. for (let dtlFilter of filter) {
  335. if (filters.indexOf(dtlFilter) < 0) {
  336. filters.push(dtlFilter);
  337. }
  338. }
  339. //正常应该根据报表模板定义的数据类型来请求数据
  340. rptTplDataFacade.prepareProjectData(userId_Dft, demoPrjId, filters, function (err, msg, rawDataObj) {
  341. if (!err) {
  342. try {
  343. //1. 这里只用一份数据,根据实际应用情况,只需要保留copy三样数据: bills, ration, ration_glj, projectGLJ
  344. let savedBillsData = [], savedRationData = [], savedGljData = [];
  345. for (let dtlData of rawDataObj.prjData) {
  346. if (dtlData.moduleName === 'bills') {
  347. Object.assign(savedBillsData, dtlData.data);
  348. } else if (dtlData.moduleName === 'ration') {
  349. Object.assign(savedRationData, dtlData.data);
  350. } else if (dtlData.moduleName === 'ration_glj') {
  351. Object.assign(savedGljData, dtlData.data);
  352. } else if (dtlData.moduleName === 'projectGLJ') {
  353. //这个待定
  354. }
  355. }
  356. //2. 一个一个模板创建数据
  357. for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
  358. let rptTpl = (rptTpls[tplIdx]._doc)?rptTpls[tplIdx]._doc:rptTpls[tplIdx];
  359. rptDataUtil.initialize(rptTpl);
  360. let tplData = rptDataUtil.assembleData(rawDataObj);
  361. let printCom = JpcEx.createNew();
  362. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  363. let defProperties = rpt_cfg;
  364. let dftOption = JV.PAGING_OPTION_NORMAL;
  365. printCom.initialize(rptTpl);
  366. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_EXCEL);
  367. let maxPages = printCom.totalPages;
  368. let customizeCfg = {"fillZero": true};
  369. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  370. if (pageRst) {
  371. } else {
  372. }
  373. //注意:这里需要把清单、定额、工料机数据assign回去!!!
  374. for (let dtlData of rawDataObj.prjData) {
  375. if (dtlData.moduleName === 'bills' && savedBillsData.length > 0) {
  376. Object.assign(dtlData.data, savedBillsData);
  377. } else if (dtlData.moduleName === 'ration' && savedRationData.length > 0) {
  378. Object.assign(dtlData.data, savedRationData);
  379. } else if (dtlData.moduleName === 'ration_glj' && savedGljData.length > 0) {
  380. Object.assign(dtlData.data, savedGljData);
  381. } else if (dtlData.moduleName === 'projectGLJ') {
  382. //这个待定
  383. }
  384. }
  385. }
  386. } catch (ex) {
  387. console.log(ex);
  388. } finally {
  389. }
  390. } else {
  391. //
  392. }
  393. })
  394. }
  395. });
  396. }
  397. function getBillsSummaryReportPages(user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
  398. let rptTpl = null;
  399. rptTplDataFacade.getBudgetSummayDatas(prjIds).then(function(summaryRawDataRst) {
  400. rptTplFacade.getRptTemplate(rpt_id).then(function(rptTpl) {
  401. let rptDataUtil = new rptDataExtractor();
  402. rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
  403. try {
  404. let tplData = rptDataUtil.assembleData(summaryRawDataRst);
  405. let printCom = JpcEx.createNew();
  406. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  407. //console.log("orientation: " + (orientation === 'null'));
  408. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  409. let defProperties = rptUtil.getReportDefaultCache();
  410. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  411. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  412. printCom.initialize(rptTpl);
  413. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  414. let maxPages = printCom.totalPages;
  415. let pageRst = null;
  416. if (maxPages > 0) {
  417. pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  418. } else {
  419. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  420. }
  421. if (pageRst) {
  422. cb(null, pageRst);
  423. } else {
  424. cb('Have errors while on going...', null);
  425. }
  426. } catch (ex) {
  427. console.log("报表数据异常: userId " + user_id + ", project id: " + prj_id);
  428. console.log(ex);
  429. cb('Exception occurs while on going...', null);
  430. }
  431. });
  432. });
  433. }
  434. function getGljSummaryReportPages(user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
  435. let rptTpl = null;
  436. rptTplDataFacade.getGLJSummayDatas(prjIds).then(function(summaryRawDataRst) {
  437. rptTplFacade.getRptTemplate(rpt_id).then(function(rptTpl) {
  438. let rptDataUtil = new rptDataExtractor();
  439. rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
  440. try {
  441. let tplData = rptDataUtil.assembleData(summaryRawDataRst);
  442. let printCom = JpcEx.createNew();
  443. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  444. //console.log("orientation: " + (orientation === 'null'));
  445. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  446. let defProperties = rptUtil.getReportDefaultCache();
  447. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  448. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  449. printCom.initialize(rptTpl);
  450. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  451. let maxPages = printCom.totalPages;
  452. let pageRst = null;
  453. if (maxPages > 0) {
  454. pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  455. } else {
  456. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  457. }
  458. if (pageRst) {
  459. cb(null, pageRst);
  460. } else {
  461. cb('Have errors while on going...', null);
  462. }
  463. } catch (ex) {
  464. console.log("报表数据异常: userId " + user_id + ", project id: " + prj_id);
  465. console.log(ex);
  466. cb('Exception occurs while on going...', null);
  467. }
  468. });
  469. });
  470. }
  471. module.exports = {
  472. getReportAllPages: function (req, res) {
  473. let params = JSON.parse(req.body.params),
  474. rpt_id = params.rpt_tpl_id,
  475. prj_id = params.prj_id,
  476. pageSize = params.pageSize,
  477. orientation = params.orientation,
  478. customizeCfg = params.custCfg
  479. ;
  480. // req.session.sessionUser.ssoId
  481. let user_id = req.session.sessionUser.id;
  482. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  483. callback(req, res, err, pageRst);
  484. });
  485. },
  486. getMultiReports: function (req, res) {
  487. let params = JSON.parse(req.body.params),
  488. prj_id = params.prj_id,
  489. rpt_ids = params.rpt_ids.split(','),
  490. pageSize = params.pageSize,
  491. orientation = params.orientation,
  492. customizeCfg = params.custCfg,
  493. option = params.option;
  494. let user_id = req.session.sessionUser.id;
  495. let parallelFunctions = [];
  496. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  497. for (let id of rpt_ids) {
  498. parallelFunctions.push((function (rpt_id) {
  499. return function (cb) {
  500. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  501. if(err){
  502. cb(err);
  503. }
  504. else{
  505. cb(null, pageRst);
  506. }
  507. })
  508. }
  509. })(parseInt(id)));
  510. }
  511. async.parallel(parallelFunctions, function (err, pageRstArray) {
  512. if (err) {
  513. callback(req, res, '数据有误', null);
  514. } else {
  515. callback(req, res, err, pageRstArray);
  516. }
  517. })
  518. },
  519. getMultiReportsEx: function (req, res) {
  520. //原则说明:把所有报表模板集中获取,统一filter,只读一次数据!(有空再整)
  521. let params = JSON.parse(req.body.params),
  522. prj_id = params.prj_id,
  523. rpt_ids = params.rpt_ids.split(','),
  524. pageSize = params.pageSize,
  525. orientation = params.orientation,
  526. customizeCfg = params.custCfg,
  527. option = params.option;
  528. let user_id = req.session.sessionUser.id;
  529. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  530. getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
  531. if(err){
  532. callback(req, res, '数据有误', null);
  533. }
  534. else{
  535. callback(req, res, err, rptPageRstArray);
  536. }
  537. });
  538. },
  539. getBillSummaryReportPages: function (req, res) {
  540. let params = JSON.parse(req.body.params),
  541. rpt_id = params.rpt_tpl_id,
  542. prjIds = params.prjIds,
  543. pageSize = params.pageSize,
  544. orientation = params.orientation,
  545. customizeCfg = params.custCfg
  546. ;
  547. let user_id = req.session.sessionUser.id;
  548. getBillsSummaryReportPages(user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  549. callback(req, res, err, pageRst);
  550. });
  551. },
  552. getGljSummaryReportPages: function (req, res) {
  553. let params = JSON.parse(req.body.params),
  554. rpt_id = params.rpt_tpl_id,
  555. prjIds = params.prjIds,
  556. pageSize = params.pageSize,
  557. orientation = params.orientation,
  558. customizeCfg = params.custCfg
  559. ;
  560. let user_id = req.session.sessionUser.id;
  561. getGljSummaryReportPages(user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  562. callback(req, res, err, pageRst);
  563. });
  564. },
  565. getReportAllPagesSvg: function (req, res) {
  566. let params = JSON.parse(req.body.params),
  567. rpt_id = params.rpt_tpl_id,
  568. prj_id = params.prj_id,
  569. pageSize = params.pageSize,
  570. orientation = params.orientation,
  571. customizeCfg = params.custCfg
  572. ;
  573. let user_id = req.session.sessionUser.id;
  574. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_SVG, function (err, pageRst) {
  575. let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
  576. callback(req, res, err, svgRstStrArr);
  577. });
  578. },
  579. createExcelFilesInOneBook: function (req, res) {
  580. let params = JSON.parse(req.body.params),
  581. prj_id = params.prj_id,
  582. rpt_ids = params.rpt_ids,
  583. rptName = params.rptName,
  584. pageSize = params.pageSize,
  585. orientation = params.orientation,
  586. customizeCfg = params.custCfg,
  587. option = params.option;
  588. let user_id = req.session.sessionUser.id;
  589. let parallelFunctions = [];
  590. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  591. for (let idx = 0; idx < rpt_ids.length; idx++) {
  592. let r_id = rpt_ids[idx];
  593. parallelFunctions.push((function (rpt_id) {
  594. return function (cb) {
  595. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  596. if(err){
  597. cb(err);
  598. }
  599. else{
  600. cb(err, pageRst);
  601. }
  602. })
  603. }
  604. })(parseInt(r_id)));
  605. }
  606. async.parallel(parallelFunctions, function (err, pageRstArray) {
  607. if (err) {
  608. callback(req, res, '数据有误', null);
  609. } else {
  610. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(uuidName){
  611. let fileRst = {uuid: uuidName, reportName: rptName};
  612. callback(req, res, err, fileRst);
  613. });
  614. }
  615. })
  616. },
  617. createExcelFiles: function (req, res) {
  618. let params = JSON.parse(req.body.params),
  619. prj_id = params.prj_id,
  620. rpt_ids = params.rpt_ids,
  621. rpt_names = params.rpt_names,
  622. pageSize = params.pageSize,
  623. orientation = params.orientation,
  624. isOneSheet = params.isOneSheet,
  625. customizeCfg = params.custCfg,
  626. option = params.option;
  627. let user_id = req.session.sessionUser.id;
  628. let parallelFunctions = [];
  629. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  630. for (let idx = 0; idx < rpt_ids.length; idx++) {
  631. let r_id = rpt_ids[idx];
  632. let r_name = rpt_names[idx];
  633. parallelFunctions.push((function (rpt_id, rpt_name) {
  634. return function (cb) {
  635. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  636. if(err){
  637. cb(err);
  638. } else {
  639. rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, isOneSheet, null, null, function(uuidName){
  640. let fileRst = {uuid: uuidName, reportName: rpt_name};
  641. cb(err, fileRst);
  642. })
  643. }
  644. })
  645. }
  646. })(parseInt(r_id), r_name));
  647. }
  648. async.parallel(parallelFunctions, function (err, fileRstArray) {
  649. if (err) {
  650. callback(req, res, '数据有误', null);
  651. } else {
  652. // console.log(err);
  653. callback(req, res, err, fileRstArray);
  654. }
  655. })
  656. },
  657. getFileByUUID: function (req, res) {
  658. let uuid = req.params.uuid,
  659. rptName = req.params.rptName,
  660. suffix = "." + req.params.suffix
  661. ;
  662. // let user_id = req.session.sessionUser.id; //未来要校验user id
  663. try {
  664. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  665. let rptNameURI = encodeURI(rptName);
  666. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix );
  667. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuid + suffix);
  668. filestream.on('data', function(chunk) {
  669. res.write(chunk);
  670. });
  671. filestream.on('end', function() {
  672. res.end();
  673. });
  674. } catch (e) {
  675. console.log(e);
  676. }
  677. },
  678. getExcel: function(req, res) {
  679. let prj_id = req.params.prj_id,
  680. rpt_id = req.params.rpt_id,
  681. pageSize = req.params.size,
  682. orientation = req.params.orientation,
  683. rptName = req.params.rptName,
  684. isOneSheet = req.params.isOneSheet,
  685. option = req.params.option
  686. ;
  687. let customizeCfg = null;
  688. let user_id = req.session.sessionUser.id;
  689. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  690. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function(err, pageRst){
  691. try {
  692. rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, null, null, function(uuidName){
  693. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  694. let rptNameURI = encodeURI(rptName);
  695. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".xlsx\"; filename*=utf-8''" + rptNameURI + '.xlsx' );
  696. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.xlsx');
  697. filestream.on('data', function(chunk) {
  698. res.write(chunk);
  699. });
  700. filestream.on('end', function() {
  701. res.end();
  702. });
  703. });
  704. } catch (e) {
  705. console.log(e);
  706. }
  707. })
  708. },
  709. getExcelInOneBook: function (req, res) {
  710. let prj_id = req.params.prj_id,
  711. rpt_ids = req.params.rpt_ids.split(','),
  712. pageSize = req.params.size,
  713. rptName = req.params.rptName,
  714. option = req.params.option;
  715. let user_id = req.session.sessionUser.id;
  716. let parallelFunctions = [];
  717. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  718. for (let id of rpt_ids) {
  719. parallelFunctions.push((function (rpt_id) {
  720. return function (cb) {
  721. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, null, null, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  722. if(err){
  723. cb(err);
  724. }
  725. else{
  726. cb(null, pageRst);
  727. }
  728. })
  729. }
  730. })(parseInt(id)));
  731. }
  732. async.parallel(parallelFunctions, function (err, pageRstArray) {
  733. if (err) {
  734. callback(req, res, '数据有误', null);
  735. } else {
  736. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(tmpFilePath){
  737. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  738. let rptNameURI = encodeURI(rptName);
  739. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".xlsx\"; filename*=utf-8''" + rptNameURI + '.xlsx');
  740. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + tmpFilePath + '.xlsx');
  741. filestream.on('data', function(chunk) {
  742. res.write(chunk);
  743. });
  744. filestream.on('end', function() {
  745. res.end();
  746. });
  747. });
  748. }
  749. })
  750. },
  751. createPdfFiles: function (req, res) {
  752. let params = JSON.parse(req.body.params),
  753. prj_id = params.prj_id,
  754. rpt_ids = params.rpt_ids,
  755. rpt_names = params.rpt_names,
  756. pageSize = params.pageSize,
  757. orientation = params.orientation,
  758. customizeCfg = params.custCfg,
  759. option = params.option;
  760. let user_id = req.session.sessionUser.id;
  761. let parallelFunctions = [];
  762. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  763. for (let idx = 0; idx < rpt_ids.length; idx++) {
  764. let r_id = rpt_ids[idx];
  765. let r_name = rpt_names[idx];
  766. parallelFunctions.push((function (rpt_id, rpt_name) {
  767. return function (cb) {
  768. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, pageRst) {
  769. if(err){
  770. cb(err);
  771. }
  772. else{
  773. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rpt_name, function(uuidName){
  774. let fileRst = {uuid: uuidName, reportName: rpt_name};
  775. cb(err, fileRst);
  776. })
  777. }
  778. })
  779. }
  780. })(parseInt(r_id), r_name));
  781. }
  782. async.parallel(parallelFunctions, function (err, fileRstArray) {
  783. if (err) {
  784. callback(req, res, '数据有误', null);
  785. } else {
  786. // console.log(err);
  787. callback(req, res, err, fileRstArray);
  788. }
  789. })
  790. },
  791. getPDF:function (req, res) {
  792. let prj_id = req.params.prj_id,
  793. rpt_id = req.params.rpt_id,
  794. pageSize = req.params.size,
  795. orientation = req.params.orientation,
  796. rptName = req.params.rptName
  797. ;
  798. let user_id = req.session.sessionUser.id;
  799. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, null, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_PDF, function(err, pageRst){
  800. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rptName,function (uuidName) {
  801. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  802. // res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".pdf");
  803. let rptNameURI = encodeURI(rptName);
  804. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".pdf\"; filename*=utf-8''" + rptNameURI + ".pdf" );
  805. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.pdf');
  806. filestream.on('data', function(chunk) {
  807. res.write(chunk);
  808. });
  809. filestream.on('end', function() {
  810. res.end();
  811. });
  812. })
  813. })
  814. },
  815. getTestReportAllPages: function(req, res){
  816. let rpt_id = req.body.ID;
  817. let pageSize = req.body.pageSize;
  818. getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
  819. //fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
  820. callback(req, res, err, pageRst);
  821. })
  822. },
  823. getTestExcel: function(req, res) {
  824. let rpt_id = req.params.id,
  825. pageSize = req.params.size,
  826. rptName = req.params.rptName,
  827. isOneSheet = req.params.isOneSheet,
  828. option = req.params.option;
  829. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  830. getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function(err, pageRst){
  831. fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
  832. try {
  833. rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, null, null, function(uuidName){
  834. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  835. res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
  836. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.xlsx');
  837. filestream.on('data', function(chunk) {
  838. res.write(chunk);
  839. });
  840. filestream.on('end', function() {
  841. res.end();
  842. });
  843. });
  844. } catch (e) {
  845. console.log(e);
  846. }
  847. })
  848. },
  849. getTestExcelInOneBook: function(req, res) {
  850. let rpt_ids = req.params.ids.split(','),
  851. pageSize = req.params.size,
  852. rptName = req.params.rptName,
  853. option = req.params.option;
  854. let parallelFunctions = [];
  855. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  856. for (let id of rpt_ids) {
  857. parallelFunctions.push((function (rpt_id) {
  858. return function (cb) {
  859. getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function (err, pageRst) {
  860. if(err){
  861. cb(err);
  862. }
  863. else{
  864. cb(null, pageRst);
  865. }
  866. })
  867. }
  868. })(parseInt(id)));
  869. }
  870. async.parallel(parallelFunctions, function (err, pageRstArray) {
  871. if (err) {
  872. callback(req, res, '数据有误', null);
  873. } else {
  874. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(tmpFilePath){
  875. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  876. res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
  877. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + tmpFilePath + '.xlsx');
  878. filestream.on('data', function(chunk) {
  879. res.write(chunk);
  880. });
  881. filestream.on('end', function() {
  882. res.end();
  883. });
  884. });
  885. //callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
  886. }
  887. })
  888. },
  889. getTestPDF:function (req, res) {
  890. let rpt_id = req.params.id,
  891. pageSize = req.params.size,
  892. rptName = req.params.rptName;
  893. getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
  894. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rptName,function (uuidName) {
  895. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  896. // res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".pdf");
  897. let rptNameURI = encodeURI(rptName);
  898. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".pdf\"; filename*=utf-8''" + rptNameURI + ".pdf" );
  899. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.pdf');
  900. filestream.on('data', function(chunk) {
  901. res.write(chunk);
  902. });
  903. filestream.on('end', function() {
  904. res.end();
  905. });
  906. })
  907. })
  908. }
  909. };