rpt_calculation_data_util.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. 'use strict';
  2. /**
  3. * Created by Tony on 2019/6/18.
  4. * 计量报表数据提取class,是协助报表模板里指标字段自主提取数据的工具类
  5. */
  6. const JV = require('../rpt_component/jpc_value_define');
  7. const $JE = require('../rpt_component/jpc_rte');
  8. const fs = require('fs');
  9. const fsUtil = require('../../public/js/fsUtil');
  10. const stringUtil = require('../../public/js/stringUtil');
  11. const scMathUtil = require('../../public/js/scMathUtil');
  12. const data_analyze_util = require('../../lib/rpt_data_analysis').analysisObj;
  13. const _ = require('lodash');
  14. const treeUtil = require('../public/treeUtil');
  15. const RELATION_TABLES_KEYS = {
  16. project: { main_key: 'id' },
  17. tender: { main_key: 'id', foreign_key: { project: 'project_id' } },
  18. tender_info: { main_key: 'id', foreign_key: { project: 'pid', tender: 'tid' } },
  19. ledger: { main_key: 'id', isTree: true, tree_pid: 'ledger_pid', tree_id: 'ledger_id', foreign_key: { tender: 'tender_id' } },
  20. };
  21. class Rpt_Common {
  22. initialize(rpt_tpl, currentDataObj) {
  23. this.template = rpt_tpl;
  24. this.currentDataObj = currentDataObj;
  25. }
  26. Multiply(val1, val2, fixFormat) {
  27. const rst = [];
  28. let maxLen = val1.length;
  29. let minLen = val2.length;
  30. if (minLen > maxLen) {
  31. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  32. }
  33. for (let i = 0; i < maxLen; i++) {
  34. let value = ((i < val1.length) ? val1[i] : val1[minLen - 1]) * ((i < val2.length) ? val2[i] : val2[minLen - 1]);
  35. if (value === null || value === undefined) {
  36. value = '0';
  37. }
  38. if (fixFormat) value = value.toFixed(fixFormat);
  39. rst.push(value);
  40. }
  41. return rst;
  42. }
  43. Divide(val1, val2, fixFormat) {
  44. const rst = [];
  45. let maxLen = val1.length;
  46. let minLen = val2.length;
  47. if (minLen > maxLen) {
  48. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  49. }
  50. for (let i = 0; i < maxLen; i++) {
  51. let value = ((i < val1.length) ? val1[i] : val1[minLen - 1]) / ((i < val2.length) ? val2[i] : val2[minLen - 1]);
  52. if (fixFormat) value = value.toFixed(fixFormat);
  53. rst.push(value);
  54. }
  55. return rst;
  56. }
  57. Plus(val1, val2, fixFormat) {
  58. const rst = [];
  59. let maxLen = val1.length;
  60. let minLen = val2.length;
  61. if (minLen > maxLen) {
  62. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  63. }
  64. for (let i = 0; i < maxLen; i++) {
  65. let value = ((i < val1.length) ? val1[i] : val1[minLen - 1]) + ((i < val2.length) ? val2[i] : val2[minLen - 1]);
  66. if (fixFormat) value = value.toFixed(fixFormat);
  67. rst.push(value);
  68. }
  69. return rst;
  70. }
  71. MultiPlus(arrVal, fixFormat) {
  72. const rst = [];
  73. for (let i = 0; i < arrVal.length; i++) {
  74. const valItem = arrVal[i];
  75. if (i === 0) {
  76. for (const dtl of valItem) {
  77. let value = parseFloat(dtl);
  78. if (fixFormat) value = value.toFixed(fixFormat);
  79. rst.push(value);
  80. }
  81. } else {
  82. for (let j = 0; j < valItem.length; j++) {
  83. if (j < rst.length) {
  84. let value = rst[j] + valItem[j];
  85. if (fixFormat) value = value.toFixed(fixFormat);
  86. rst[j] = value;
  87. } else {
  88. let value = parseFloat(valItem[j]);
  89. if (fixFormat) value = value.toFixed(fixFormat);
  90. rst.push(value);
  91. }
  92. }
  93. }
  94. }
  95. return rst;
  96. }
  97. Minus(val1, val2, fixFormat) {
  98. const rst = [];
  99. let maxLen = val1.length;
  100. let minLen = val2.length;
  101. if (minLen > maxLen) {
  102. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  103. }
  104. for (let i = 0; i < maxLen; i++) {
  105. let value = ((i < val1.length) ? val1[i] : val1[minLen - 1]) - ((i < val2.length) ? val2[i] : val2[minLen - 1]);
  106. if (fixFormat) value = value.toFixed(fixFormat);
  107. rst.push(value);
  108. }
  109. return rst;
  110. }
  111. FormatString(arrVal, formatStr) {
  112. const rst = [];
  113. for (const val of arrVal) {
  114. rst.push(stringUtil.replaceAll(formatStr, '%S', val));
  115. }
  116. return rst;
  117. }
  118. }
  119. class Rpt_Data_Extractor {
  120. constructor() {
  121. this.COMMON = new Rpt_Common();
  122. }
  123. initialize(tpl) {
  124. this.rptTpl = tpl;
  125. }
  126. // 因为计量是采用传统的关系数据库(MySQL), 有一些表关系是需要先约定(如上下级关系,外键关系等)
  127. // 根据报表模板映射指标(非离散指标)的定义,罗列出所有需要用到的data对象key,作为数据请求的过滤依据
  128. getDataRequestFilter() {
  129. const rst = {};
  130. const memFieldKeys = {}; // 内存表优化用,需要获得相关内存表的指标请求,因为有些额外指标需要花资源去获得
  131. const tables = []; // 记录需要查询哪些表
  132. // const filters = []; // 记录过滤条件(预处理中的过滤),目前先不处理
  133. const tpl = this.rptTpl;
  134. const pri_func_split_mem_fieldKey = function(field) {
  135. // 计量需要获取所有内存表指标的key,优化用
  136. if (memFieldKeys[field.TableName] === undefined) {
  137. memFieldKeys[field.TableName] = [];
  138. }
  139. const strs = field[JV.PROP_FIELD_EXP_MAP].split("', '");
  140. if (strs.length === 2) {
  141. const codeKey = strs[1].slice(0, strs[1].indexOf("'"));
  142. if (field.TableName.indexOf('mem_') === 0 && memFieldKeys[field.TableName].indexOf(codeKey) < 0) {
  143. memFieldKeys[field.TableName].push(codeKey);
  144. }
  145. }
  146. };
  147. const pri_func_chk_filter = function(field) {
  148. // 计量的机制有所不同,数据分开保存在不同的表里,
  149. if (field.TableName && tables.indexOf(field.TableName) < 0) {
  150. tables.push(field.TableName);
  151. }
  152. pri_func_split_mem_fieldKey(field);
  153. };
  154. const pri_setup_filter = function(FIELD_LIST_KEY) {
  155. // console.log(tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]);
  156. if (tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  157. for (const field of tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  158. pri_func_chk_filter(field);
  159. }
  160. }
  161. };
  162. pri_setup_filter(JV.NODE_DISCRETE_FIELDS);
  163. pri_setup_filter(JV.NODE_MASTER_FIELDS);
  164. pri_setup_filter(JV.NODE_DETAIL_FIELDS);
  165. pri_setup_filter(JV.NODE_MASTER_FIELDS_EX);
  166. pri_setup_filter(JV.NODE_DETAIL_FIELDS_EX);
  167. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO] && tpl[JV.NODE_MAP_DATA_HANDLE_INFO].length > 0) {
  168. // 计量的预处理会有所变化,没有那么多方式,这里只记录过滤
  169. for (const preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  170. if (preHandle[JV.PROP_HANDLE_TYPE] === JV.PROP_HANDLE_TYPE_FILTER) {
  171. if (tables.indexOf(preHandle[JV.PROP_DATA_KEY]) < 0) {
  172. tables.push(preHandle[JV.PROP_DATA_KEY]);
  173. }
  174. // 目前还没想好有哪些过滤,骑驴找马吧
  175. }
  176. }
  177. }
  178. rst.tables = tables;
  179. rst.memFieldKeys = memFieldKeys;
  180. return rst;
  181. }
  182. // 装配数据(把收集到的数据,依据报表模板的指示,预处理(如:排序、过滤、合计)及装配到相关指标)
  183. assembleData(ctx, rawDataObj, baseDir, $CURRENT_RPT, customSelect) {
  184. const $PROJECT = { REPORT: {} };
  185. const tpl = this.rptTpl;
  186. this.COMMON.initialize(tpl, rawDataObj);
  187. $PROJECT.COMMON = this.COMMON;
  188. // console.log(rawDataObj);
  189. setupFunc($PROJECT.REPORT, rawDataObj, baseDir);
  190. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  191. for (const preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  192. const srcData = getModuleDataByKey(rawDataObj.prjData, preHandle[JV.PROP_DATA_KEY]);
  193. switch (preHandle[JV.PROP_HANDLE_TYPE]) {
  194. case JV.PROP_HANDLE_TYPE_SORT:
  195. // sortData(srcData, preHandle, rawDataObj.prjData);
  196. break;
  197. case JV.PROP_HANDLE_TYPE_FILTER:
  198. // filterData(srcData, preHandle, rawDataObj.prjData);
  199. break;
  200. case JV.PROP_HANDLE_TYPE_PRE_DEFINED:
  201. preDefineProcess(ctx, tpl, preHandle, rawDataObj, $CURRENT_RPT, customSelect);
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207. }
  208. const rptDataObj = {};
  209. rptDataObj[JV.DATA_DISCRETE_DATA] = [];
  210. rptDataObj[JV.DATA_MASTER_DATA] = [];
  211. rptDataObj[JV.DATA_DETAIL_DATA] = [];
  212. rptDataObj[JV.DATA_MASTER_DATA_EX] = [];
  213. rptDataObj[JV.DATA_DETAIL_DATA_EX] = [];
  214. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS], rptDataObj[JV.DATA_DISCRETE_DATA], $PROJECT);
  215. // console.log(JV.DATA_DISCRETE_DATA);
  216. // console.log(rptDataObj[JV.DATA_DISCRETE_DATA]);
  217. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], rptDataObj[JV.DATA_MASTER_DATA], $PROJECT);
  218. // console.log(JV.DATA_MASTER_DATA);
  219. // console.log(rptDataObj[JV.DATA_MASTER_DATA]);
  220. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS], rptDataObj[JV.DATA_DETAIL_DATA], $PROJECT);
  221. // console.log(JV.DATA_DETAIL_DATA);
  222. // console.log(rptDataObj[JV.DATA_DETAIL_DATA]);
  223. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS_EX], rptDataObj[JV.DATA_MASTER_DATA_EX], $PROJECT);
  224. // console.log(JV.DATA_MASTER_DATA_EX);
  225. // console.log(rptDataObj[JV.DATA_MASTER_DATA_EX]);
  226. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS_EX], rptDataObj[JV.DATA_DETAIL_DATA_EX], $PROJECT);
  227. // console.log(JV.DATA_DETAIL_DATA_EX);
  228. // console.log(rptDataObj[JV.DATA_DETAIL_DATA_EX]);
  229. // fsUtil.writeObjToFile(rptDataObj, 'D:/GitHome/temp/insertedOriginalData.jsp');
  230. // fsUtil.writeObjToFile(rawDataObj, 'D:/GitHome/temp/insertedRawDataData.jsp');
  231. // fsUtil.writeObjToFile($PROJECT, 'D:/GitHome/temp/$PROJECTData.jsp');
  232. // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], 'D:/GitHome/temp/masterFieldsAfterAssemble.jsp');
  233. // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS], 'D:/GitHome/temp/detailFieldsAfterAssemble.jsp');
  234. // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS], 'D:/GitHome/temp/discreteFieldsAfterAssemble.jsp');
  235. return rptDataObj;
  236. }
  237. }
  238. function getModuleDataByKey(prjData, key) {
  239. let rst = null;
  240. if (prjData) {
  241. for (const item of prjData) {
  242. if (item.moduleName === key) {
  243. rst = item;
  244. break;
  245. }
  246. }
  247. }
  248. return rst;
  249. }
  250. function filterData(sourceData, handleCfg, prjData) {
  251. let rstArr = [];
  252. const tempRstArr = [];
  253. for (const item of getActDataArr(sourceData)) {
  254. if (item._doc) {
  255. tempRstArr.push(item._doc);
  256. } else {
  257. tempRstArr.push(item);
  258. }
  259. }
  260. const private_chkVal = function(src, compVal, compStr) {
  261. let rst = true;
  262. switch (compStr) {
  263. case '==' :
  264. rst = (src == compVal);
  265. break;
  266. case '===' :
  267. rst = (src === compVal);
  268. break;
  269. case '>' :
  270. rst = (src > compVal);
  271. break;
  272. case '>=' :
  273. rst = (src >= compVal);
  274. break;
  275. case '<' :
  276. rst = (src < compVal);
  277. break;
  278. case '<=' :
  279. rst = (src <= compVal);
  280. break;
  281. case '!=' :
  282. rst = (src != compVal);
  283. break;
  284. case '!==' :
  285. rst = (src !== compVal);
  286. break;
  287. case 'in' :
  288. if (compVal instanceof Array) {
  289. rst = compVal.indexOf(src) >= 0;
  290. } else {
  291. // string,需要转类型
  292. const newInCv = JSON.parse(compVal);
  293. if (newInCv instanceof Array) {
  294. rst = newInCv.indexOf(src) >= 0;
  295. } else {
  296. rst = false;
  297. }
  298. }
  299. break;
  300. case 'not in':
  301. if (compVal instanceof Array) {
  302. rst = compVal.indexOf(src) < 0;
  303. } else {
  304. // string,需要转类型
  305. const newNotInCv = JSON.parse(compVal);
  306. if (newNotInCv instanceof Array) {
  307. rst = (newNotInCv.indexOf(src) < 0);
  308. } else {
  309. rst = true;
  310. }
  311. }
  312. break;
  313. default:
  314. rst = true;
  315. }
  316. return rst;
  317. };
  318. const private_chkArrVal = function(arr, key, compVal, compStr) {
  319. let rst = false;
  320. if (arr.length > 0) {
  321. for (const arrItem of arr) {
  322. if (arrItem[key] !== undefined) {
  323. // 可以为null值去判断
  324. rst = private_chkVal(arrItem[key], compVal, compStr);
  325. }
  326. if (rst) {
  327. break;
  328. }
  329. }
  330. } else {
  331. // 在某些判断条件下(含有'非'判断),如arr没有数组项,默认结果反而是true
  332. switch (compStr) {
  333. case '!=' :
  334. case '!==' :
  335. case 'not in':
  336. rst = true;
  337. break;
  338. default:
  339. break;
  340. }
  341. }
  342. return rst;
  343. };
  344. const private_filter_compare = function(item, filterCfg) {
  345. const compareObj = {};
  346. let compRst = true;
  347. let curComparePrjData = null;
  348. let startIdx = 0;
  349. const private_ref_join = function(refKey, targetDataKey, targetPropertyKey) {
  350. let rst = null;
  351. let objDataArr = null;
  352. curComparePrjData = getModuleDataByKey(prjData, targetDataKey);
  353. try {
  354. if (curComparePrjData !== null) {
  355. objDataArr = getActDataArr(curComparePrjData);
  356. for (const dtl of objDataArr) {
  357. if (item[refKey] === dtl[targetPropertyKey]) {
  358. rst = dtl;
  359. break;
  360. }
  361. }
  362. }
  363. } finally {
  364. curComparePrjData = null;
  365. }
  366. return rst;
  367. };
  368. for (const cfg of filterCfg[JV.PROP_FILTER_KEYS]) {
  369. if (cfg[JV.PROP_FILTER_COMPARE_VAL]) {
  370. // 比较key值
  371. const keys = cfg.key.split('.');
  372. if (keys.length > 1) {
  373. let lastObj = item;
  374. for (let i = 0; i < keys.length - 1; i++) {
  375. if (keys[i].indexOf('ref_join(') === 0) {
  376. const params = keys[i].slice(9, keys[i].length - 1).split(',');
  377. if (params.length === 3) {
  378. lastObj = private_ref_join(params[0], params[1], params[2]);
  379. }
  380. if (!(lastObj)) {
  381. compRst = false;
  382. break;
  383. }
  384. } else {
  385. lastObj = item[keys[i]];
  386. if (!(lastObj)) {
  387. compRst = false;
  388. break;
  389. }
  390. }
  391. }
  392. if (lastObj) {
  393. if (lastObj instanceof Array) {
  394. compRst = private_chkArrVal(lastObj, keys[keys.length - 1], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  395. } else {
  396. compRst = private_chkVal(lastObj[keys[keys.length - 1]], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  397. }
  398. }
  399. } else {
  400. compRst = private_chkVal(item[cfg.key], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  401. }
  402. } else if (cfg[JV.PROP_FILTER_COMPARE_OBJ] && cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]) {
  403. // 通过其他对象来过滤
  404. if (!curComparePrjData) {
  405. curComparePrjData = getModuleDataByKey(prjData, cfg[JV.PROP_FILTER_COMPARE_OBJ]);
  406. }
  407. if (cfg[JV.PROP_FILTER_CONDITION] === 'in' || cfg[JV.PROP_FILTER_CONDITION] === 'not in') {
  408. let compareArr = null;
  409. if (!compareObj.hasOwnProperty(cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString())) {
  410. compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()] = [];
  411. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  412. for (const data of getActDataArr(curComparePrjData)) {
  413. if (compareArr.indexOf(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]) < 0) {
  414. compareArr.push(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]);
  415. }
  416. }
  417. } else {
  418. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  419. }
  420. compRst = private_chkVal(item[cfg.key], compareArr, cfg[JV.PROP_FILTER_CONDITION]);
  421. } else {
  422. for (const data of getActDataArr(curComparePrjData)) {
  423. compRst = private_chkVal(item[cfg.key], data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]], cfg[JV.PROP_FILTER_CONDITION]);
  424. if (compRst) break;
  425. }
  426. }
  427. }
  428. startIdx++;
  429. if (!compRst) {
  430. break; // 有不符合条件的数据则退出(这里的判断条件是and关系)
  431. }
  432. }
  433. return compRst;
  434. };
  435. const private_sub_filter_compare = function(dtlItem, subFilters) {
  436. let cmpRst = false;
  437. for (const dtlCfg of subFilters) {
  438. cmpRst = private_filter_compare(dtlItem, dtlCfg);
  439. if (cmpRst) {
  440. if (dtlCfg[JV.PROP_OTHER_SUB_FILTER] && dtlCfg[JV.PROP_OTHER_SUB_FILTER].length > 0) {
  441. cmpRst = private_sub_filter_compare(dtlItem, dtlCfg[JV.PROP_OTHER_SUB_FILTER]);
  442. if (cmpRst) break;
  443. } else {
  444. break;
  445. }
  446. }
  447. }
  448. return cmpRst;
  449. };
  450. for (const item of tempRstArr) {
  451. if (private_filter_compare(item, handleCfg)) {
  452. rstArr.push(item);
  453. }
  454. }
  455. if (handleCfg[JV.PROP_OTHER_SUB_FILTER] && handleCfg[JV.PROP_OTHER_SUB_FILTER].length > 0) {
  456. const newRstArr = [];
  457. for (const dtlItem of rstArr) {
  458. const cmpRst = private_sub_filter_compare(dtlItem, handleCfg[JV.PROP_OTHER_SUB_FILTER]);
  459. if (cmpRst) {
  460. newRstArr.push(dtlItem);
  461. }
  462. }
  463. rstArr = newRstArr;
  464. }
  465. replaceActDataArr(sourceData, rstArr);
  466. // fsUtil.writeObjToFile(sourceData.data, 'D:/GitHome/ConstructionCost/tmp/filteredRst.jsp');
  467. }
  468. function getOrgFieldDefine(fieldId, tpl) {
  469. let rst = null;
  470. if (tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]) {
  471. for (const field of tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]) {
  472. if (field[JV.PROP_ID] === fieldId) {
  473. rst = field;
  474. break;
  475. }
  476. }
  477. }
  478. if (rst === null && tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  479. for (const field of tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  480. if (field[JV.PROP_ID] === fieldId) {
  481. rst = field;
  482. break;
  483. }
  484. }
  485. }
  486. if (rst === null && tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  487. for (const field of tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  488. if (field[JV.PROP_ID] === fieldId) {
  489. rst = field;
  490. break;
  491. }
  492. }
  493. }
  494. // 不会让用户选择独立离散指标的
  495. return rst;
  496. }
  497. function preDefineProcess(ctx, tpl, preDefineCfg, rawDataObj, $CURRENT_RPT, customSelect) {
  498. // 依据约定,需要提供如右所示格式的数据:[{field: 'b_code', table: 'mem_stage_bills'}, {field: 'id', table: 'mem_stage_bills'}]
  499. // 指标对象的mapExpression 格式类似于: "$PROJECT.REPORT.getProperty('mem_stage_im_zl', 'calc_memo')"
  500. const fields = [];
  501. // console.log($CURRENT_RPT);
  502. if (preDefineCfg.fields) {
  503. for (const field of preDefineCfg.fields) {
  504. const tplF = getOrgFieldDefine(field[JV.PROP_FIELD_ID], tpl);
  505. const mapStr = tplF[JV.PROP_FIELD_EXP_MAP].split(','); // 如上,用逗号分割
  506. let start = 0;
  507. let end = 0;
  508. let cnt = 0;
  509. for (let idx = 0; idx < mapStr[1].length; idx++) {
  510. if (mapStr[1][idx] === '\'') {
  511. cnt++;
  512. if (cnt === 1) {
  513. start = idx;
  514. } else {
  515. end = idx;
  516. break;
  517. }
  518. }
  519. }
  520. const codeKey = mapStr[1].slice(start + 1, end);
  521. // console.log('field codeKey: ' + codeKey);
  522. const rstF = { field: codeKey, table: tplF.TableName };
  523. fields.push(rstF);
  524. }
  525. }
  526. const analysisKey = preDefineCfg[JV.PROP_HANDLE_TYPE_PRE_DEFINED_KEY];
  527. if (analysisKey && analysisKey !== '') {
  528. if (data_analyze_util[analysisKey]) {
  529. try {
  530. // 在预定义方式中,小麦处理原始数据,不需要
  531. let preSetup = preDefineCfg[JV.PROP_HANDLE_SELF_SETUP];
  532. console.log(preSetup);
  533. try {
  534. if (preSetup) {
  535. preSetup = JSON.parse(preSetup);
  536. }
  537. } catch (ex) {
  538. console.log(analysisKey);
  539. ctx.helper.log(ex);
  540. }
  541. data_analyze_util[analysisKey].fun(ctx, rawDataObj, fields, preSetup, {
  542. tplDefine: tpl[JV.NODE_CUS_AUDIT_SELECT], cDefine: customSelect
  543. });
  544. } catch (err) {
  545. ctx.helper.log(err);
  546. throw '报表预处理数据出错';
  547. }
  548. } else {
  549. throw '报表预处理方法不存在';
  550. }
  551. }
  552. }
  553. function adjustData(sourceData, adjustCfg) {
  554. const rstArr = [];
  555. for (const item of getActDataArr(sourceData)) {
  556. if (item._doc) {
  557. rstArr.push(item._doc);
  558. } else {
  559. rstArr.push(item);
  560. }
  561. }
  562. for (const item of adjustCfg[JV.PROP_ADJUST_COLLECTION]) {
  563. for (const rec of rstArr) {
  564. if (item[JV.PROP_ADJUST_ACTION] === 'prefix') {
  565. rec[item.key] = item[JV.PROP_ADJUST_ACTION_VAL] + rec[item.key];
  566. } else if (item[JV.PROP_ADJUST_ACTION] === 'suffix') {
  567. rec[item.key] = rec[item.key] + item[JV.PROP_ADJUST_ACTION_VAL];
  568. }
  569. }
  570. }
  571. replaceActDataArr(sourceData, rstArr);
  572. }
  573. function sortData(sourceData, sortCfg, prjData) {
  574. let rst = getActDataArr(sourceData);
  575. const tempRstArr = [];
  576. const sortType = sortCfg[JV.PROP_SORT_TYPE];
  577. const srcData = getActDataArr(sourceData);
  578. for (const item of srcData) {
  579. if (item._doc) {
  580. tempRstArr.push(item._doc);
  581. } else {
  582. tempRstArr.push(item);
  583. }
  584. }
  585. function private_normal_sort(destArr, sortKeys) {
  586. destArr.sort(function(a, b) {
  587. let compRst = 0;
  588. for (const comp of sortKeys) {
  589. const reverse = (comp.order === 'ascend') ? 1 : (-1);
  590. //
  591. if (a[comp.key] > b[comp.key]) {
  592. compRst = reverse;
  593. break;
  594. } else if (a[comp.key] < b[comp.key]) {
  595. compRst = -reverse;
  596. break;
  597. }
  598. }
  599. return compRst;
  600. });
  601. }
  602. function private_parent_sort(parentArr, parentKeys, childArr, childKeys) {
  603. const tmpRst = {};
  604. const rst = [];
  605. for (const pItem of parentArr) {
  606. let pKey = 'key';
  607. for (const key of parentKeys) {
  608. pKey += '_' + pItem[key];
  609. }
  610. tmpRst[pKey] = [];
  611. }
  612. for (const cItem of childArr) {
  613. let cKey = 'key';
  614. for (const key of childKeys) {
  615. cKey += '_' + cItem[key];
  616. }
  617. if (tmpRst[cKey]) {
  618. tmpRst[cKey].push(cItem);
  619. } else {
  620. // unknown child value! should be filtered!
  621. }
  622. }
  623. // childArr.splice(0);
  624. for (const pItem of parentArr) {
  625. let pKey = 'key';
  626. for (const key of parentKeys) {
  627. pKey += '_' + pItem[key];
  628. }
  629. rst.push(tmpRst[pKey]);
  630. // for (let rItem of tmpRst[pKey]) {
  631. // childArr.push(rItem);
  632. // }
  633. }
  634. return rst;
  635. }
  636. switch (sortType) {
  637. case 'tree':
  638. const addLevel = true;
  639. rst = treeUtil.buildTreeNodeDirectly(tempRstArr, addLevel);
  640. let newTopArr = [];
  641. if ((sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES] && sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].length > 0) ||
  642. (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0)) {
  643. const local_check_bills = function(tItem) {
  644. let chkDtl = false;
  645. if (tItem.flags && tItem.flags.length > 0) {
  646. for (const flagItem of tItem.flags) {
  647. if (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  648. newTopArr.push(tItem);
  649. chkDtl = true;
  650. break;
  651. }
  652. }
  653. }
  654. if (!chkDtl && tItem.items && tItem.items.length > 0) {
  655. for (const dtlItem of tItem.items) {
  656. local_check_bills(dtlItem);
  657. }
  658. }
  659. };
  660. for (const topItem of rst) {
  661. let chkTop = false;
  662. if (topItem.flags && topItem.flags.length > 0) {
  663. for (const flagItem of topItem.flags) {
  664. if (sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  665. newTopArr.push(topItem);
  666. chkTop = true;
  667. break;
  668. }
  669. }
  670. }
  671. if (!chkTop && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0) {
  672. local_check_bills(topItem);
  673. }
  674. }
  675. } else {
  676. newTopArr = rst;
  677. }
  678. const destArr = [];
  679. // fsUtil.writeObjToFile(newTopArr, 'D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRstBefore.jsp');
  680. treeUtil.getFlatArray(newTopArr, destArr, true);
  681. // console.log(destArr);
  682. replaceActDataArr(sourceData, destArr);
  683. // fsUtil.writeObjToFile(sourceData.data, 'D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRst.jsp');
  684. break;
  685. case 'normal':
  686. private_normal_sort(tempRstArr, sortCfg[JV.PROP_SORT_KEYS]);
  687. replaceActDataArr(sourceData, tempRstArr);
  688. // fsUtil.writeObjToFile(sourceData.data, 'D:/GitHome/ConstructionCost/tmp/normalSortedRst.jsp');
  689. break;
  690. case 'accord_to_parent':
  691. const pcKey = sortCfg[JV.PROP_PARENT_CHILD_SORT_KEY];
  692. const parentSrcData = getModuleDataByKey(prjData, pcKey[JV.PROP_PARENT_DATA_KEY]);
  693. if (parentSrcData) {
  694. const tempParentArr = [];
  695. for (const item of getActDataArr(parentSrcData)) {
  696. if (item._doc) {
  697. tempParentArr.push(item._doc);
  698. } else {
  699. tempParentArr.push(item);
  700. }
  701. }
  702. const sortedRstArr = private_parent_sort(tempParentArr, pcKey[JV.PROP_PARENT_SORT_KEYS], tempRstArr, pcKey[JV.PROP_CHILD_SORT_KEYS]);
  703. if (sortCfg[JV.PROP_OTHER_SUB_SORT] && sortCfg[JV.PROP_OTHER_SUB_SORT].length > 0) {
  704. for (const sort of sortCfg[JV.PROP_OTHER_SUB_SORT]) {
  705. if (sort[JV.PROP_SORT_TYPE] === 'normal') {
  706. for (const subArr of sortedRstArr) {
  707. private_normal_sort(subArr, sort[JV.PROP_SORT_KEYS]);
  708. }
  709. } else if (sort[JV.PROP_SORT_TYPE] === 'self_define') {
  710. for (const subArr of sortedRstArr) {
  711. // console.log(subArr);
  712. const selfDefFunc = null;
  713. eval('selfDefFunc = ' + sort[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  714. subArr.sort(selfDefFunc);
  715. // console.log(subArr);
  716. }
  717. }
  718. }
  719. }
  720. tempRstArr.splice(0);
  721. for (const item of sortedRstArr) {
  722. for (const subItem of item) {
  723. tempRstArr.push(subItem);
  724. }
  725. }
  726. }
  727. replaceActDataArr(sourceData, tempRstArr);
  728. break;
  729. case 'self_define':
  730. if (sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]) {
  731. let selfDefFuncA = null;
  732. eval('selfDefFuncA = ' + sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  733. if (selfDefFuncA !== null) {
  734. tempRstArr.sort(selfDefFuncA);
  735. } else {
  736. console.log('sorting function is null!!!');
  737. }
  738. }
  739. replaceActDataArr(sourceData, tempRstArr);
  740. break;
  741. default:
  742. //
  743. }
  744. return rst;
  745. }
  746. function setupFunc(obj, ownRawObj, baseDir) {
  747. obj.myOwnRawDataObj = ownRawObj;
  748. obj.baseDir = baseDir;
  749. obj.getProperty = ext_getProperty;
  750. obj.getSplitProperty = ext_getSplitProperty;
  751. obj.getPicProperty = ext_getPicProperty;
  752. // obj.getPropertyByForeignId = ext_getPropertyByForeignId;
  753. obj.getPreferPrecisionProperty = ext_getPreferPrecisionProperty;
  754. obj.getArrayProperty = ext_getArrayValues;
  755. obj.getBlank = ext_getBlank;
  756. }
  757. function assembleFields(fieldList, rstDataArr, $PROJECT) {
  758. if (fieldList) {
  759. for (const field of fieldList) {
  760. shielded_exec_env($PROJECT, field, rstDataArr);
  761. if ('Precision' in field) {
  762. if (field.Precision.type === 'fixed') {
  763. // console.log('field.Precision.fixedMapExpression: ' + field.Precision.fixedMapExpression);
  764. const vrst = eval(field.Precision.fixedMapExpression);
  765. // console.log(vrst);
  766. if (vrst && vrst.length === 1) {
  767. field.fixedPrecisionNum = vrst[0];
  768. vrst.splice(0,1);
  769. }
  770. // console.log(field);
  771. } else if (field.Precision.type === 'flexible') {
  772. // console.log('field.Precision.flexibleMapExpression: ' + field.Precision.flexibleMapExpression);
  773. const vrst = eval(field.Precision.flexibleMapExpression);
  774. if (vrst && vrst.length === 1) {
  775. const tmpFlexObj = []; // 计量的动态精度对象与建筑/养护有所不同,需要重新生成
  776. for (const uKey in vrst[0]) {
  777. const tmpFObj = { unit: vrst[0][uKey].unit, decimal: vrst[0][uKey].value };
  778. if (uKey === 'other') {
  779. tmpFObj.unit = '其他未列单位';
  780. }
  781. tmpFlexObj.push(tmpFObj);
  782. }
  783. field.flexiblePrecisionRefObj = tmpFlexObj;
  784. vrst.splice(0, 1);
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. function shielded_exec_env($PROJECT, $ME, rptDataItemObj) {
  792. if ($ME[JV.PROP_FIELD_EXP_MAP]) {
  793. rptDataItemObj.push(eval($ME[JV.PROP_FIELD_EXP_MAP]));
  794. }
  795. }
  796. function getActPropertyVal(firstPropKey, secPropKey, orgObj) {
  797. let rst = null;
  798. if (orgObj[firstPropKey]) {
  799. rst = orgObj[firstPropKey];
  800. } else if (orgObj[secPropKey]) {
  801. rst = orgObj[secPropKey];
  802. }
  803. return rst;
  804. }
  805. function getDeepProperty(propKey, orgObj, destArr) {
  806. const keys = propKey.split('.');
  807. const dftPropKey = 'key';
  808. const dftPropVal = 'value';
  809. const secDftPropVal = 'items';
  810. let parent = orgObj;
  811. let lastVal = null;
  812. for (const key of keys) {
  813. if (parent instanceof Array) {
  814. for (const item of parent) {
  815. if (item[dftPropKey] === key) {
  816. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  817. break;
  818. }
  819. }
  820. } else {
  821. lastVal = null;
  822. if (parent[key] !== undefined) {
  823. lastVal = parent[key];
  824. } else if (parent[secDftPropVal]) {
  825. for (const item of parent[secDftPropVal]) {
  826. if (item[dftPropKey] === key) {
  827. // lastVal = item[dftPropVal];
  828. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  829. break;
  830. }
  831. }
  832. }
  833. }
  834. parent = lastVal;
  835. if (parent === null) break;
  836. }
  837. if (destArr && destArr instanceof Array) {
  838. destArr.push(lastVal);
  839. }
  840. }
  841. function ext_getPreferPrecisionProperty(dataKey, preferKey, preferPropKey, dftPropKey) {
  842. // 通过一个开关(preferKey)来控制精度,如为true,则选择preferPropKey,否则选择dftPropKey
  843. const rst = [];
  844. const parentObj = this;
  845. const dtObj = parentObj.myOwnRawDataObj[dataKey];
  846. if (preferKey && preferPropKey && dftPropKey && dtObj) {
  847. const da = getActDataArr(dtObj);
  848. if (da.length === 1) {
  849. const pKey = [];
  850. pri_push_property(preferKey, da[0], pKey);
  851. if (pKey.length > 0 && pKey[0]) {
  852. pri_push_property(preferPropKey, da[0], rst);
  853. } else {
  854. pri_push_property(dftPropKey, da[0], rst);
  855. }
  856. }
  857. }
  858. return rst;
  859. }
  860. function ext_getProperty(dataKey, propKey) {
  861. const rst = [];
  862. const parentObj = this;
  863. const dtObj = parentObj.myOwnRawDataObj[dataKey];
  864. // console.log('dataKey: ' + dataKey);
  865. // console.log(dtObj);
  866. if (propKey && dtObj) {
  867. // console.log('---- dtObj[' + dataKey + '] ----');
  868. // console.log(dtObj[dataKey]);
  869. const da = getActDataArr(dtObj);
  870. // console.log(da);
  871. for (const dItem of da) {
  872. // const doc = (dItem._doc === null || dItem._doc === undefined) ? dItem : dItem._doc;
  873. pri_push_property(propKey, dItem, rst);
  874. }
  875. }
  876. // console.log('---- result ----');
  877. // console.log(rst);
  878. return rst;
  879. }
  880. function ext_getSplitProperty(dataKey, propKey, splitChar, index, dftValue) {
  881. const rst = [];
  882. const parentObj = this;
  883. const dtObj = parentObj.myOwnRawDataObj[dataKey];
  884. if (propKey && dtObj) {
  885. const da = getActDataArr(dtObj);
  886. for (const dItem of da) {
  887. pri_push_property(propKey, dItem, rst);
  888. }
  889. }
  890. // const rst = ext_getProperty(dataKey, propKey);
  891. for (let idx = 0; idx < rst.length; idx++) {
  892. if (typeof rst[idx] === 'string') {
  893. const splitArr = rst[idx].split(splitChar);
  894. if (splitArr.length > index) {
  895. rst[idx] = splitArr[index];
  896. } else {
  897. rst[idx] = dftValue;
  898. }
  899. }
  900. }
  901. return rst;
  902. }
  903. async function ext_getPicProperty(dataKey, propKey, isPath) {
  904. const rst = [];
  905. const parentObj = this;
  906. const dtObj = parentObj.myOwnRawDataObj[dataKey];
  907. if (propKey && dtObj) {
  908. const da = getActDataArr(dtObj);
  909. for (const dItem of da) {
  910. pri_push_property(propKey, dItem, rst);
  911. }
  912. if (isPath) {
  913. for (let picIdx = 0; picIdx < rst.length; picIdx++) {
  914. if (rst[picIdx] !== undefined && rst[picIdx] !== null && rst[picIdx] !== '') {
  915. const filePath = parentObj.baseDir + '/app/' + rst[picIdx];
  916. try {
  917. fs.accessSync(filePath, fs.constants.R_OK);
  918. const bData = fs.readFileSync(filePath);
  919. const base64Str = bData.toString('base64');
  920. const datauri = 'data:image/png;base64,' + base64Str;
  921. rst[picIdx] = datauri;
  922. // const res = await isFileExisted(filePath);
  923. // if (res) {
  924. // const bData = fs.readFileSync(filePath);
  925. // const base64Str = bData.toString('base64');
  926. // const datauri = 'data:image/png;base64,' + base64Str;
  927. // rst[picIdx] = datauri;
  928. // } else {
  929. // rst[picIdx] = ''; // 不存在图片,则设置为空,后续的方法就不会当作图片来处理了
  930. // }
  931. } catch (err) {
  932. rst[picIdx] = ''; // 不存在图片,则设置为空,后续的方法就不会当作图片来处理了
  933. console.error(err);
  934. }
  935. }
  936. }
  937. } else {
  938. // 不是路径,那么必须是image data,不用处理,正常走即可
  939. }
  940. }
  941. return rst;
  942. }
  943. function ext_getArrayValues(dataKey, itemKey) {
  944. const rst = [];
  945. const parentObj = this;
  946. const dtObj = parentObj.myOwnRawDataObj[dataKey];
  947. // 计量需要重写
  948. const keysArr = itemKey.split('.');
  949. const da = getActDataArr(dtObj);
  950. // console.log(keysArr);
  951. for (const dataItem of da) {
  952. let itemArr = [];
  953. if (keysArr.length <= 2) {
  954. if (dataItem[keysArr[0]] instanceof Array) {
  955. if (keysArr.length === 2) {
  956. for (const item of dataItem[keysArr[0]]) {
  957. itemArr.push(item[keysArr[1]]);
  958. }
  959. } else {
  960. itemArr = itemArr.concat(dataItem[keysArr[0]]);
  961. }
  962. } else {
  963. if (keysArr.length === 2) {
  964. const subProperty = dataItem[keysArr[0]][keysArr[1]];
  965. if (subProperty instanceof Array) {
  966. itemArr = itemArr.concat(subProperty);
  967. } else {
  968. itemArr.push(subProperty);
  969. }
  970. } else {
  971. itemArr.push(dataItem[keysArr[0]]);
  972. }
  973. }
  974. }
  975. rst.push(itemArr);
  976. // console.log(itemArr);
  977. }
  978. return rst;
  979. }
  980. function ext_getBlank(dataKey, dftVal) {
  981. const rst = [];
  982. const parentObj = this;
  983. const dtObj = parentObj.myOwnRawDataObj[dataKey]; // dataKey是有必要的,必须知道是哪个Table
  984. // 计量需要重写
  985. if (dtObj) {
  986. const dtData = getActDataArr(dtObj);
  987. for (let i = 0; i < dtData.length; i++) {
  988. if (dftVal !== null && dftVal !== undefined) {
  989. rst.push(dftVal)
  990. } else rst.push('');
  991. }
  992. }
  993. return rst;
  994. }
  995. function ext_getPropertyByForeignId(foreignIdVal, adHocIdKey, propKey, dftValIfNotFound) {
  996. const rst = [];
  997. // 计量需要重写
  998. return rst;
  999. }
  1000. function getActDataArr(dtObj) {
  1001. let rst = [];
  1002. if (dtObj) {
  1003. if (dtObj instanceof Array) {
  1004. rst = rst.concat(dtObj);
  1005. } else {
  1006. rst.push(dtObj);
  1007. }
  1008. }
  1009. return rst;
  1010. }
  1011. function replaceActDataArr(dtObj, newArr) {
  1012. if (dtObj.moduleName === 'projectGLJ') {
  1013. delete dtObj.data.gljList;
  1014. dtObj.data.gljList = newArr;
  1015. } else {
  1016. delete dtObj.data;
  1017. dtObj.data = newArr;
  1018. }
  1019. }
  1020. function pri_push_property(propKey, doc, rst) {
  1021. if (propKey instanceof Array) {
  1022. // 备注:这里的key数组表示取value的优先级
  1023. for (let pi = 0; pi < propKey.length; pi++) {
  1024. if (doc.hasOwnProperty('property')) {
  1025. if (doc['property'].hasOwnProperty(propKey[pi])) {
  1026. rst.push(doc['property'][propKey[pi]]);
  1027. break;
  1028. }
  1029. } else if (doc.hasOwnProperty(propKey[pi])) {
  1030. rst.push(doc[propKey[pi]]);
  1031. break;
  1032. } else {
  1033. const lenBefore = rst.length;
  1034. getDeepProperty(propKey[pi], doc, rst);
  1035. if (rst.length === (lenBefore + 1)) {
  1036. if (rst[lenBefore] !== null && rst[lenBefore] !== undefined && rst[lenBefore] !== '') {
  1037. break;
  1038. } else {
  1039. rst.splice(-1, 1); // 删除末尾一条数据,给后面留空间
  1040. }
  1041. }
  1042. }
  1043. if (pi === propKey.length - 1) rst.push('');
  1044. }
  1045. } else {
  1046. if (doc.hasOwnProperty('property') && doc['property'].hasOwnProperty(propKey)) {
  1047. rst.push(doc['property'][propKey]);
  1048. } else if (doc.hasOwnProperty(propKey)) {
  1049. rst.push(doc[propKey]);
  1050. } else {
  1051. getDeepProperty(propKey, doc, rst);
  1052. }
  1053. }
  1054. }
  1055. // export default Rpt_Data_Extractor;
  1056. module.exports = Rpt_Data_Extractor;