jpc_ex.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. 'use strict';
  2. const JV = require('./jpc_value_define');
  3. const JpcBand = require('./jpc_band');
  4. const JpcFlowTab = require('./jpc_flow_tab');
  5. const JpcBillTab = require('./jpc_bill_tab');
  6. const JpcCrossTab = require('./jpc_cross_tab');
  7. const JpcField = require('./jpc_field');
  8. const JpcParam = require('./jpc_param');
  9. const JpcFunc = require('./jpc_function');
  10. const JpcEvent = require('./jpc_event');
  11. const JpcData = require('./jpc_data');
  12. const JpcCommonHelper = require('./helper/jpc_helper_common');
  13. const $JE = require('./jpc_rte'); // Important: for self-define function execution purpose
  14. const JpcExSrv = function() {};
  15. JpcExSrv.prototype.createNew = function() {
  16. function private_buildDftItems(rptTpl, dftCollection, propArray, nodeName) {
  17. const rst = {};
  18. if (dftCollection) {
  19. for (let i = 0; i < dftCollection.length; i++) {
  20. const item = {};
  21. for (let j = 0; j < propArray.length; j++) {
  22. item[propArray[j]] = dftCollection[i][propArray[j]];
  23. }
  24. rst[dftCollection[i][JV.PROP_ID]] = item;
  25. }
  26. if (rptTpl && rptTpl[nodeName] && rptTpl[nodeName].length > 0) {
  27. for (let i = 0; i < rptTpl[nodeName].length; i++) {
  28. const rptDftItem = rptTpl[nodeName][i];
  29. if (rst[rptDftItem[JV.PROP_ID]] === undefined) {
  30. const item = {};
  31. for (let j = 0; j < propArray.length; j++) {
  32. item[propArray[j]] = rptDftItem[propArray[j]];
  33. }
  34. rst[rptDftItem[JV.PROP_ID]] = item;
  35. }
  36. }
  37. }
  38. }
  39. return rst;
  40. }
  41. function private_buildDftControls(rptTpl, dftControlCollection) {
  42. return private_buildDftItems(rptTpl, dftControlCollection, JV.CONTROL_PROPS, JV.NODE_CONTROL_COLLECTION);
  43. }
  44. function private_buildDftFonts(rptTpl, dftFontCollection) {
  45. return private_buildDftItems(rptTpl, dftFontCollection, JV.FONT_PROPS, JV.NODE_FONT_COLLECTION);
  46. }
  47. function private_buildDftStyles(rptTpl, dftStyleCollection) {
  48. const rst = {};
  49. function private_CopyBorder(destItem, srcItem) {
  50. destItem[JV.PROP_LINE_WEIGHT] = srcItem[JV.PROP_LINE_WEIGHT];
  51. destItem[JV.PROP_DASH_STYLE] = srcItem[JV.PROP_DASH_STYLE];
  52. destItem[JV.PROP_COLOR] = srcItem[JV.PROP_COLOR];
  53. }
  54. if (dftStyleCollection) {
  55. for (let i = 0; i < dftStyleCollection.length; i++) {
  56. const item = {};
  57. if (dftStyleCollection[i][JV.PROP_BORDER_STYLE] && dftStyleCollection[i][JV.PROP_BORDER_STYLE].length > 0) {
  58. for (let j = 0; j < dftStyleCollection[i][JV.PROP_BORDER_STYLE].length; j++) {
  59. const borderItem = {};
  60. private_CopyBorder(borderItem, dftStyleCollection[i][JV.PROP_BORDER_STYLE][j]);
  61. item[dftStyleCollection[i][JV.PROP_BORDER_STYLE][j][JV.PROP_POSITION]] = borderItem;
  62. }
  63. }
  64. rst[dftStyleCollection[i][JV.PROP_ID]] = item;
  65. }
  66. if (rptTpl && rptTpl[JV.NODE_STYLE_COLLECTION] && rptTpl[JV.NODE_STYLE_COLLECTION].length > 0) {
  67. for (let i = 0; i < rptTpl[JV.NODE_STYLE_COLLECTION].length; i++) {
  68. const rptDftItem = rptTpl[JV.NODE_STYLE_COLLECTION][i];
  69. if (rst[rptDftItem[JV.PROP_ID]] === undefined) {
  70. if (rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Top') > 0) {
  71. const key = rptDftItem[JV.PROP_ID].substr(0, rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Top'));
  72. if (rst[key]) {
  73. const item = {};
  74. if (rst[key][JV.PROP_LEFT]) {
  75. item[JV.PROP_LEFT] = {};
  76. private_CopyBorder(item[JV.PROP_LEFT], rst[key][JV.PROP_LEFT]);
  77. }
  78. if (rst[key][JV.PROP_RIGHT]) {
  79. item[JV.PROP_RIGHT] = {};
  80. private_CopyBorder(item[JV.PROP_RIGHT], rst[key][JV.PROP_RIGHT]);
  81. }
  82. if (rst[key][JV.PROP_TOP]) {
  83. item[JV.PROP_TOP] = {};
  84. private_CopyBorder(item[JV.PROP_TOP], rst[key][JV.PROP_TOP]);
  85. }
  86. rst[rptDftItem[JV.PROP_ID]] = item;
  87. }
  88. } else if (rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Middle') > 0) {
  89. const key = rptDftItem[JV.PROP_ID].substr(0, rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Middle'));
  90. if (rst[key]) {
  91. const item = {};
  92. if (rst[key][JV.PROP_LEFT]) {
  93. item[JV.PROP_LEFT] = {};
  94. private_CopyBorder(item[JV.PROP_LEFT], rst[key][JV.PROP_LEFT]);
  95. }
  96. if (rst[key][JV.PROP_RIGHT]) {
  97. item[JV.PROP_RIGHT] = {};
  98. private_CopyBorder(item[JV.PROP_RIGHT], rst[key][JV.PROP_RIGHT]);
  99. }
  100. rst[rptDftItem[JV.PROP_ID]] = item;
  101. }
  102. } else if (rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Bottom') > 0) {
  103. const key = rptDftItem[JV.PROP_ID].substr(0, rptDftItem[JV.PROP_ID].indexOf('_AutoHeightMerge_Bottom'));
  104. if (rst[key]) {
  105. const item = {};
  106. if (rst[key][JV.PROP_LEFT]) {
  107. item[JV.PROP_LEFT] = {};
  108. private_CopyBorder(item[JV.PROP_LEFT], rst[key][JV.PROP_LEFT]);
  109. }
  110. if (rst[key][JV.PROP_RIGHT]) {
  111. item[JV.PROP_RIGHT] = {};
  112. private_CopyBorder(item[JV.PROP_RIGHT], rst[key][JV.PROP_RIGHT]);
  113. }
  114. if (rst[key][JV.PROP_BOTTOM]) {
  115. item[JV.PROP_BOTTOM] = {};
  116. private_CopyBorder(item[JV.PROP_BOTTOM], rst[key][JV.PROP_BOTTOM]);
  117. }
  118. rst[rptDftItem[JV.PROP_ID]] = item;
  119. }
  120. } else {
  121. const item = {};
  122. for (let j = 0; j < rptDftItem[JV.PROP_BORDER_STYLE].length; j++) {
  123. const borderItem = {};
  124. private_CopyBorder(borderItem, rptDftItem[JV.PROP_BORDER_STYLE][j]);
  125. item[rptDftItem[JV.PROP_BORDER_STYLE][j][JV.PROP_POSITION]] = borderItem;
  126. }
  127. rst[rptDftItem[JV.PROP_ID]] = item;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return rst;
  134. }
  135. const JpcResult = {};
  136. JpcResult.initialize = function(rptTpl) {
  137. const me = this;
  138. if (rptTpl[JV.NODE_FLOW_INFO]) {
  139. me.flowTab = JpcFlowTab.createNew();
  140. me.flowTab.initialize(false);
  141. me.isFollowMode = false;
  142. }
  143. if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
  144. me.flowTabEx = JpcFlowTab.createNew();
  145. me.flowTabEx.initialize(true);
  146. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.PROP_FLOW_EX_DISPLAY_MODE] === JV.DISPLAY_MODE_FOLLOW) {
  147. me.isFollowMode = true;
  148. }
  149. }
  150. if (rptTpl[JV.NODE_BILL_INFO]) {
  151. me.billTab = JpcBillTab.createNew();
  152. me.billTab.initialize();
  153. }
  154. if (rptTpl[JV.NODE_CROSS_INFO]) {
  155. me.crossTab = JpcCrossTab.createNew();
  156. me.crossTab.initialize();
  157. }
  158. me.totalPages = 0;
  159. me.exTotalPages = 0;
  160. me.runTimePageData = {};
  161. me.fields = JpcField.createNew(rptTpl);
  162. me.params = JpcParam.createNew(rptTpl);
  163. // console.log('params:');
  164. // console.log(me.params);
  165. me.formulas = JpcFunc.createNew(rptTpl);
  166. me.events = JpcEvent.createNew(rptTpl);
  167. };
  168. JpcResult.analyzeData = function($CTX_HELPER, rptTpl, dataObj, defProperties, option, outputType, $CUSTOM_DEFINE, splitArchives = []) {
  169. const me = this;
  170. const dftPagingOption = option || JV.PAGING_OPTION_NORMAL;
  171. // 1. data object
  172. let dataHelper = JpcData.createNew();
  173. // console.log(JSON.stringify(rptTpl));
  174. me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_ANALYZING, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties); // 在分析前运行,主要是增加灵活性,比如:重新编排数据的主从关系
  175. // console.log(JSON.stringify(rptTpl));
  176. if (me.crossTab) {
  177. me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_PAGING, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties);
  178. dataHelper.analyzeData(rptTpl, dataObj);
  179. me.crossTab.sorting(rptTpl, dataObj, dataHelper.dataSeq.slice(0), me);
  180. } else {
  181. dataHelper.analyzeData(rptTpl, dataObj);
  182. if (splitArchives.length > 0) {
  183. // 这里需要根据标记指标拆分数据 {rpt_id: tplNode.refId, split_field_id: parseInt(tplNode.splitArchiveField)
  184. for (const splitArc of splitArchives) {
  185. if (splitArc.rpt_id === rptTpl.id) {
  186. // 匹配报表ID通过,再找分割指示指标
  187. const splitField = $JE.F(splitArc.split_field_id, me);
  188. if (splitField) {
  189. rptTpl.splitFieldId = splitArc.split_field_id;
  190. const df = $JE.getFieldValueArray(splitField, dataObj);
  191. dataObj.splitArcVals = df;
  192. dataObj.splitField = splitField;
  193. break;
  194. }
  195. }
  196. }
  197. }
  198. // 2. tab object
  199. // pre-condition: the data should be sorted in SQL/NoSQL level!
  200. // let dt1 = new Date();
  201. if (me.flowTab) {
  202. me.flowTab.sorting(rptTpl, dataObj, dataHelper.dataSeq.slice(0), me);
  203. if (me.flowTabEx) {
  204. me.flowTabEx.sorting(rptTpl, dataObj, dataHelper.exDataSeq.slice(0), me);
  205. }
  206. }
  207. if (me.billTab) {
  208. me.billTab.sorting(rptTpl, dataObj, dataHelper.dataSeq.slice(0), me);
  209. }
  210. // let dt2 = new Date();
  211. // alert(dt2 - dt1);
  212. // 3. formulas
  213. me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_PAGING, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties);
  214. }
  215. // 4. paging
  216. me.paging(rptTpl, dataObj, defProperties, dftPagingOption, outputType);
  217. // alert('analyzeData was completed!');
  218. // for garbage collection:
  219. dataHelper = null;
  220. };
  221. JpcResult.paging = function(rptTpl, dataObj, defProperties, option, outputType) {
  222. const me = this;
  223. const dftPagingOption = option || JV.PAGING_OPTION_NORMAL;
  224. if (me.flowTab) {
  225. if (me.isFollowMode) {
  226. me.totalPages = me.flowTab.preSetupPages(rptTpl, dataObj, defProperties, dftPagingOption, me, me.flowTabEx, outputType);
  227. } else {
  228. me.totalPages = me.flowTab.preSetupPages(rptTpl, dataObj, defProperties, dftPagingOption, me, null, outputType);
  229. if (me.flowTabEx) {
  230. me.exTotalPages = me.flowTabEx.preSetupPages(rptTpl, dataObj, defProperties, dftPagingOption, me, null, outputType);
  231. // console.log('ad-hoc flow pages: ' + me.exTotalPages);
  232. }
  233. me.totalPages += me.exTotalPages;
  234. }
  235. } else if (me.crossTab) {
  236. // me.totalPages = me.crossTab.preSetupPages(rptTpl, defProperties, dftPagingOption);
  237. me.totalPages = me.crossTab.preSetupPages(rptTpl, defProperties, JV.PAGING_OPTION_NORMAL); // infinity对交叉表来说无意义
  238. } else if (me.billTab) {
  239. me.totalPages = me.billTab.paging(rptTpl, dataObj);
  240. }
  241. };
  242. JpcResult.getDftRowsPerPage = function(rptTpl, defProperties) {
  243. const me = this;
  244. let rst = 1;
  245. if (me.flowTab) {
  246. rst = me.flowTab.getDftRowsPerPage(rptTpl, defProperties, me);
  247. } else if (me.crossTab) {
  248. // 实际业务可以暂时不提供
  249. } else if (me.billTab) {
  250. // 实际业务可以暂时不提供
  251. }
  252. return rst;
  253. };
  254. JpcResult.executeFormulas = function($CTX_HELPER, runType, $CURRENT_TEMPLATE, $CURRENT_DATA, $CURRENT_RPT, $CUSTOM_DEFINE, $PAGE_PROPERTIES) {
  255. const execFmlMe = this;
  256. for (let execFmlIdx = 0; execFmlIdx < execFmlMe.formulas.length; execFmlIdx++) {
  257. // remark: 搞这么复杂的变量名是为了防止与表达式起冲突(如循环变量i,j,k,容易造成变量冲突且不容易看出问题)
  258. // console.log('execFmlMe.formulas[execFmlIdx][JV.PROP_RUN_TYPE]: ' + execFmlMe.formulas[execFmlIdx][JV.PROP_RUN_TYPE]);
  259. // console.log('runType: ' + runType);
  260. if (execFmlMe.formulas[execFmlIdx][JV.PROP_RUN_TYPE] === runType) {
  261. const expression = execFmlMe.formulas[execFmlIdx][JV.PROP_EXPRESSION];
  262. if (expression) {
  263. const $ME = execFmlMe.formulas[execFmlIdx];
  264. // console.log('current expression idx: ' + execFmlIdx);
  265. // console.log(expression);
  266. try {
  267. eval(expression);
  268. } catch (ex) {
  269. console.log('current expression idx: ' + execFmlIdx);
  270. console.log(expression);
  271. console.log(ex);
  272. }
  273. }
  274. }
  275. }
  276. };
  277. JpcResult.outputAsPreviewPage = function(rptTpl, defProperties) {
  278. const me = this;
  279. const rst = {};
  280. rst[JV.NODE_CONTROL_COLLECTION] = private_buildDftControls(rptTpl, (defProperties === null) ? null : defProperties.ctrls);
  281. rst[JV.NODE_STYLE_COLLECTION] = private_buildDftStyles(rptTpl, (defProperties === null) ? null : defProperties.styles);
  282. rst[JV.NODE_FONT_COLLECTION] = private_buildDftFonts(rptTpl, (defProperties === null) ? null : defProperties.fonts);
  283. rst[JV.NODE_PAGE_INFO] = {};
  284. rst[JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MAIN_INFO_RPT_NAME];
  285. rst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE] = JpcCommonHelper.getPageSize(rptTpl);
  286. rst[JV.NODE_PAGE_INFO][JV.NODE_MARGINS] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS];
  287. rst.items = [];
  288. let bands = JpcBand.createNew(rptTpl, defProperties);
  289. function getPageMergeBorder() {
  290. let mergeRst = null;
  291. if (bands[JV.BAND_PROP_MERGE_BAND]) {
  292. const mergedBand = bands[JV.BAND_PROP_MERGE_BAND];
  293. mergeRst = {};
  294. mergeRst[JV.PROP_LEFT] = parseInt(mergedBand[JV.PROP_LEFT].toFixed(0));
  295. mergeRst[JV.PROP_RIGHT] = parseInt(mergedBand[JV.PROP_RIGHT].toFixed(0));
  296. mergeRst[JV.PROP_TOP] = parseInt(mergedBand[JV.PROP_TOP].toFixed(0));
  297. mergeRst[JV.PROP_BOTTOM] = parseInt(mergedBand[JV.PROP_BOTTOM].toFixed(0));
  298. }
  299. return mergeRst;
  300. }
  301. try {
  302. // 1.
  303. const rstPage = {};
  304. rstPage[JV.PROP_PAGE_SEQ] = 1;
  305. rstPage[JV.PROP_SIGNATURE_CELLS] = [];
  306. rstPage[JV.PROP_SIGNATURE_DATE_CELLS] = [];
  307. rstPage[JV.PROP_SIGNATURE_AUDIT_CELLS] = [];
  308. rstPage[JV.PROP_INTERACT_CELLS] = [];
  309. if (me.flowTab) {
  310. rstPage[JV.PROP_CELLS] = me.flowTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
  311. rstPage[JV.PROP_INTERACT_CELLS] = me.flowTab.interactRst;
  312. rstPage[JV.PROP_SIGNATURE_CELLS] = me.flowTab.signatureRst;
  313. rstPage[JV.PROP_SIGNATURE_DATE_CELLS] = me.flowTab.signatureDateRst;
  314. rstPage[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.flowTab.signatureAuditRst;
  315. } else if (me.crossTab) {
  316. rstPage[JV.PROP_CELLS] = me.crossTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
  317. rstPage[JV.PROP_INTERACT_CELLS] = me.crossTab.interactRst;
  318. rstPage[JV.PROP_SIGNATURE_CELLS] = me.crossTab.signatureRst;
  319. rstPage[JV.PROP_SIGNATURE_DATE_CELLS] = me.crossTab.signatureDateRst;
  320. rstPage[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.crossTab.signatureAuditRst;
  321. } else if (me.billTab) {
  322. rstPage[JV.PROP_CELLS] = me.billTab.outputAsPreviewPage(rptTpl, bands, rst[JV.NODE_CONTROL_COLLECTION], me);
  323. rstPage[JV.PROP_INTERACT_CELLS] = me.billTab.interactRst;
  324. rstPage[JV.PROP_SIGNATURE_CELLS] = me.billTab.signatureRst;
  325. rstPage[JV.PROP_SIGNATURE_DATE_CELLS] = me.billTab.signatureDateRst;
  326. rstPage[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.billTab.signatureAuditRst;
  327. }
  328. const pageMergeBorder = getPageMergeBorder();
  329. if (pageMergeBorder) {
  330. rstPage[JV.PROP_PAGE_MERGE_BORDER] = pageMergeBorder;
  331. }
  332. rst.items.push(rstPage);
  333. // 2.
  334. if (bands[JV.BAND_PROP_MERGE_BAND]) {
  335. const mergedBand = {};
  336. const band = bands[JV.BAND_PROP_MERGE_BAND];
  337. mergedBand[JV.PROP_LEFT] = parseInt(band[JV.PROP_LEFT].toFixed(0));
  338. mergedBand[JV.PROP_RIGHT] = parseInt(band[JV.PROP_RIGHT].toFixed(0));
  339. mergedBand[JV.PROP_TOP] = parseInt(band[JV.PROP_TOP].toFixed(0));
  340. mergedBand[JV.PROP_BOTTOM] = parseInt(band[JV.PROP_BOTTOM].toFixed(0));
  341. mergedBand[JV.BAND_PROP_STYLE] = band[JV.BAND_PROP_STYLE];
  342. rst[JV.BAND_PROP_MERGE_BAND] = mergedBand;
  343. }
  344. } catch (exception) {
  345. console.log(exception);
  346. } finally {
  347. bands = null;
  348. }
  349. return rst;
  350. };
  351. JpcResult.outputAsSimpleJSONPageArray = function($CTX_HELPER, rptTpl, dataObj, startPage, endPage, defProperties, customizeCfg, $CUSTOM_DEFINE) {
  352. const me = this;
  353. const rst = {};
  354. if ((startPage > 0) && (startPage <= endPage) && (endPage <= me.totalPages)) {
  355. rst[JV.NODE_CONTROL_COLLECTION] = private_buildDftControls(rptTpl, (defProperties === null) ? null : defProperties.ctrls);
  356. // console.log('controls: ');
  357. // console.log(rst[JV.NODE_CONTROL_COLLECTION]);
  358. rst[JV.NODE_STYLE_COLLECTION] = private_buildDftStyles(rptTpl, (defProperties === null) ? null : defProperties.styles);
  359. rst[JV.NODE_FONT_COLLECTION] = private_buildDftFonts(rptTpl, (defProperties === null) ? null : defProperties.fonts);
  360. rst[JV.NODE_PAGE_INFO] = {};
  361. rst[JV.NODE_PAGE_INFO][JV.NODE_MAIN_INFO_RPT_NAME] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MAIN_INFO_RPT_NAME];
  362. rst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE] = JpcCommonHelper.getPageSize(rptTpl);
  363. rst[JV.NODE_PAGE_INFO][JV.NODE_MARGINS] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS];
  364. rst[JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE];
  365. rst.items = [];
  366. let bands = JpcBand.createNew(rptTpl, defProperties);
  367. try {
  368. for (let page = startPage; page <= endPage; page++) {
  369. me.runTimePageData.currentPage = page;
  370. me.executeFormulas($CTX_HELPER, JV.RUN_TYPE_BEFORE_OUTPUT, rptTpl, dataObj, me, $CUSTOM_DEFINE, defProperties);
  371. rst.items.push(me.outputAsSimpleJSONPage(rptTpl, dataObj, bands, page, rst[JV.NODE_CONTROL_COLLECTION], rst[JV.NODE_FONT_COLLECTION], customizeCfg));
  372. }
  373. if (bands[JV.BAND_PROP_MERGE_BAND]) {
  374. const mergedBand = {};
  375. const band = bands[JV.BAND_PROP_MERGE_BAND];
  376. mergedBand[JV.PROP_LEFT] = parseInt(band[JV.PROP_LEFT].toFixed(0));
  377. mergedBand[JV.PROP_RIGHT] = parseInt(band[JV.PROP_RIGHT].toFixed(0));
  378. mergedBand[JV.PROP_TOP] = parseInt(band[JV.PROP_TOP].toFixed(0));
  379. mergedBand[JV.PROP_BOTTOM] = parseInt(band[JV.PROP_BOTTOM].toFixed(0));
  380. mergedBand[JV.BAND_PROP_STYLE] = band[JV.BAND_PROP_STYLE];
  381. rst[JV.BAND_PROP_MERGE_BAND] = mergedBand;
  382. }
  383. } catch (exception) {
  384. console.log(exception);
  385. } finally {
  386. bands = null;
  387. }
  388. }
  389. return rst;
  390. };
  391. JpcResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, bands, page, controls, fonts, customizeCfg) {
  392. const me = this;
  393. let rst = null;
  394. function getPageMergeBorder() {
  395. let mergeRst = null;
  396. if (bands[JV.BAND_PROP_MERGE_BAND]) {
  397. const mergedBand = bands[JV.BAND_PROP_MERGE_BAND];
  398. mergeRst = {};
  399. mergeRst[JV.PROP_LEFT] = parseInt(mergedBand[JV.PROP_LEFT].toFixed(0));
  400. mergeRst[JV.PROP_RIGHT] = parseInt(mergedBand[JV.PROP_RIGHT].toFixed(0));
  401. mergeRst[JV.PROP_TOP] = parseInt(mergedBand[JV.PROP_TOP].toFixed(0));
  402. mergeRst[JV.PROP_BOTTOM] = parseInt(mergedBand[JV.PROP_BOTTOM].toFixed(0));
  403. }
  404. return mergeRst;
  405. }
  406. if (me.totalPages >= page) {
  407. rst = {};
  408. rst[JV.PROP_PAGE_SEQ] = page;
  409. // rst.cells = [];
  410. let adHocMergePos = null;
  411. if (me.flowTab) {
  412. // console.log('page_seg_map:');
  413. // console.log(me.flowTab.page_seg_map);
  414. if (me.totalPages - me.exTotalPages >= page) {
  415. if (me.flowTab.paging_option === JV.PAGING_OPTION_INFINITY) {
  416. adHocMergePos = {};
  417. }
  418. rst[JV.PROP_CELLS] = me.flowTab.outputAsSimpleJSONPage(rptTpl, dataObj, page, bands, controls, fonts, adHocMergePos, me, customizeCfg);
  419. rst[JV.PROP_SIGNATURE_CELLS] = me.flowTab.signatureRst;
  420. rst[JV.PROP_SIGNATURE_DATE_CELLS] = me.flowTab.signatureDateRst;
  421. rst[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.flowTab.signatureAuditRst;
  422. rst[JV.PROP_INTERACT_CELLS] = me.flowTab.interactRst;
  423. rst[JV.PROP_FIGURE_CELLS] = me.flowTab.figureRst;
  424. if (adHocMergePos) {
  425. adHocMergePos[JV.NODE_PAGE_SIZE] = JpcCommonHelper.getPageSize(rptTpl);
  426. rst[JV.PAGE_SPECIAL_MERGE_POS] = adHocMergePos;
  427. }
  428. } else {
  429. if (!me.isFollowMode) {
  430. rst[JV.PROP_CELLS] = me.flowTabEx.outputAsSimpleJSONPage(rptTpl, dataObj, page - (me.totalPages - me.exTotalPages), bands, controls, fonts, adHocMergePos, me, customizeCfg);
  431. rst[JV.PROP_SIGNATURE_CELLS] = me.flowTabEx.signatureRst;
  432. rst[JV.PROP_SIGNATURE_DATE_CELLS] = me.flowTabEx.signatureDateRst;
  433. rst[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.flowTabEx.signatureAuditRst;
  434. rst[JV.PROP_INTERACT_CELLS] = me.flowTabEx.interactRst;
  435. rst[JV.PROP_FIGURE_CELLS] = me.flowTabEx.figureRst;
  436. }
  437. }
  438. } else if (me.crossTab) {
  439. rst[JV.PROP_CELLS] = me.crossTab.outputAsSimpleJSONPage(rptTpl, dataObj, page, bands, controls, fonts, me, customizeCfg);
  440. rst[JV.PROP_SIGNATURE_CELLS] = me.crossTab.signatureRst;
  441. rst[JV.PROP_SIGNATURE_DATE_CELLS] = me.crossTab.signatureDateRst;
  442. rst[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.crossTab.signatureAuditRst;
  443. rst[JV.PROP_INTERACT_CELLS] = me.crossTab.interactRst;
  444. rst[JV.PROP_FIGURE_CELLS] = me.crossTab.figureRst;
  445. } else if (me.billTab) {
  446. rst[JV.PROP_CELLS] = me.billTab.outputAsSimpleJSONPage(rptTpl, dataObj, page, bands, controls, fonts, me, customizeCfg);
  447. rst[JV.PROP_SIGNATURE_CELLS] = me.billTab.signatureRst;
  448. rst[JV.PROP_SIGNATURE_DATE_CELLS] = me.billTab.signatureDateRst;
  449. rst[JV.PROP_SIGNATURE_AUDIT_CELLS] = me.billTab.signatureAuditRst;
  450. rst[JV.PROP_INTERACT_CELLS] = me.billTab.interactRst;
  451. rst[JV.PROP_FIGURE_CELLS] = me.billTab.figureRst;
  452. }
  453. if (!(me.flowTab && me.flowTab.paging_option === JV.PAGING_OPTION_INFINITY)) {
  454. const pageMergeBorder = getPageMergeBorder();
  455. if (pageMergeBorder) {
  456. rst[JV.PROP_PAGE_MERGE_BORDER] = pageMergeBorder;
  457. if (me.flowTab) {
  458. me.flowTab.eraseBlankCells(rptTpl, rst);
  459. }
  460. }
  461. }
  462. } else {
  463. console.log('no page result was found!');
  464. }
  465. if (rst[JV.PROP_SIGNATURE_CELLS] && rst[JV.PROP_SIGNATURE_CELLS].length > 0) {
  466. rst[JV.PROP_SIGNATURE_CELLS].sort(function(cell1, cell2) {
  467. return cell1[JV.PROP_FIELD_ORDER] - cell2[JV.PROP_FIELD_ORDER];
  468. });
  469. }
  470. return rst;
  471. };
  472. // JpcEx.rte.currentRptObj = JpcResult;
  473. return JpcResult;
  474. };
  475. module.exports = new JpcExSrv();