rpt_calculation_data_util.js 44 KB

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