rpt_controller.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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. let dummyDataObj = {
  12. ProjectCostFields: [{
  13. "name": "分部分项工程费",
  14. "cost": 728819,
  15. "unitCost": 728819,
  16. "per": 70.08
  17. }, {
  18. "name": "技术措施费",
  19. "cost": 36807.79,
  20. "unitCost": 36807.79,
  21. "per": 3.54
  22. }, {
  23. "name": "安全文明施工费",
  24. "cost": 62312.37,
  25. "unitCost": 62312.37,
  26. "per": 5.99
  27. }, {
  28. "name": "建设工程竣工档案编制费",
  29. "cost": 6867.95,
  30. "unitCost": 6867.95,
  31. "per": 0.66
  32. }, {
  33. "name": "其他组织措施费",
  34. "cost": 36056.75,
  35. "unitCost": 36056.75,
  36. "per": 3.47
  37. }, {
  38. "name": "暂列金额",
  39. "cost": 0,
  40. "unitCost": 0,
  41. "per": 0
  42. }, {
  43. "name": "专业工程暂估价",
  44. "cost": 0,
  45. "unitCost": 0,
  46. "per": 0
  47. }, {
  48. "name": "计日工",
  49. "cost": 0,
  50. "unitCost": 0,
  51. "per": 0
  52. }, {
  53. "name": "总承包服务费",
  54. "cost": 0,
  55. "unitCost": 0,
  56. "per": 0
  57. }, {
  58. "name": "索赔与现场签证",
  59. "cost": 0,
  60. "unitCost": 0,
  61. "per": 0
  62. }, {
  63. "name": "规费",
  64. "cost": 64387.06,
  65. "unitCost": 64387.06,
  66. "per": 6.19
  67. }, {
  68. "name": "税金",
  69. "cost": 104748.1,
  70. "unitCost": 104748.1,
  71. "per": 10.07
  72. }, {
  73. "name": "工程造价",
  74. "cost": 1039999.02,
  75. "unitCost": 1039999.02,
  76. "per": 100
  77. }
  78. ],
  79. ProjectEcoFields: [{
  80. "name": "土石方工程",
  81. "cost": 31477.97,
  82. "unitCost": 29.338,
  83. "per": 0.84
  84. }, {
  85. "name": "地基处理与边坡支护工程",
  86. "cost": 0,
  87. "unitCost": 0,
  88. "per": 0
  89. }, {
  90. "name": "桩基工程",
  91. "cost": 0,
  92. "unitCost": 0,
  93. "per": 0
  94. }, {
  95. "name": "砌筑工程",
  96. "cost": 312217.05,
  97. "unitCost": 290.995,
  98. "per": 8.32
  99. }, {
  100. "name": "混凝土及钢筋混凝土工程",
  101. "cost": 2301974.32,
  102. "unitCost": 2145.503,
  103. "per": 61.34
  104. }, {
  105. "name": "金属结构工程",
  106. "cost": 0,
  107. "unitCost": 0,
  108. "per": 0
  109. }, {
  110. "name": "木结构工程",
  111. "cost": 0,
  112. "unitCost": 0,
  113. "per": 0
  114. }, {
  115. "name": "门窗工程",
  116. "cost": 0,
  117. "unitCost": 0,
  118. "per": 0
  119. }, {
  120. "name": "屋面及防水工程",
  121. "cost": 0,
  122. "unitCost": 0,
  123. "per": 0
  124. }, {
  125. "name": "保温、防腐、隔热工程",
  126. "cost": 0,
  127. "unitCost": 0,
  128. "per": 0
  129. }, {
  130. "name": "楼地面装饰工程",
  131. "cost": 0,
  132. "unitCost": 0,
  133. "per": 0
  134. }, {
  135. "name": "其他工程",
  136. "cost": 0,
  137. "unitCost": 0,
  138. "per": 0
  139. }
  140. ],
  141. ProjectLabMaterialFields: [{
  142. "name": "综合用工",
  143. "unit": "工日",
  144. "unitPrice": 118.62,
  145. "quantity": 5248.2,
  146. "unitIndex": 489.147
  147. }, {
  148. "name": "土石方用工",
  149. "unit": "工日",
  150. "unitPrice": 100,
  151. "quantity": 176.71,
  152. "unitIndex": 16.47
  153. }, {
  154. "name": "钢材",
  155. "unit": "t",
  156. "unitPrice": 3079.64,
  157. "quantity": 1.68,
  158. "unitIndex": 0.157
  159. }, {
  160. "name": "水泥",
  161. "unit": "t",
  162. "unitPrice": 0,
  163. "quantity": 0,
  164. "unitIndex": 0
  165. }, {
  166. "name": "商品混凝土",
  167. "unit": "m3",
  168. "unitPrice": 403,
  169. "quantity": 484.59,
  170. "unitIndex": 45.165
  171. }, {
  172. "name": "锯材",
  173. "unit": "m3",
  174. "unitPrice": 0,
  175. "quantity": 0,
  176. "unitIndex": 0
  177. }, {
  178. "name": "砂",
  179. "unit": "t",
  180. "unitPrice": 0,
  181. "quantity": 0,
  182. "unitIndex": 0
  183. }, {
  184. "name": "石子",
  185. "unit": "t",
  186. "unitPrice": 0,
  187. "quantity": 0,
  188. "unitIndex": 0
  189. }, {
  190. "name": "标砖",
  191. "unit": "千块",
  192. "unitPrice": 4,
  193. "quantity": 11.06,
  194. "unitIndex": 1.031
  195. }, {
  196. "name": "砌块",
  197. "unit": "m3",
  198. "unitPrice": 0,
  199. "quantity": 0,
  200. "unitIndex": 0
  201. }, {
  202. "name": "门",
  203. "unit": "m2",
  204. "unitPrice": 0,
  205. "quantity": 0,
  206. "unitIndex": 0
  207. }, {
  208. "name": "窗",
  209. "unit": "m2",
  210. "unitPrice": 0,
  211. "quantity": 0,
  212. "unitIndex": 0
  213. }, {
  214. "name": "保温材料",
  215. "unit": "",
  216. "unitPrice": 0,
  217. "quantity": 0,
  218. "unitIndex": 0
  219. }, {
  220. "name": "防水材料",
  221. "unit": "",
  222. "unitPrice": 0,
  223. "quantity": 0,
  224. "unitIndex": 0
  225. }, {
  226. "name": "其它材料",
  227. "unit": "",
  228. "unitPrice": 0,
  229. "quantity": 0,
  230. "unitIndex": 0
  231. }
  232. ],
  233. ProjectQtyFields: [{
  234. "name": "挖土石方量",
  235. "quantityIndexUnit": "m3",
  236. "quantity": 0
  237. }, {
  238. "name": "基础混凝土",
  239. "quantityIndexUnit": "m3",
  240. "quantity": 0
  241. }, {
  242. "name": "混凝土桩",
  243. "quantityIndexUnit": "m3",
  244. "quantity": 0
  245. }, {
  246. "name": "混凝土柱",
  247. "quantityIndexUnit": "m3",
  248. "quantity": 0
  249. }, {
  250. "name": "混凝土梁",
  251. "quantityIndexUnit": "m3",
  252. "quantity": 0
  253. }, {
  254. "name": "混凝土有梁板",
  255. "quantityIndexUnit": "m3",
  256. "quantity": 0
  257. }, {
  258. "name": "混凝土平板",
  259. "quantityIndexUnit": "m3",
  260. "quantity": 0
  261. }, {
  262. "name": "混凝土楼梯",
  263. "quantityIndexUnit": "m2",
  264. "quantity": 0
  265. }, {
  266. "name": "混凝土墙",
  267. "quantityIndexUnit": "m3",
  268. "quantity": 0
  269. }, {
  270. "name": "屋架",
  271. "quantityIndexUnit": "m3",
  272. "quantity": 0
  273. }, {
  274. "name": "砌体",
  275. "quantityIndexUnit": "m3",
  276. "quantity": 0
  277. }, {
  278. "name": "楼地面",
  279. "quantityIndexUnit": "m2",
  280. "quantity": 0
  281. }, {
  282. "name": "隔热、保温",
  283. "quantityIndexUnit": "m2",
  284. "quantity": 0
  285. }, {
  286. "name": "天棚装饰",
  287. "quantityIndexUnit": "m2",
  288. "quantity": 0
  289. }, {
  290. "name": "内墙装饰",
  291. "quantityIndexUnit": "m2",
  292. "quantity": 0
  293. }, {
  294. "name": "外墙装饰",
  295. "quantityIndexUnit": "m2",
  296. "quantity": 0
  297. }, {
  298. "name": "防水",
  299. "quantityIndexUnit": "m2",
  300. "quantity": 0
  301. }, {
  302. "name": "门",
  303. "quantityIndexUnit": "m2",
  304. "quantity": 0
  305. }, {
  306. "name": "窗",
  307. "quantityIndexUnit": "m2",
  308. "quantity": 0
  309. }, {
  310. "name": "钢材",
  311. "quantityIndexUnit": "t",
  312. "quantity": 0
  313. }, {
  314. "name": "阳台雨蓬挑檐",
  315. "quantityIndexUnit": "m3",
  316. "quantity": 0
  317. }, {
  318. "name": "屋面防水",
  319. "quantityIndexUnit": "m2",
  320. "quantity": 0
  321. }, {
  322. "name": "基础模板",
  323. "quantityIndexUnit": "m2",
  324. "quantity": 0
  325. }, {
  326. "name": "梁模板",
  327. "quantityIndexUnit": "m2",
  328. "quantity": 0
  329. }, {
  330. "name": "柱模板",
  331. "quantityIndexUnit": "m2",
  332. "quantity": 0
  333. }, {
  334. "name": "墙模板",
  335. "quantityIndexUnit": "m2",
  336. "quantity": 0
  337. }, {
  338. "name": "平板模板",
  339. "quantityIndexUnit": "m2",
  340. "quantity": 0
  341. }, {
  342. "name": "楼梯模板",
  343. "quantityIndexUnit": "m2",
  344. "quantity": 0
  345. }, {
  346. "name": "其他模板",
  347. "quantityIndexUnit": "m2",
  348. "quantity": 0
  349. }
  350. ]
  351. };
  352. import rptTplFacade from "../facade/rpt_template_facade";
  353. import demoTemplateFacade from "../facade/rpt_tpl_data_demo_facade";
  354. import JpcEx from "../rpt_component/jpc_ex";
  355. import rptUtil from "../util/rpt_util";
  356. import rpt_xl_util from "../util/rpt_excel_util";
  357. import rpt_pdf_util from "../util/rpt_pdf_util";
  358. import rpt_svg_util from "../util/rpt_svg_util";
  359. import fs from "fs";
  360. import strUtil from "../../../public/stringUtil";
  361. import rptDataExtractor from "../util/rpt_construct_data_util";
  362. //统一回调函数
  363. let callback = function(req, res, err, data){
  364. if(err){
  365. res.json({success: false, error: err});
  366. }
  367. else{
  368. //res.send({success: true, data: data});
  369. res.json({success:true, data: data});
  370. }
  371. };
  372. function getAllPagesCommonOrg(rpt_id, pageSize, option, cb) {
  373. let rptTpl = null;
  374. rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
  375. rptTpl = rst;
  376. if (rptTpl) {
  377. if (rptTpl.ID_KEY) {
  378. return demoTemplateFacade.getDemoData(rptTpl.ID_KEY);
  379. } else {
  380. //callback(req, res, 'No report template data were found!', null);
  381. cb('No report template data were found!', null);
  382. }
  383. } else {
  384. //callback(req, res, 'No report template was found!', null);
  385. cb('No report template was found!', null);
  386. }
  387. }).then(function(tplData){
  388. if (tplData) {
  389. let printCom = JpcEx.createNew();
  390. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  391. let defProperties = rptUtil.getReportDefaultCache();
  392. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  393. printCom.initialize(rptTpl);
  394. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_NORMAL);
  395. let maxPages = printCom.totalPages;
  396. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  397. if (pageRst) {
  398. cb(null, pageRst);
  399. } else {
  400. //callback(req, res, "Have errors while on going...", null);
  401. cb('Have errors while on going...', null);
  402. }
  403. } else {
  404. //callback(req, res, 'No report data were found!', null);
  405. cb('No report data were found!', null);
  406. }
  407. }
  408. );
  409. }
  410. function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
  411. let tmpObj = {};
  412. //1. 字体
  413. let newFonts = [];
  414. for (let font of defProperties.fonts) {
  415. let copyFont = {};
  416. copyFont.ID = font.ID;
  417. for (let fontProp of JV.FONT_PROPS) {
  418. copyFont[fontProp] = font[fontProp];
  419. }
  420. newFonts.push(copyFont);
  421. tmpObj[font.ID] = copyFont;
  422. }
  423. let private_setup_font = function (propStr, newFont) {
  424. if (tmpObj[propStr]) {
  425. tmpObj[propStr].Name = newFont.Name;
  426. tmpObj[propStr].FontHeight = String(newFont.FontHeight);
  427. tmpObj[propStr].FontBold = newFont.FontBold;
  428. tmpObj[propStr].FontItalic = newFont.FontItalic;
  429. tmpObj[propStr].FontUnderline = newFont.FontUnderline;
  430. }
  431. };
  432. for (let custFont of customizeCfg.fonts) {
  433. switch (custFont.CfgDispName) {
  434. case "表标题":
  435. private_setup_font("ReportTitle_Main", custFont);
  436. break;
  437. case "列标题":
  438. private_setup_font("HeaderColumn", custFont);
  439. private_setup_font("FooterColumn", custFont);
  440. break;
  441. case "正文内容":
  442. private_setup_font("Content", custFont);
  443. break;
  444. case "合计":
  445. private_setup_font("GrandTotal", custFont);
  446. private_setup_font("SectionTotal", custFont);
  447. break;
  448. case "表眉/表脚":
  449. private_setup_font("Header", custFont);
  450. private_setup_font("Footer", custFont);
  451. break;
  452. }
  453. }
  454. // 1.1 窄体
  455. if (tmpObj["Content_Narrow"]) {
  456. if (customizeCfg.isNarrow) {
  457. tmpObj["Content_Narrow"].Name = "Arial Narrow";
  458. } else {
  459. if (tmpObj["Content"]) {
  460. tmpObj["Content_Narrow"].Name = tmpObj["Content"].Name;
  461. } else {
  462. tmpObj["Content_Narrow"].Name = "宋体";
  463. }
  464. }
  465. }
  466. defProperties.fonts = newFonts;
  467. //2. 页边距
  468. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = customizeCfg.margins[JV.PROP_LEFT] / 10;
  469. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = customizeCfg.margins[JV.PROP_RIGHT] / 10;
  470. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = customizeCfg.margins[JV.PROP_TOP] / 10;
  471. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = customizeCfg.margins[JV.PROP_BOTTOM] / 10;
  472. //3. 边框竖线
  473. if (!(customizeCfg.showVerticalLine)) {
  474. let private_copy_border = function (src) {
  475. let rst = {};
  476. rst.Position = src.Position;
  477. rst.LineWeight = src.LineWeight;
  478. rst.DashStyle = src.DashStyle;
  479. rst.Color = src.Color;
  480. return rst;
  481. };
  482. let newStyles = [];
  483. for (let i =0 ; i < defProperties.styles.length; i++) {
  484. let style = defProperties.styles[i];
  485. newStyles.push(style);
  486. if (style.ID === "BORDER_ALL_AROUND") {
  487. let newStyle = {};
  488. newStyle.ID = style.ID;
  489. newStyle.CfgDispName = style.CfgDispName;
  490. newStyle.border_style = [];
  491. for (let border of style.border_style) {
  492. let newBorder = private_copy_border(border);
  493. newStyle.border_style.push(newBorder);
  494. if (border.Position === "Left" || border.Position === "Right") {
  495. newBorder.LineWeight = 0;
  496. }
  497. }
  498. newStyles[newStyles.length - 1] = newStyle;
  499. }
  500. }
  501. defProperties.styles = newStyles;
  502. }
  503. //4. 补0
  504. let private_Setup_Format = function(tabFields) {
  505. if (tabFields) {
  506. for (let tabField of tabFields) {
  507. if (tabField[JV.PROP_FORMAT]) {
  508. tabField[JV.PROP_FORMAT] = tabField[JV.PROP_FORMAT].replace(new RegExp("#","gm"),"0");
  509. }
  510. }
  511. }
  512. };
  513. if (customizeCfg.fillZero) {
  514. if (rptTpl[JV.NODE_FLOW_INFO]) {
  515. 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]);
  516. 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]);
  517. 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]);
  518. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES])
  519. private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  520. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  521. for (let discrete of rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  522. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  523. }
  524. }
  525. if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
  526. 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]);
  527. 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]);
  528. 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]);
  529. 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]);
  530. 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])
  531. private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  532. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  533. for (let discrete of rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  534. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  535. }
  536. }
  537. }
  538. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  539. 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]);
  540. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  541. for (let discrete of rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  542. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  543. }
  544. }
  545. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  546. 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]);
  547. 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]);
  548. 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]);
  549. 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]);
  550. 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]);
  551. 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]);
  552. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  553. for (let discrete of rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  554. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  555. }
  556. }
  557. }
  558. }
  559. }
  560. function getEcoFieldsData() {
  561. return dummyDataObj;
  562. }
  563. function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
  564. let rptTpl = null;
  565. rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
  566. rptTpl = rst;
  567. if (rptTpl) {
  568. let rptDataUtil = new rptDataExtractor();
  569. rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
  570. let summaryRst = [], economicRst = [];
  571. let filter = rptDataUtil.getDataRequestFilter(summaryRst, economicRst);
  572. let promiseArr = [null, null, null];
  573. if (summaryRst.length > 0) {
  574. if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
  575. promiseArr[0] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.project);
  576. }
  577. if (summaryRst.indexOf(`Segment`) >= 0 || summaryRst.indexOf(`SegmentDetail`) >= 0) {
  578. promiseArr[1] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.engineering);
  579. }
  580. }
  581. if (economicRst.length > 0) {
  582. promiseArr[2] = getEcoFieldsData();
  583. }
  584. rptTplDataFacade.prepareProjectData(user_id, prj_id, filter, function (err, msg, rawDataObj) {
  585. if (!err) {
  586. let buildPageData = function() {
  587. try {
  588. let tplData = rptDataUtil.assembleData(rawDataObj);
  589. let printCom = JpcEx.createNew();
  590. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  591. //console.log("orientation: " + (orientation === 'null'));
  592. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  593. let defProperties = rptUtil.getReportDefaultCache();
  594. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  595. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  596. printCom.initialize(rptTpl);
  597. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  598. let maxPages = printCom.totalPages;
  599. let pageRst = null;
  600. if (maxPages > 0) {
  601. pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  602. } else {
  603. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  604. }
  605. if (pageRst) {
  606. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  607. cb(null, pageRst);
  608. } else {
  609. cb('Have errors while on going...', null);
  610. }
  611. } catch (ex) {
  612. console.log("报表数据异常: userId " + user_id + ", project id: " + prj_id);
  613. console.log(ex);
  614. cb('Exception occurs while on going...', null);
  615. }
  616. };
  617. //*/
  618. //取汇总数据流程
  619. if (promiseArr[0] !== null) {
  620. promiseArr[0].then(function (rst) {
  621. rawDataObj.Construct = rst.parent;
  622. rawDataObj.ConstructDetail = rst.subList;
  623. if (promiseArr[1] !== null) {
  624. promiseArr[1].then(function (rst) {
  625. rawDataObj.Segment = rst.parent;
  626. rawDataObj.SegmentDetail = rst.subList;
  627. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  628. });
  629. } else {
  630. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  631. }
  632. });
  633. } else if (promiseArr[1] !== null) {
  634. promiseArr[1].then(function (rst) {
  635. rawDataObj.Segment = rst.parent;
  636. rawDataObj.SegmentDetail = rst.subList;
  637. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  638. });
  639. } else {
  640. if (promiseArr[2] !== null) {
  641. //暂时这样测试
  642. rawDataObj.prjData.push({moduleName: 'ProjectCostFields', data: promiseArr[2].ProjectCostFields});
  643. rawDataObj.prjData.push({moduleName: 'ProjectEcoFields', data: promiseArr[2].ProjectEcoFields});
  644. rawDataObj.prjData.push({moduleName: 'ProjectLabMaterialFields', data: promiseArr[2].ProjectLabMaterialFields});
  645. rawDataObj.prjData.push({moduleName: 'ProjectQtyFields', data: promiseArr[2].ProjectQtyFields});
  646. }
  647. buildPageData(rawDataObj, rptDataUtil, rptTpl);
  648. }
  649. /*/
  650. let tplData = rptDataUtil.assembleData(rawDataObj);
  651. let printCom = JpcEx.createNew();
  652. if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  653. //console.log("orientation: " + (orientation === 'null'));
  654. if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
  655. let defProperties = rptUtil.getReportDefaultCache();
  656. if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
  657. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  658. printCom.initialize(rptTpl);
  659. printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
  660. let maxPages = printCom.totalPages;
  661. let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
  662. if (pageRst) {
  663. // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
  664. cb(null, pageRst);
  665. } else {
  666. cb('Have errors while on going...', null);
  667. }
  668. //*/
  669. } else {
  670. cb('No report data were found!', null);
  671. }
  672. });
  673. } else {
  674. cb('No report template was found!', null);
  675. }
  676. })
  677. }
  678. module.exports = {
  679. getReportAllPages: function (req, res) {
  680. let params = JSON.parse(req.body.params),
  681. rpt_id = params.rpt_tpl_id,
  682. prj_id = params.prj_id,
  683. pageSize = params.pageSize,
  684. orientation = params.orientation,
  685. customizeCfg = params.custCfg
  686. ;
  687. // req.session.sessionUser.ssoId
  688. let user_id = req.session.sessionUser.id;
  689. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  690. callback(req, res, err, pageRst);
  691. });
  692. },
  693. getMultiReports: function (req, res) {
  694. let params = JSON.parse(req.body.params),
  695. prj_id = params.prj_id,
  696. rpt_ids = params.rpt_ids.split(','),
  697. pageSize = params.pageSize,
  698. orientation = params.orientation,
  699. customizeCfg = params.custCfg,
  700. option = params.option;
  701. let user_id = req.session.sessionUser.id;
  702. let parallelFunctions = [];
  703. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  704. for (let id of rpt_ids) {
  705. parallelFunctions.push((function (rpt_id) {
  706. return function (cb) {
  707. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
  708. if(err){
  709. cb(err);
  710. }
  711. else{
  712. cb(null, pageRst);
  713. }
  714. })
  715. }
  716. })(parseInt(id)));
  717. }
  718. async.parallel(parallelFunctions, function (err, pageRstArray) {
  719. if (err) {
  720. callback(req, res, '数据有误', null);
  721. } else {
  722. callback(req, res, err, pageRstArray);
  723. }
  724. })
  725. },
  726. getMultiReportsEx: function (req, res) {
  727. //原则说明:把所有报表模板集中获取,统一filter,只读一次数据!(有空再整)
  728. let params = JSON.parse(req.body.params),
  729. prj_id = params.prj_id,
  730. rpt_ids = params.rpt_ids.split(','),
  731. pageSize = params.pageSize,
  732. orientation = params.orientation,
  733. customizeCfg = params.custCfg,
  734. option = params.option;
  735. let user_id = req.session.sessionUser.id;
  736. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  737. },
  738. getReportAllPagesSvg: function (req, res) {
  739. let params = JSON.parse(req.body.params),
  740. rpt_id = params.rpt_tpl_id,
  741. prj_id = params.prj_id,
  742. pageSize = params.pageSize,
  743. orientation = params.orientation,
  744. customizeCfg = params.custCfg
  745. ;
  746. let user_id = req.session.sessionUser.id;
  747. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_SVG, function (err, pageRst) {
  748. let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
  749. callback(req, res, err, svgRstStrArr);
  750. });
  751. },
  752. createExcelFilesInOneBook: function (req, res) {
  753. let params = JSON.parse(req.body.params),
  754. prj_id = params.prj_id,
  755. rpt_ids = params.rpt_ids,
  756. rptName = params.rptName,
  757. pageSize = params.pageSize,
  758. orientation = params.orientation,
  759. customizeCfg = params.custCfg,
  760. option = params.option;
  761. let user_id = req.session.sessionUser.id;
  762. let parallelFunctions = [];
  763. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  764. for (let idx = 0; idx < rpt_ids.length; idx++) {
  765. let r_id = rpt_ids[idx];
  766. parallelFunctions.push((function (rpt_id) {
  767. return function (cb) {
  768. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  769. if(err){
  770. cb(err);
  771. }
  772. else{
  773. cb(err, pageRst);
  774. }
  775. })
  776. }
  777. })(parseInt(r_id)));
  778. }
  779. async.parallel(parallelFunctions, function (err, pageRstArray) {
  780. if (err) {
  781. callback(req, res, '数据有误', null);
  782. } else {
  783. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(uuidName){
  784. let fileRst = {uuid: uuidName, reportName: rptName};
  785. callback(req, res, err, fileRst);
  786. });
  787. }
  788. })
  789. },
  790. createExcelFiles: function (req, res) {
  791. let params = JSON.parse(req.body.params),
  792. prj_id = params.prj_id,
  793. rpt_ids = params.rpt_ids,
  794. rpt_names = params.rpt_names,
  795. pageSize = params.pageSize,
  796. orientation = params.orientation,
  797. isOneSheet = params.isOneSheet,
  798. customizeCfg = params.custCfg,
  799. option = params.option;
  800. let user_id = req.session.sessionUser.id;
  801. let parallelFunctions = [];
  802. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  803. for (let idx = 0; idx < rpt_ids.length; idx++) {
  804. let r_id = rpt_ids[idx];
  805. let r_name = rpt_names[idx];
  806. parallelFunctions.push((function (rpt_id, rpt_name) {
  807. return function (cb) {
  808. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  809. if(err){
  810. cb(err);
  811. } else {
  812. rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, isOneSheet, null, null, function(uuidName){
  813. let fileRst = {uuid: uuidName, reportName: rpt_name};
  814. cb(err, fileRst);
  815. })
  816. }
  817. })
  818. }
  819. })(parseInt(r_id), r_name));
  820. }
  821. async.parallel(parallelFunctions, function (err, fileRstArray) {
  822. if (err) {
  823. callback(req, res, '数据有误', null);
  824. } else {
  825. // console.log(err);
  826. callback(req, res, err, fileRstArray);
  827. }
  828. })
  829. },
  830. getFileByUUID: function (req, res) {
  831. let uuid = req.params.uuid,
  832. rptName = req.params.rptName,
  833. suffix = "." + req.params.suffix
  834. ;
  835. // let user_id = req.session.sessionUser.id; //未来要校验user id
  836. try {
  837. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  838. let rptNameURI = encodeURI(rptName);
  839. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix );
  840. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuid + suffix);
  841. filestream.on('data', function(chunk) {
  842. res.write(chunk);
  843. });
  844. filestream.on('end', function() {
  845. res.end();
  846. });
  847. } catch (e) {
  848. console.log(e);
  849. }
  850. },
  851. getExcel: function(req, res) {
  852. let prj_id = req.params.prj_id,
  853. rpt_id = req.params.rpt_id,
  854. pageSize = req.params.size,
  855. orientation = req.params.orientation,
  856. rptName = req.params.rptName,
  857. isOneSheet = req.params.isOneSheet,
  858. option = req.params.option
  859. ;
  860. let customizeCfg = null;
  861. let user_id = req.session.sessionUser.id;
  862. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  863. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_EXCEL, function(err, pageRst){
  864. try {
  865. rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, null, null, function(uuidName){
  866. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  867. let rptNameURI = encodeURI(rptName);
  868. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".xlsx\"; filename*=utf-8''" + rptNameURI + '.xlsx' );
  869. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.xlsx');
  870. filestream.on('data', function(chunk) {
  871. res.write(chunk);
  872. });
  873. filestream.on('end', function() {
  874. res.end();
  875. });
  876. });
  877. } catch (e) {
  878. console.log(e);
  879. }
  880. })
  881. },
  882. getExcelInOneBook: function (req, res) {
  883. let prj_id = req.params.prj_id,
  884. rpt_ids = req.params.rpt_ids.split(','),
  885. pageSize = req.params.size,
  886. rptName = req.params.rptName,
  887. option = req.params.option;
  888. let user_id = req.session.sessionUser.id;
  889. let parallelFunctions = [];
  890. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  891. for (let id of rpt_ids) {
  892. parallelFunctions.push((function (rpt_id) {
  893. return function (cb) {
  894. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, null, null, dftOption, JV.OUTPUT_TYPE_EXCEL, function (err, pageRst) {
  895. if(err){
  896. cb(err);
  897. }
  898. else{
  899. cb(null, pageRst);
  900. }
  901. })
  902. }
  903. })(parseInt(id)));
  904. }
  905. async.parallel(parallelFunctions, function (err, pageRstArray) {
  906. if (err) {
  907. callback(req, res, '数据有误', null);
  908. } else {
  909. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(tmpFilePath){
  910. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  911. let rptNameURI = encodeURI(rptName);
  912. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".xlsx\"; filename*=utf-8''" + rptNameURI + '.xlsx');
  913. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + tmpFilePath + '.xlsx');
  914. filestream.on('data', function(chunk) {
  915. res.write(chunk);
  916. });
  917. filestream.on('end', function() {
  918. res.end();
  919. });
  920. });
  921. }
  922. })
  923. },
  924. createPdfFiles: function (req, res) {
  925. let params = JSON.parse(req.body.params),
  926. prj_id = params.prj_id,
  927. rpt_ids = params.rpt_ids,
  928. rpt_names = params.rpt_names,
  929. pageSize = params.pageSize,
  930. orientation = params.orientation,
  931. customizeCfg = params.custCfg,
  932. option = params.option;
  933. let user_id = req.session.sessionUser.id;
  934. let parallelFunctions = [];
  935. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  936. for (let idx = 0; idx < rpt_ids.length; idx++) {
  937. let r_id = rpt_ids[idx];
  938. let r_name = rpt_names[idx];
  939. parallelFunctions.push((function (rpt_id, rpt_name) {
  940. return function (cb) {
  941. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, pageRst) {
  942. if(err){
  943. cb(err);
  944. }
  945. else{
  946. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rpt_name, function(uuidName){
  947. let fileRst = {uuid: uuidName, reportName: rpt_name};
  948. cb(err, fileRst);
  949. })
  950. }
  951. })
  952. }
  953. })(parseInt(r_id), r_name));
  954. }
  955. async.parallel(parallelFunctions, function (err, fileRstArray) {
  956. if (err) {
  957. callback(req, res, '数据有误', null);
  958. } else {
  959. // console.log(err);
  960. callback(req, res, err, fileRstArray);
  961. }
  962. })
  963. },
  964. getPDF:function (req, res) {
  965. let prj_id = req.params.prj_id,
  966. rpt_id = req.params.rpt_id,
  967. pageSize = req.params.size,
  968. orientation = req.params.orientation,
  969. rptName = req.params.rptName
  970. ;
  971. let user_id = req.session.sessionUser.id;
  972. getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, null, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_PDF, function(err, pageRst){
  973. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rptName,function (uuidName) {
  974. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  975. // res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".pdf");
  976. let rptNameURI = encodeURI(rptName);
  977. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".pdf\"; filename*=utf-8''" + rptNameURI + ".pdf" );
  978. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.pdf');
  979. filestream.on('data', function(chunk) {
  980. res.write(chunk);
  981. });
  982. filestream.on('end', function() {
  983. res.end();
  984. });
  985. })
  986. })
  987. },
  988. getTestReportAllPages: function(req, res){
  989. let rpt_id = req.body.ID;
  990. let pageSize = req.body.pageSize;
  991. getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
  992. //fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
  993. callback(req, res, err, pageRst);
  994. })
  995. },
  996. getTestExcel: function(req, res) {
  997. let rpt_id = req.params.id,
  998. pageSize = req.params.size,
  999. rptName = req.params.rptName,
  1000. isOneSheet = req.params.isOneSheet,
  1001. option = req.params.option;
  1002. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  1003. getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function(err, pageRst){
  1004. fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
  1005. try {
  1006. rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, null, null, function(uuidName){
  1007. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  1008. res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
  1009. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.xlsx');
  1010. filestream.on('data', function(chunk) {
  1011. res.write(chunk);
  1012. });
  1013. filestream.on('end', function() {
  1014. res.end();
  1015. });
  1016. });
  1017. } catch (e) {
  1018. console.log(e);
  1019. }
  1020. })
  1021. },
  1022. getTestExcelInOneBook: function(req, res) {
  1023. let rpt_ids = req.params.ids.split(','),
  1024. pageSize = req.params.size,
  1025. rptName = req.params.rptName,
  1026. option = req.params.option;
  1027. let parallelFunctions = [];
  1028. let dftOption = option||JV.PAGING_OPTION_NORMAL;
  1029. for (let id of rpt_ids) {
  1030. parallelFunctions.push((function (rpt_id) {
  1031. return function (cb) {
  1032. getAllPagesCommonOrg(rpt_id, pageSize, dftOption, function (err, pageRst) {
  1033. if(err){
  1034. cb(err);
  1035. }
  1036. else{
  1037. cb(null, pageRst);
  1038. }
  1039. })
  1040. }
  1041. })(parseInt(id)));
  1042. }
  1043. async.parallel(parallelFunctions, function (err, pageRstArray) {
  1044. if (err) {
  1045. callback(req, res, '数据有误', null);
  1046. } else {
  1047. rpt_xl_util.exportExcelInOneBook(pageRstArray, pageSize, rptName, function(tmpFilePath){
  1048. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  1049. res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
  1050. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + tmpFilePath + '.xlsx');
  1051. filestream.on('data', function(chunk) {
  1052. res.write(chunk);
  1053. });
  1054. filestream.on('end', function() {
  1055. res.end();
  1056. });
  1057. });
  1058. //callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
  1059. }
  1060. })
  1061. },
  1062. getTestPDF:function (req, res) {
  1063. let rpt_id = req.params.id,
  1064. pageSize = req.params.size,
  1065. rptName = req.params.rptName;
  1066. getAllPagesCommonOrg(rpt_id, pageSize, JV.PAGING_OPTION_NORMAL, function(err, pageRst){
  1067. rpt_pdf_util.export_pdf_file(pageRst, pageSize, rptName,function (uuidName) {
  1068. res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  1069. // res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".pdf");
  1070. let rptNameURI = encodeURI(rptName);
  1071. res.setHeader("Content-Disposition", "attachment; filename=\"" + rptNameURI + ".pdf\"; filename*=utf-8''" + rptNameURI + ".pdf" );
  1072. let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + uuidName + '.pdf');
  1073. filestream.on('data', function(chunk) {
  1074. res.write(chunk);
  1075. });
  1076. filestream.on('end', function() {
  1077. res.end();
  1078. });
  1079. })
  1080. })
  1081. }
  1082. };