rpt_construct_data_util.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /**
  2. * Created by Tony on 2017/7/14.
  3. * 报表数据提取class,是协助报表模板里指标字段自主提取数据的工具类
  4. */
  5. let JV = require('../rpt_component/jpc_value_define');
  6. let $JE = require('../rpt_component/jpc_rte');
  7. let consts = require('../../../modules/main/models/project_consts');
  8. let fsUtil = require("../../../public/fsUtil");
  9. let stringUtil = require("../../../public/stringUtil");
  10. let treeUtil = require('../../../public/treeUtil');
  11. let projectConst = consts.projectConst;
  12. let projectConstList = consts.projectConstList;
  13. const gljUtil = require('../../../public/gljUtil');
  14. const GLJ_TYPE = {
  15. Labour: 1,
  16. Material: 2,
  17. Machine: 3,
  18. Main_Material: 4,
  19. Equipment: 5
  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. let rst = [], maxLen = val1.length, minLen = val2.length;
  28. if (minLen > maxLen) {
  29. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  30. }
  31. for (let i = 0; i < maxLen; i++) {
  32. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) * ((i < val2.length)?val2[i]:val2[minLen - 1]);
  33. if (value === null || value === undefined) {
  34. value = '0';
  35. }
  36. if (fixFormat) value = value.toFixed(fixFormat);
  37. rst.push(value);
  38. }
  39. return rst;
  40. };
  41. Divide(val1, val2, fixFormat) {
  42. let rst = [], maxLen = val1.length, minLen = val2.length;
  43. if (minLen > maxLen) {
  44. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  45. }
  46. for (let i = 0; i < maxLen; i++) {
  47. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) / ((i < val2.length)?val2[i]:val2[minLen - 1]);
  48. if (fixFormat) value = value.toFixed(fixFormat);
  49. rst.push(value);
  50. }
  51. return rst;
  52. };
  53. Plus(val1, val2, fixFormat) {
  54. let rst = [], maxLen = val1.length, minLen = val2.length;
  55. if (minLen > maxLen) {
  56. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  57. }
  58. for (let i = 0; i < maxLen; i++) {
  59. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) + ((i < val2.length)?val2[i]:val2[minLen - 1]);
  60. if (fixFormat) value = value.toFixed(fixFormat);
  61. rst.push(value);
  62. }
  63. return rst;
  64. };
  65. MultiPlus(arrVal, fixFormat) {
  66. let rst = [];
  67. for (let i = 0; i < arrVal.length; i++) {
  68. let valItem = arrVal[i];
  69. if (i === 0) {
  70. for (let dtl of valItem) {
  71. let value = parseFloat(dtl);
  72. if (fixFormat) value = value.toFixed(fixFormat);
  73. rst.push(value);
  74. }
  75. } else {
  76. for (let j = 0; j < valItem.length; j++) {
  77. if (j < rst.length) {
  78. let value = rst[j] + valItem[j];
  79. if (fixFormat) value = value.toFixed(fixFormat);
  80. rst[j] = value;
  81. } else {
  82. let value = parseFloat(valItem[j]);
  83. if (fixFormat) value = value.toFixed(fixFormat);
  84. rst.push(value);
  85. }
  86. }
  87. }
  88. }
  89. return rst;
  90. };
  91. Minus(val1, val2, fixFormat) {
  92. let rst = [], maxLen = val1.length, minLen = val2.length;
  93. if (minLen > maxLen) {
  94. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  95. }
  96. for (let i = 0; i < maxLen; i++) {
  97. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) - ((i < val2.length)?val2[i]:val2[minLen - 1]);
  98. if (fixFormat) value = value.toFixed(fixFormat);
  99. rst.push(value);
  100. }
  101. return rst;
  102. };
  103. FormatString(arrVal, formatStr){
  104. let rst = [];
  105. for (let val of arrVal) {
  106. rst.push(stringUtil.replaceAll(formatStr, '%S', val));
  107. }
  108. return rst;
  109. };
  110. }
  111. class Rpt_Data_Extractor {
  112. constructor () {
  113. this.COMMON = new Rpt_Common();
  114. };
  115. initialize(tpl) {
  116. this.rptTpl = tpl;
  117. };
  118. //-- 根据报表模板映射指标(非离散指标)的定义,罗列出所有需要用到的data对象key,作为数据请求的过滤依据
  119. getDataRequestFilter() {
  120. let rst = [];
  121. let tpl = this.rptTpl;
  122. let pri_func_chk_filter = function (field) {
  123. for (let key of projectConstList) {
  124. if (rst.indexOf(key) < 0) {
  125. if (field[JV.PROP_FIELD_EXP_MAP]) {
  126. if (field[JV.PROP_FIELD_EXP_MAP].indexOf('.' + key + '.') >= 0) {
  127. rst.push(key);
  128. if (key === projectConst.RATION_GLJ && (rst.indexOf(projectConst.PROJECTGLJ) < 0)) {
  129. rst.push(projectConst.PROJECTGLJ);
  130. }
  131. if (key === projectConst.PROJECTGLJ && (rst.indexOf(projectConst.RATION_GLJ) < 0)) {
  132. rst.push(projectConst.RATION_GLJ);
  133. }
  134. }
  135. }
  136. }
  137. }
  138. };
  139. let pri_setup_filter = function (FIELD_LIST_KEY) {
  140. if (tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  141. for (let field of tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  142. pri_func_chk_filter(field);
  143. }
  144. }
  145. };
  146. pri_setup_filter(JV.NODE_DISCRETE_FIELDS);
  147. pri_setup_filter(JV.NODE_MASTER_FIELDS);
  148. pri_setup_filter(JV.NODE_DETAIL_FIELDS);
  149. pri_setup_filter(JV.NODE_MASTER_FIELDS_EX);
  150. pri_setup_filter(JV.NODE_DETAIL_FIELDS_EX);
  151. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO] && tpl[JV.NODE_MAP_DATA_HANDLE_INFO].length > 0) {
  152. for (let preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  153. if (rst.indexOf(preHandle[JV.PROP_DATA_KEY]) < 0) {
  154. rst.push(preHandle[JV.PROP_DATA_KEY]);
  155. }
  156. if (preHandle[JV.PROP_HANDLE_TYPE] === JV.PROP_HANDLE_TYPE_FILTER) {
  157. if (preHandle[JV.PROP_FILTER_KEYS]) {
  158. for (let filter of preHandle[JV.PROP_FILTER_KEYS]) {
  159. if (filter[JV.PROP_FILTER_COMPARE_OBJ] && rst.indexOf(filter[JV.PROP_FILTER_COMPARE_OBJ]) < 0) {
  160. rst.push(filter[JV.PROP_FILTER_COMPARE_OBJ]);
  161. }
  162. }
  163. }
  164. } else if (preHandle[JV.PROP_HANDLE_TYPE] === JV.PROP_HANDLE_TYPE_SUM) {
  165. if (preHandle[JV.PROP_SUM_GROUP_KEYS]) {
  166. for (let grpKey of preHandle[JV.PROP_SUM_GROUP_KEYS]) {
  167. if (grpKey.seeking_parent && rst.indexOf(grpKey.seeking_parent) < 0) {
  168. rst.push(grpKey.seeking_parent);
  169. }
  170. }
  171. }
  172. } else if (preHandle[JV.PROP_PARENT_CHILD_SORT_KEY] && preHandle[JV.PROP_PARENT_CHILD_SORT_KEY].length > 0) {
  173. for (let item of preHandle[JV.PROP_PARENT_CHILD_SORT_KEY]) {
  174. if (rst.indexOf(item[JV.PROP_PARENT_DATA_KEY]) < 0) {
  175. rst.push(item[JV.PROP_PARENT_DATA_KEY]);
  176. }
  177. }
  178. }
  179. }
  180. }
  181. if (rst.length === 0) {
  182. rst.push(projectConst.RATION_ASS);
  183. }
  184. return rst;
  185. };
  186. //--- 装配数据(把收集到的数据,依据报表模板的指示,预处理(如:排序、过滤、合计)及装配到相关指标) ---//
  187. assembleData(rawDataObj) {
  188. let $PROJECT = {"COMMON": null, "MAIN": {}, "DETAIL": {}};
  189. let tpl = this.rptTpl;
  190. this.COMMON.initialize(tpl, rawDataObj);
  191. $PROJECT.COMMON = this.COMMON;
  192. $PROJECT.MAIN["myOwnRawDataObj"] = rawDataObj.prj._doc;
  193. $PROJECT.MAIN.getProperty = ext_mainGetPropety;
  194. $PROJECT.MAIN.getFee = ext_mainGetFee;
  195. for (let item of rawDataObj.prjData) {
  196. setupFunc($PROJECT.DETAIL, item.moduleName, item);
  197. }
  198. let projectGLJDatas = getModuleDataByKey(rawDataObj.prjData, "projectGLJ");
  199. let rationGLJDatas = getModuleDataByKey(rawDataObj.prjData, "ration_glj");
  200. let rationDatas = getModuleDataByKey(rawDataObj.prjData, "ration");
  201. let billsDatas = getModuleDataByKey(rawDataObj.prjData, "bills");
  202. if (projectGLJDatas && rationGLJDatas, rationDatas, billsDatas) {
  203. gljUtil.calcProjectGLJQuantity(projectGLJDatas.data, rationGLJDatas.data, rationDatas.data, billsDatas.data, 4);
  204. }
  205. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  206. for (let preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  207. let srcData = getModuleDataByKey(rawDataObj.prjData, preHandle[JV.PROP_DATA_KEY]);
  208. switch(preHandle[JV.PROP_HANDLE_TYPE]) {
  209. case JV.PROP_HANDLE_TYPE_SORT:
  210. sortData(srcData, preHandle, rawDataObj.prjData);
  211. break;
  212. case JV.PROP_HANDLE_TYPE_FILTER:
  213. filterData(srcData, preHandle, rawDataObj.prjData);
  214. break;
  215. case JV.PROP_HANDLE_TYPE_SUM:
  216. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData10.jsp");
  217. summaryData(srcData, preHandle, rawDataObj.prjData);
  218. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData11.jsp");
  219. break;
  220. case JV.PROP_HANDLE_TYPE_ADD_DUMMY:
  221. addDummyData(srcData, preHandle);
  222. break;
  223. case JV.PROP_HANDLE_TYPE_ADJUST:
  224. adjustData(srcData, preHandle);
  225. break;
  226. case JV.PROP_HANDLE_TYPE_BILLS_DATA_MOVE:
  227. moveRationData(srcData, rawDataObj);
  228. break;
  229. default:
  230. break;
  231. }
  232. }
  233. }
  234. let rptDataObj = {};
  235. rptDataObj[JV.DATA_DISCRETE_DATA] = [];
  236. rptDataObj[JV.DATA_MASTER_DATA] = [];
  237. rptDataObj[JV.DATA_DETAIL_DATA] = [];
  238. rptDataObj[JV.DATA_MASTER_DATA_EX] = [];
  239. rptDataObj[JV.DATA_DETAIL_DATA_EX] = [];
  240. rptDataObj.DecimalObj = {};
  241. rptDataObj.DecimalObj.prjDecimal = $PROJECT.MAIN["myOwnRawDataObj"].decimal; //为函数 P_REF() 准备数据
  242. rptDataObj.DecimalObj.unitDecimal = getUnitDecimal($PROJECT.MAIN["myOwnRawDataObj"].billsQuantityDecimal); //为函数 U_REF() 准备数据
  243. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS], rptDataObj[JV.DATA_DISCRETE_DATA], $PROJECT);
  244. // console.log(JV.DATA_DISCRETE_DATA);
  245. // console.log(rptDataObj[JV.DATA_DISCRETE_DATA]);
  246. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], rptDataObj[JV.DATA_MASTER_DATA], $PROJECT);
  247. // console.log(JV.DATA_MASTER_DATA);
  248. // console.log(rptDataObj[JV.DATA_MASTER_DATA]);
  249. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS], rptDataObj[JV.DATA_DETAIL_DATA], $PROJECT);
  250. // console.log(JV.DATA_DETAIL_DATA);
  251. // console.log(rptDataObj[JV.DATA_DETAIL_DATA]);
  252. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS_EX], rptDataObj[JV.DATA_MASTER_DATA_EX], $PROJECT);
  253. // console.log(JV.DATA_MASTER_DATA_EX);
  254. // console.log(rptDataObj[JV.DATA_MASTER_DATA_EX]);
  255. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS_EX], rptDataObj[JV.DATA_DETAIL_DATA_EX], $PROJECT);
  256. // console.log(JV.DATA_DETAIL_DATA_EX);
  257. // console.log(rptDataObj[JV.DATA_DETAIL_DATA_EX]);
  258. // fsUtil.writeObjToFile(rptDataObj, "D:/GitHome/ConstructionCost/tmp/insertedOriginalData.jsp");
  259. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData.jsp");
  260. // fsUtil.writeObjToFile($PROJECT, "D:/GitHome/ConstructionCost/tmp/$PROJECTData.jsp");
  261. return rptDataObj;
  262. };
  263. }
  264. //小数位数依据单位来调整(如吨、公斤的精度要求就不同)
  265. function getUnitDecimal(unitDecimalArr) {
  266. let rst = {"default_decimal": 2};
  267. if (unitDecimalArr) {
  268. for (let item of unitDecimalArr) {
  269. if (item.unit === "其他未列单位") {
  270. rst["default_decimal"] = item.decimal;
  271. } else {
  272. rst['unit_decimal_' + item.unit] = item.decimal;
  273. }
  274. }
  275. }
  276. return rst;
  277. }
  278. function getModuleDataByKey(prjData, key) {
  279. let rst = null;
  280. for (let item of prjData) {
  281. if (item.moduleName === key) {
  282. rst = item;
  283. break;
  284. }
  285. }
  286. return rst;
  287. }
  288. function summaryData(sourceData, handleCfg, prjData){
  289. let rstArr = [], tempRstArr = [];
  290. let curParentPrjData = {};
  291. for (let item of sourceData.data) {
  292. if (item._doc) {
  293. tempRstArr.push(item._doc);
  294. } else {
  295. tempRstArr.push(item);
  296. }
  297. }
  298. let private_cal_before_sum = function () {
  299. for (let calcAheadObj of handleCfg[JV.PROP_SUM_CALC_AHEAD]) {
  300. if (!curParentPrjData[calcAheadObj["seeking_parent"]]) curParentPrjData[calcAheadObj["seeking_parent"]] = getModuleDataByKey(prjData, calcAheadObj["seeking_parent"]);
  301. for (let idxP = 0; idxP < curParentPrjData[calcAheadObj["seeking_parent"]].data.length; idxP++) {
  302. let pDataItem = curParentPrjData[calcAheadObj["seeking_parent"]].data[idxP];
  303. let data = (pDataItem._doc)?pDataItem._doc:pDataItem;
  304. for (let idx = 0; idx < tempRstArr.length; idx++) {
  305. let dtlItem = tempRstArr[idx];
  306. if (dtlItem[calcAheadObj["seeking_key"]] === data[calcAheadObj["parent_key"]]) {
  307. for (let sumKey of handleCfg[JV.PROP_SUM_SUM_KEYS]) {
  308. switch (calcAheadObj[JV.PROP_SUM_CACL_TYPE]) {
  309. case "+":
  310. dtlItem[sumKey] = parseFloat(dtlItem[sumKey]) + parseFloat(data[calcAheadObj["calc_property"]]);
  311. break;
  312. case "-":
  313. dtlItem[sumKey] = parseFloat(dtlItem[sumKey]) - parseFloat(data[calcAheadObj["calc_property"]]);
  314. break;
  315. case "*":
  316. dtlItem[sumKey] = dtlItem[sumKey] * parseFloat(data[calcAheadObj["calc_property"]]).toFixed(4);
  317. break;
  318. case "/":
  319. dtlItem[sumKey] = dtlItem[sumKey] / parseFloat(data[calcAheadObj["calc_property"]]).toFixed(4);
  320. break;
  321. default:
  322. break;
  323. }
  324. }
  325. // break;
  326. }
  327. }
  328. }
  329. }
  330. };
  331. let private_get_grp_key = function (item) {
  332. let keys = [];
  333. for (let cfg of handleCfg[JV.PROP_SUM_GROUP_KEYS]) {
  334. if (typeof cfg === "string") {
  335. keys.push(item[cfg]);
  336. } else {
  337. if (!curParentPrjData[cfg["seeking_parent"]]) curParentPrjData[cfg["seeking_parent"]] = getModuleDataByKey(prjData, cfg["seeking_parent"]);
  338. for (let pDataItem of curParentPrjData[cfg["seeking_parent"]].data) {
  339. let data = (pDataItem._doc)?pDataItem._doc:pDataItem;
  340. if (item[cfg["seeking_key"]] === data[cfg["parent_key"]]) {
  341. keys.push(data[cfg["parent_grp_key"]]);
  342. break;
  343. }
  344. }
  345. }
  346. }
  347. return ( "grp_key_" + keys.join('_'));
  348. };
  349. let sumObj = {};
  350. if (handleCfg[JV.PROP_SUM_CALC_AHEAD] && handleCfg[JV.PROP_SUM_CALC_AHEAD].length > 0) {
  351. private_cal_before_sum();
  352. }
  353. for (let dtl of tempRstArr) {
  354. let grpKey = private_get_grp_key(dtl);
  355. if (sumObj[grpKey] === null || sumObj[grpKey] === undefined) {
  356. sumObj[grpKey] = dtl;
  357. rstArr.push(dtl);
  358. } else {
  359. for (let sumKey of handleCfg[JV.PROP_SUM_SUM_KEYS]) {
  360. if (dtl[sumKey]) {
  361. // sumObj[grpKey][sumKey] += dtl[sumKey];
  362. sumObj[grpKey][sumKey] = parseFloat(sumObj[grpKey][sumKey]) + parseFloat(dtl[sumKey]);
  363. }
  364. }
  365. }
  366. }
  367. delete sourceData.data;
  368. sourceData.data = rstArr;
  369. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/sumRst.jsp");
  370. }
  371. function filterData(sourceData, handleCfg, prjData) {
  372. let rstArr = [], tempRstArr = [];
  373. for (let item of sourceData.data) {
  374. if (item._doc) {
  375. tempRstArr.push(item._doc);
  376. } else {
  377. tempRstArr.push(item);
  378. }
  379. }
  380. let private_chkVal = function (src, compVal, compStr) {
  381. let rst = true;
  382. switch (compStr) {
  383. case "==" :
  384. rst = (src == compVal);
  385. break;
  386. case "===" :
  387. rst = (src === compVal);
  388. break;
  389. case ">" :
  390. rst = (src > compVal);
  391. break;
  392. case ">=" :
  393. rst = (src >= compVal);
  394. break;
  395. case "<" :
  396. rst = (src < compVal);
  397. break;
  398. case "<=" :
  399. rst = (src <= compVal);
  400. break;
  401. case "!=" :
  402. rst = (src != compVal);
  403. break;
  404. case "!==" :
  405. rst = (src !== compVal);
  406. break;
  407. case "in" :
  408. if (compVal instanceof Array) {
  409. rst = compVal.indexOf(src) >= 0;
  410. } else {
  411. //string,需要转类型
  412. let newCv = JSON.parse(compVal);
  413. if (newCv instanceof Array) {
  414. rst = newCv.indexOf(src) >= 0;
  415. } else {
  416. rst = false;
  417. }
  418. }
  419. break;
  420. case "not in":
  421. if (compVal instanceof Array) {
  422. rst = compVal.indexOf(src) < 0;
  423. } else {
  424. //string,需要转类型
  425. let newCv = JSON.parse(compVal);
  426. if (newCv instanceof Array) {
  427. rst = newCv.indexOf(src) < 0;
  428. } else {
  429. rst = true;
  430. }
  431. }
  432. break;
  433. default:
  434. rst = true;
  435. }
  436. return rst;
  437. };
  438. let private_chkArrVal = function(arr, key, compVal, compStr){
  439. let rst = false;
  440. for (let arrItem of arr) {
  441. if (arrItem[key]) {
  442. rst = private_chkVal(arrItem[key], compVal, compStr);
  443. }
  444. if (rst) {
  445. break;
  446. }
  447. }
  448. return rst;
  449. };
  450. let private_filter_compare = function (item, filterCfg) {
  451. let compareObj = {};
  452. let compRst = true;
  453. let curComparePrjData = null;
  454. let startIdx = 0;
  455. let private_ref_join = function(refKey, targetDataKey, targetPropertyKey) {
  456. let rst = null, objDataArr = null;
  457. curComparePrjData = getModuleDataByKey(prjData, targetDataKey);
  458. try {
  459. if (curComparePrjData !== null) {
  460. if (targetDataKey === "projectGLJ") {
  461. objDataArr = curComparePrjData.data.gljList;
  462. } else {
  463. objDataArr = curComparePrjData.data;
  464. }
  465. for (let dtl of objDataArr) {
  466. if (item[refKey] === dtl[targetPropertyKey]) {
  467. rst = dtl;
  468. break;
  469. }
  470. }
  471. }
  472. } finally {
  473. curComparePrjData = null;
  474. }
  475. return rst;
  476. };
  477. for (let cfg of filterCfg[JV.PROP_FILTER_KEYS]) {
  478. if (cfg[JV.PROP_FILTER_COMPARE_VAL]) {
  479. //比较key值
  480. let keys = cfg.key.split(".");
  481. if (keys.length > 1) {
  482. let lastObj = item;
  483. for (let i = 0; i < keys.length - 1; i++) {
  484. if (keys[i].indexOf("ref_join(") === 0) {
  485. let params = keys[i].slice(9, keys[i].length - 1).split(",");
  486. if (params.length === 3) {
  487. lastObj = private_ref_join(params[0], params[1], params[2]);
  488. }
  489. if (!(lastObj)) {
  490. compRst = false;
  491. break;
  492. }
  493. } else {
  494. lastObj = item[keys[i]];
  495. if (!(lastObj)) {
  496. compRst = false;
  497. break;
  498. }
  499. }
  500. }
  501. if (lastObj) {
  502. if (lastObj instanceof Array) {
  503. compRst = private_chkArrVal(lastObj, keys[keys.length - 1], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  504. } else {
  505. compRst = private_chkVal(lastObj[keys[keys.length - 1]], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  506. }
  507. }
  508. } else {
  509. compRst = private_chkVal(item[cfg.key], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  510. }
  511. } else if (cfg[JV.PROP_FILTER_COMPARE_OBJ] && cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]){
  512. //通过其他对象来过滤
  513. if (!curComparePrjData) {
  514. curComparePrjData = getModuleDataByKey(prjData, cfg[JV.PROP_FILTER_COMPARE_OBJ]);
  515. }
  516. if (cfg[JV.PROP_FILTER_CONDITION] === "in" || cfg[JV.PROP_FILTER_CONDITION] === "not in") {
  517. let compareArr = null;
  518. if (!compareObj.hasOwnProperty(cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString())) {
  519. compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()] = [];
  520. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  521. for (let data of curComparePrjData.data) {
  522. if (compareArr.indexOf(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]) < 0) {
  523. compareArr.push(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]);
  524. }
  525. }
  526. } else {
  527. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  528. }
  529. compRst = private_chkVal(item[cfg.key], compareArr, cfg[JV.PROP_FILTER_CONDITION]);
  530. } else {
  531. for (let data of curComparePrjData.data) {
  532. compRst = private_chkVal(item[cfg.key], data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]], cfg[JV.PROP_FILTER_CONDITION]);
  533. if (compRst) break;
  534. }
  535. }
  536. }
  537. startIdx++;
  538. }
  539. return compRst;
  540. };
  541. for (let item of tempRstArr) {
  542. if (private_filter_compare(item, handleCfg)) {
  543. rstArr.push(item);
  544. }
  545. }
  546. if (handleCfg[JV.PROP_OTHER_SUB_FILTER] && handleCfg[JV.PROP_OTHER_SUB_FILTER].length > 0) {
  547. let newRstArr = [];
  548. for (let dtlItem of rstArr) {
  549. let cmpRst = false;
  550. for (let dtlCfg of handleCfg[JV.PROP_OTHER_SUB_FILTER]) {
  551. cmpRst = private_filter_compare(dtlItem, dtlCfg);
  552. if (cmpRst) {
  553. newRstArr.push(dtlItem);
  554. break;
  555. }
  556. }
  557. }
  558. rstArr = newRstArr;
  559. }
  560. delete sourceData.data;
  561. sourceData.data = rstArr;
  562. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/filteredRst.js");
  563. }
  564. function adjustData(sourceData, adjustCfg) {
  565. let rstArr = [];
  566. for (let item of sourceData.data) {
  567. if (item._doc) {
  568. rstArr.push(item._doc);
  569. } else {
  570. rstArr.push(item);
  571. }
  572. }
  573. for (let item of adjustCfg[JV.PROP_ADJUST_COLLECTION]) {
  574. for (let rec of rstArr) {
  575. if (item[JV.PROP_ADJUST_ACTION] === "prefix") {
  576. rec[item.key] = item[JV.PROP_ADJUST_ACTION_VAL] + rec[item.key];
  577. } else if (item[JV.PROP_ADJUST_ACTION] === "suffix") {
  578. rec[item.key] = rec[item.key] + item[JV.PROP_ADJUST_ACTION_VAL];
  579. }
  580. }
  581. }
  582. delete sourceData.data;
  583. sourceData.data = rstArr;
  584. }
  585. function moveRationData(rationData, rawDataObj) {
  586. if (rawDataObj) {
  587. // let rationData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION);
  588. let rationGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION_GLJ);
  589. let prjGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.PROJECTGLJ);
  590. let dummyCode = " ", dummyPRJID = 10101010;
  591. for (let rationItem of rationData.data) {
  592. if (rationItem.type === 2 || rationItem.type === 3) {
  593. //2: 量材(人工/材料/机械/主材/设备) 3:材料(材料/主材/设备)
  594. let copyItem = {};
  595. copyItem.ID = rationItem.ID;
  596. copyItem.projectID = rationItem.projectID;
  597. copyItem.GLJID = rationItem.GLJID;
  598. copyItem.rationID = rationItem.ID;
  599. copyItem.rationItemQuantity = 1;
  600. copyItem.quantity = 1;
  601. // copyItem.specialType_quantity = rationItem.quantity;
  602. copyItem.name = rationItem.name;
  603. if (rationItem.code) {
  604. copyItem.code = rationItem.ID + "_" + rationItem.code;
  605. } else {
  606. copyItem.code = dummyCode;
  607. dummyCode = dummyCode + " ";
  608. }
  609. copyItem.original_code = rationItem.original_code;
  610. copyItem.unit = rationItem.unit;
  611. copyItem.specs = rationItem.specs;
  612. copyItem.shortName = rationItem.shortName;
  613. copyItem.billsItemID = rationItem.billsItemID;
  614. copyItem.type = rationItem.subType;
  615. if (rationItem.projectGLJID) {
  616. copyItem.projectGLJID = rationItem.projectGLJID;
  617. } else {
  618. //add dummy project GLJ
  619. let dummyPrjItem = {};
  620. copyItem.projectGLJID = dummyPRJID;
  621. dummyPrjItem.id = dummyPRJID;
  622. dummyPRJID++;
  623. dummyPrjItem.unit_price = {};
  624. dummyPrjItem.unit_price.base_price = 0;
  625. dummyPrjItem.unit_price.market_price = (rationItem["marketUnitFee"])?rationItem["marketUnitFee"]:0;
  626. dummyPrjItem.quantity = 0;
  627. dummyPrjItem.is_evaluate = 0;
  628. prjGljData.data.gljList.push(dummyPrjItem);
  629. }
  630. rationGljData.data.push(copyItem);
  631. }
  632. }
  633. // fsUtil.writeObjToFile(rationGljData.data, "D:/GitHome/ConstructionCost/tmp/afterMoveGLJ.jsp");
  634. }
  635. }
  636. function getDupGrpKeyVals(sourceData, segKeys) {
  637. let rst = [];
  638. function pushKeyVal(item) {
  639. let tr = {};
  640. for (let i = 0; i < segKeys.length; i++) {
  641. tr[segKeys[i]] = item[segKeys[i]];
  642. }
  643. rst.push(tr);
  644. }
  645. for (let idx = 0; idx < sourceData.length; idx++) {
  646. let itemRec = sourceData[idx];
  647. if (idx === 0) {
  648. pushKeyVal(itemRec);
  649. continue;
  650. }
  651. let hasDiff = false;
  652. for (let i = 0; i < segKeys.length; i++) {
  653. if (itemRec[segKeys[i]] !== sourceData[idx - 1][segKeys[i]]) {
  654. hasDiff = true;
  655. break;
  656. }
  657. }
  658. if (hasDiff) {
  659. pushKeyVal(itemRec);
  660. }
  661. }
  662. return rst;
  663. }
  664. function addDummyData(sourceData, addCfg) {
  665. let rstArr = [], tempRstArr = [];
  666. for (let item of sourceData.data) {
  667. if (item._doc) {
  668. tempRstArr.push(item._doc);
  669. } else {
  670. tempRstArr.push(item);
  671. }
  672. }
  673. for (let item of addCfg[JV.PROP_DUMMY_COLLECTION]) {
  674. let newRecStr = JSON.stringify(item[JV.PROP_DUMMY_VAL]), cacheGrpKeyRecs = null;
  675. if (item[JV.PROP_FREQUENCY] === "OncePerGrp") {
  676. if (!cacheGrpKeyRecs) {
  677. cacheGrpKeyRecs = {};
  678. }
  679. let cacheKey = "";
  680. for (let key of item[JV.PROP_GRP_KEYS]) {
  681. cacheKey += "_" + key;
  682. }
  683. if (!cacheGrpKeyRecs[cacheKey]) {
  684. cacheGrpKeyRecs[cacheKey] = getDupGrpKeyVals(tempRstArr, item[JV.PROP_GRP_KEYS]);
  685. }
  686. for (let kv of cacheGrpKeyRecs[cacheKey]) {
  687. let rec = JSON.parse(newRecStr);
  688. for (let key of item[JV.PROP_GRP_KEYS]) {
  689. rec[key] = kv[key];
  690. }
  691. rstArr.push(rec);
  692. }
  693. } else if (item[JV.PROP_FREQUENCY] === "Once") {
  694. rstArr.push(JSON.parse(newRecStr));
  695. }
  696. }
  697. rstArr = rstArr.concat(tempRstArr);
  698. delete sourceData.data;
  699. sourceData.data = rstArr;
  700. }
  701. function getGLJBizType(orgType, orgCode, orgName) {
  702. let rst = orgType;
  703. if (orgName.indexOf("其他材料费") >= 0) {
  704. rst = 299;
  705. } else if (orgType === GLJ_TYPE.Labour) {
  706. rst = 11;
  707. if (orgCode === "000000") rst = 10;
  708. } else if (orgType === GLJ_TYPE.Main_Material || orgType === GLJ_TYPE.Equipment) {
  709. //未计价材料(主材 + 设备)
  710. rst = 30 + orgType;
  711. } else if (orgType === GLJ_TYPE.Material || (orgType >= 200 && orgType < 300)) {
  712. //材料
  713. if (orgCode === "000000") {
  714. rst = 20; //2.材料
  715. } else if (orgCode === "000000_1") {
  716. rst = 30; //(1) 未计价材料
  717. } else if (orgCode === "000000_2") {
  718. rst = 40; //(2) 辅助材料
  719. } else if (orgCode === "000000_3") {
  720. rst = 50; //(3) 其他材料费
  721. } else {
  722. rst = 45; //到这里就只有辅助材料没有预处理了
  723. }
  724. } else if (orgType === GLJ_TYPE.Machine || (orgType >= 300 && orgType < 400)) {
  725. //机械
  726. if (orgCode === "000000") {
  727. rst = 300; //3.机械
  728. } else if (orgType === GLJ_TYPE.Machine) {
  729. rst = 300.5;
  730. } else {
  731. rst = orgType;
  732. }
  733. }
  734. return rst;
  735. }
  736. function sortData(sourceData, sortCfg, prjData) {
  737. let rst = sourceData.data, tempRstArr = [];
  738. let sortType = sortCfg[JV.PROP_SORT_TYPE];
  739. for (let item of sourceData.data) {
  740. if (item._doc) {
  741. tempRstArr.push(item._doc);
  742. } else {
  743. tempRstArr.push(item);
  744. }
  745. }
  746. function private_normal_sort(destArr, sortKeys) {
  747. destArr.sort(function(a, b){
  748. let compRst = 0;
  749. for (let comp of sortKeys) {
  750. let reverse = (comp.order === 'ascend')?1:(-1);
  751. //
  752. if (a[comp.key] > b[comp.key]) {
  753. compRst = reverse;
  754. break;
  755. } else if (a[comp.key] < b[comp.key]) {
  756. compRst = -reverse;
  757. break;
  758. }
  759. }
  760. return compRst;
  761. });
  762. }
  763. function private_parent_sort(parentArr, parentKeys, childArr, childKeys) {
  764. let tmpRst = {}, rst = [];
  765. for (let pItem of parentArr) {
  766. let pKey = "key";
  767. for (let key of parentKeys) {
  768. pKey += "_" + pItem[key];
  769. }
  770. tmpRst[pKey] = [];
  771. }
  772. for (let cItem of childArr) {
  773. let cKey = "key";
  774. for (let key of childKeys) {
  775. cKey += "_" + cItem[key];
  776. }
  777. if (tmpRst[cKey]) {
  778. tmpRst[cKey].push(cItem);
  779. } else {
  780. //unknown child value! should be filtered!
  781. }
  782. }
  783. // childArr.splice(0);
  784. for (let pItem of parentArr) {
  785. let pKey = "key";
  786. for (let key of parentKeys) {
  787. pKey += "_" + pItem[key];
  788. }
  789. rst.push(tmpRst[pKey]);
  790. // for (let rItem of tmpRst[pKey]) {
  791. // childArr.push(rItem);
  792. // }
  793. }
  794. return rst;
  795. }
  796. switch (sortType) {
  797. case "tree":
  798. let addLevel = true;
  799. rst = treeUtil.buildTreeNodeDirectly(tempRstArr, addLevel);
  800. let newTopArr = [];
  801. if ((sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES] && sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].length > 0) ||
  802. (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0)) {
  803. let local_check_bills = function(tItem) {
  804. let chkDtl = false;
  805. if (tItem.flags && tItem.flags.length > 0) {
  806. for (let flagItem of tItem.flags) {
  807. if (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  808. newTopArr.push(tItem);
  809. chkDtl = true;
  810. break;
  811. }
  812. }
  813. }
  814. if (!chkDtl && tItem.items && tItem.items.length > 0) {
  815. for (let dtlItem of tItem.items) {
  816. local_check_bills(dtlItem);
  817. }
  818. }
  819. };
  820. for (let topItem of rst) {
  821. let chkTop = false;
  822. if (topItem.flags && topItem.flags.length > 0) {
  823. for (let flagItem of topItem.flags) {
  824. if (sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  825. newTopArr.push(topItem);
  826. chkTop = true;
  827. break;
  828. }
  829. }
  830. }
  831. if (!chkTop && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0) {
  832. local_check_bills(topItem);
  833. }
  834. }
  835. } else {
  836. newTopArr = rst;
  837. }
  838. let destArr = [];
  839. treeUtil.getFlatArray(newTopArr, destArr);
  840. delete sourceData.data;
  841. sourceData.data = destArr;
  842. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRst.jsp");
  843. break;
  844. case "normal":
  845. private_normal_sort(tempRstArr, sortCfg[JV.PROP_SORT_KEYS]);
  846. delete sourceData.data;
  847. sourceData.data = tempRstArr;
  848. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/normalSortedRst.jsp");
  849. break;
  850. case "accord_to_parent":
  851. let pcKey = sortCfg[JV.PROP_PARENT_CHILD_SORT_KEY];
  852. let parentSrcData = getModuleDataByKey(prjData, pcKey[JV.PROP_PARENT_DATA_KEY]);
  853. if (parentSrcData) {
  854. let tempParentArr = [];
  855. for (let item of parentSrcData.data) {
  856. if (item._doc) {
  857. tempParentArr.push(item._doc);
  858. } else {
  859. tempParentArr.push(item);
  860. }
  861. }
  862. let sortedRstArr = private_parent_sort(tempParentArr, pcKey[JV.PROP_PARENT_SORT_KEYS], tempRstArr, pcKey[JV.PROP_CHILD_SORT_KEYS]);
  863. if (sortCfg[JV.PROP_OTHER_SUB_SORT] && sortCfg[JV.PROP_OTHER_SUB_SORT].length > 0) {
  864. for (let sort of sortCfg[JV.PROP_OTHER_SUB_SORT]) {
  865. if (sort[JV.PROP_SORT_TYPE] === 'normal') {
  866. for (let subArr of sortedRstArr) {
  867. private_normal_sort(subArr, sort[JV.PROP_SORT_KEYS]);
  868. }
  869. } else if (sort[JV.PROP_SORT_TYPE] === 'self_define') {
  870. for (let subArr of sortedRstArr) {
  871. // console.log(subArr);
  872. let selfDefFunc = null;
  873. eval('selfDefFunc = ' + sort[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  874. subArr.sort(selfDefFunc);
  875. // console.log(subArr);
  876. }
  877. }
  878. }
  879. }
  880. tempRstArr.splice(0);
  881. for (let item of sortedRstArr) {
  882. for (let subItem of item) {
  883. tempRstArr.push(subItem);
  884. }
  885. }
  886. }
  887. delete sourceData.data;
  888. sourceData.data = tempRstArr;
  889. break;
  890. case "self_define":
  891. if (sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]) {
  892. let selfDefFunc = null;
  893. eval('selfDefFunc = ' + sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  894. tempRstArr.sort(selfDefFunc);
  895. }
  896. delete sourceData.data;
  897. sourceData.data = tempRstArr;
  898. break;
  899. default:
  900. //
  901. }
  902. return rst;
  903. }
  904. function setupFunc(obj, prop, ownRawObj) {
  905. obj[prop] = {};
  906. obj[prop]["myOwnRawDataObj"] = ownRawObj;
  907. obj[prop]["myOwnOrgRawDataObj"] = ownRawObj.data;
  908. obj[prop].getProperty = ext_getPropety;
  909. obj[prop].getPropertyByRefId = ext_getPropertyByRefId;
  910. obj[prop].getFee = ext_getFee;
  911. obj[prop].getPropertyByForeignId = ext_getPropertyByForeignId;
  912. obj[prop].getArrayValues = ext_getArrayValues;
  913. obj[prop].getArrayItemByKey = ext_getArrayItemByKey;
  914. obj[prop].getPropertyByFlag = ext_getPropertyByFlag;
  915. obj[prop].getBlank = ext_getBlank;
  916. if (prop === projectConst.CALC_PROGRAM) obj[prop].getCalcProperty = ext_getCalcProperty;
  917. if (prop === projectConst.FEERATE) obj[prop].getFeeRate = ext_getFeeRate;
  918. }
  919. function assembleFields(fieldList, rstDataArr, $PROJECT) {
  920. if (fieldList) {
  921. for (let field of fieldList) {
  922. shielded_exec_env($PROJECT, field, rstDataArr);
  923. }
  924. }
  925. }
  926. function shielded_exec_env($PROJECT, $ME, rptDataItemObj) {
  927. if ($ME[JV.PROP_FIELD_EXP_MAP]) {
  928. rptDataItemObj.push(eval($ME[JV.PROP_FIELD_EXP_MAP]));
  929. }
  930. }
  931. function getActPropertyVal(firstPropKey, secPropKey, orgObj) {
  932. let rst = null;
  933. if (orgObj[firstPropKey]) {
  934. rst = orgObj[firstPropKey];
  935. } else if (orgObj[secPropKey]){
  936. rst = orgObj[secPropKey];
  937. }
  938. return rst;
  939. }
  940. function getDeepProperty(propKey, orgObj, destArr) {
  941. let keys = propKey.split(".");
  942. let dftPropKey = "key", dftPropVal = "value", secDftPropVal = "items";
  943. let parent = orgObj, lastVal = null;
  944. for (let key of keys) {
  945. if (parent instanceof Array) {
  946. for (let item of parent) {
  947. if (item[dftPropKey] === key) {
  948. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  949. break;
  950. }
  951. }
  952. } else {
  953. lastVal = null;
  954. if (parent[key] !== undefined) {
  955. lastVal = parent[key];
  956. } else if (parent[secDftPropVal]){
  957. for (let item of parent[secDftPropVal]) {
  958. if (item[dftPropKey] === key) {
  959. // lastVal = item[dftPropVal];
  960. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  961. break;
  962. }
  963. }
  964. }
  965. }
  966. parent = lastVal;
  967. if (parent === null) break;
  968. }
  969. if (destArr && destArr instanceof Array) {
  970. destArr.push(lastVal);
  971. }
  972. }
  973. function ext_mainGetPropety(propKey) {
  974. let rst = [], parentObj = this;
  975. let dtObj = parentObj["myOwnRawDataObj"];
  976. if (propKey && dtObj) {
  977. if (dtObj.hasOwnProperty("property")) {
  978. if (!dtObj["property"][propKey] && dtObj[propKey]) {
  979. rst.push(dtObj[propKey]);
  980. } else {
  981. getDeepProperty(propKey, dtObj["property"], rst);
  982. }
  983. } else {
  984. // rst.push(dtObj[propKey]);
  985. getDeepProperty(propKey, dtObj, rst);
  986. }
  987. }
  988. return rst;
  989. }
  990. function ext_getPropety(propKey) {
  991. let rst = [], parentObj = this;
  992. let dtObj = parentObj["myOwnRawDataObj"];
  993. if (propKey && dtObj) {
  994. for (let dItem of dtObj.data) {
  995. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  996. if (propKey instanceof Array) {
  997. for (let pi = 0; pi < propKey.length; pi++) {
  998. if (doc.hasOwnProperty("property")) {
  999. if (doc["property"].hasOwnProperty(propKey[pi])) {
  1000. rst.push(doc["property"][propKey[pi]]);
  1001. break;
  1002. }
  1003. } else if (doc.hasOwnProperty(propKey[pi])) {
  1004. rst.push(doc[propKey[pi]]);
  1005. break;
  1006. }
  1007. if (pi === propKey.length - 1) rst.push('');
  1008. }
  1009. } else {
  1010. if (doc.hasOwnProperty("property")) {
  1011. rst.push(doc["property"][propKey]);
  1012. } else if (doc.hasOwnProperty(propKey)) {
  1013. rst.push(doc[propKey]);
  1014. } else {
  1015. rst.push('');
  1016. }
  1017. }
  1018. }
  1019. }
  1020. return rst;
  1021. }
  1022. function ext_getPropertyByRefId(baseKey, refIDKey, propertyKey){
  1023. let rst = [], parentObj = this;
  1024. let dtObj = parentObj["myOwnRawDataObj"];
  1025. let orgDtObj = parentObj["myOwnOrgRawDataObj"];
  1026. if (baseKey && refIDKey && propertyKey && dtObj) {
  1027. for (let dItem of dtObj.data) {
  1028. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1029. let tmpRst = doc[baseKey];
  1030. if (typeof tmpRst === "string" && tmpRst[0] === "@") {
  1031. let refKey = tmpRst.slice(1);
  1032. let hasGetRef = false;
  1033. for (let orgDItem of orgDtObj) {
  1034. let oDoc = (orgDItem._doc === null || orgDItem._doc === undefined)?orgDItem:orgDItem._doc;
  1035. if (oDoc[refIDKey] === refKey) {
  1036. rst.push(oDoc[propertyKey]);
  1037. hasGetRef = true;
  1038. break;
  1039. }
  1040. }
  1041. if (!hasGetRef) {
  1042. rst.push(tmpRst);
  1043. }
  1044. } else {
  1045. rst.push(tmpRst);
  1046. }
  1047. }
  1048. }
  1049. return rst;
  1050. }
  1051. function ext_mainGetFee(feeKey, dtlFeeKey) {
  1052. let rst = [];
  1053. let parentObj = this;
  1054. let dtObj = parentObj["myOwnRawDataObj"];
  1055. if ((dtObj) && (feeKey)) {
  1056. if (dtObj.hasOwnProperty("fees")) {
  1057. for (let fee of dtObj["fees"]) {
  1058. if (fee["fieldName"] === feeKey) {
  1059. if (dtlFeeKey) {
  1060. rst.push(fee[dtlFeeKey]);
  1061. } else {
  1062. rst.push(fee["unitFee"]);
  1063. }
  1064. break;
  1065. }
  1066. }
  1067. } else if (dtObj.hasOwnProperty(feeKey)) {
  1068. rst.push(dtObj[feeKey]);
  1069. } else {
  1070. //
  1071. }
  1072. }
  1073. return rst;
  1074. }
  1075. function ext_getFee(feeKey, dtlFeeKey) {
  1076. let rst = [], parentObj = this;
  1077. let dtObj = parentObj["myOwnRawDataObj"];
  1078. if (feeKey && dtObj) {
  1079. for (let dItem of dtObj.data) {
  1080. rst.push(pri_getFee(dItem, feeKey, dtlFeeKey));
  1081. }
  1082. }
  1083. for (let i = 0; i < rst.length; i++) {
  1084. rst[i] = parseFloat(rst[i]);
  1085. }
  1086. return rst;
  1087. }
  1088. function pri_getFee(dItem, feeKey, dtlFeeKey) {
  1089. let rst = 0;
  1090. let hasValue = false;
  1091. if (dItem["fees"]) {
  1092. for (let fee of dItem["fees"]) {
  1093. if (fee["fieldName"] === feeKey) {
  1094. if (dtlFeeKey) {
  1095. rst = fee[dtlFeeKey];
  1096. } else {
  1097. rst = fee["unitFee"];
  1098. }
  1099. hasValue = true;
  1100. break;
  1101. }
  1102. }
  1103. } else if (dItem[feeKey]) {
  1104. hasValue = true;
  1105. rst = dItem[feeKey];
  1106. } else {
  1107. hasValue = true;
  1108. rst = 0;
  1109. }
  1110. if (!hasValue) {
  1111. rst = 0;
  1112. }
  1113. return rst;
  1114. }
  1115. function ext_getCalcProperty(templateIDs, calcItemKey, calcItemKeyVal, calcItemRstKey){
  1116. let rst = [], parentObj = this; //this should be "calc_program" object
  1117. let dtObj = parentObj["myOwnRawDataObj"];
  1118. let optimizeObj = {};
  1119. let private_getProperty = function (cId) {
  1120. let calcTplObj = optimizeObj["calc_program_" + cId];
  1121. if (!calcTplObj) {
  1122. let templates = (dtObj.data._doc)?dtObj.data._doc.templates:dtObj.data.templates;
  1123. for (let tpl of templates) {
  1124. if (cId === tpl.ID) {
  1125. optimizeObj["calc_program_" + cId] = tpl;
  1126. calcTplObj = tpl;
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. if (calcTplObj) {
  1132. for (let calcItem of calcTplObj.calcItems) {
  1133. if (calcItem[calcItemKey] === calcItemKeyVal) {
  1134. rst.push(calcItem[calcItemRstKey]);
  1135. break;
  1136. }
  1137. }
  1138. }
  1139. };
  1140. if (templateIDs instanceof Array) {
  1141. for (let tplId of templateIDs) {
  1142. private_getProperty(tplId);
  1143. }
  1144. } else {
  1145. private_getProperty(templateIDs);
  1146. }
  1147. optimizeObj = null;
  1148. return rst;
  1149. }
  1150. function ext_getFeeRate(fee_Ids){
  1151. let rst = [], parentObj = this; //this should be "feeRate" object
  1152. let dtObj = parentObj["myOwnRawDataObj"];
  1153. let optimizeObj = {};
  1154. let private_getFeeRate = function (fId) {
  1155. let feeRateItemObj = optimizeObj["fee_rates_" + fId];
  1156. if (!feeRateItemObj) {
  1157. let rates = (dtObj.data._doc)?dtObj.data._doc.rates:dtObj.data.rates;
  1158. for (let feeItem of rates) {
  1159. if (fId === feeItem.ID) {
  1160. optimizeObj["fee_rates_" + fId] = feeItem;
  1161. feeRateItemObj = feeItem;
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. if (feeRateItemObj) {
  1167. rst.push(feeRateItemObj.rate);
  1168. } else {
  1169. rst.push(0);
  1170. }
  1171. };
  1172. if (fee_Ids instanceof Array) {
  1173. for (let fId of fee_Ids) {
  1174. private_getFeeRate(fId);
  1175. }
  1176. } else {
  1177. private_getFeeRate(fee_Ids);
  1178. }
  1179. optimizeObj = null;
  1180. return rst;
  1181. }
  1182. function ext_getArrayValues(itemKey) {
  1183. let rst = [], parentObj = this;
  1184. let dtObj = parentObj["myOwnRawDataObj"];
  1185. let keysArr = itemKey.split(".");
  1186. for (let dataItem of dtObj.data) {
  1187. let itemArr = [];
  1188. if (keysArr.length <= 2) {
  1189. if (dataItem[keysArr[0]] instanceof Array) {
  1190. if (keysArr.length === 2) {
  1191. for (let item of dataItem[keysArr[0]]) {
  1192. itemArr.push(item[keysArr[1]]);
  1193. }
  1194. } else {
  1195. itemArr = itemArr.concat(dataItem[keysArr[0]]);
  1196. }
  1197. } else {
  1198. if (keysArr.length === 2) {
  1199. let subProperty = dataItem[keysArr[0]][keysArr[1]];
  1200. if (subProperty instanceof Array) {
  1201. itemArr = itemArr.concat(subProperty);
  1202. } else {
  1203. itemArr.push(subProperty);
  1204. }
  1205. } else {
  1206. itemArr.push(dataItem[keysArr[0]]);
  1207. }
  1208. }
  1209. }
  1210. rst.push(itemArr);
  1211. }
  1212. return rst;
  1213. }
  1214. function ext_getArrayItemByKey(arrayKey, itemKey, itemKeyValue, itemRstKey){
  1215. let rst = [], parentObj = this;
  1216. let dtObj = parentObj["myOwnRawDataObj"];
  1217. let private_getItemValue = function (arr, dtlItKV) {
  1218. for (let item of arr) {
  1219. if (item[itemKey] === dtlItKV) {
  1220. if (itemRstKey) {
  1221. rst.push(item[itemRstKey]);
  1222. } else {
  1223. rst.push(item);
  1224. }
  1225. break;
  1226. }
  1227. }
  1228. };
  1229. let arr = dtObj[arrayKey];
  1230. if (arr && arr instanceof Array) {
  1231. if (itemKeyValue instanceof Array) {
  1232. for (let dtlItemKeyVal of itemKeyValue) {
  1233. private_getItemValue(arr, dtlItemKeyVal);
  1234. }
  1235. } else {
  1236. private_getItemValue(arr, itemKeyValue);
  1237. }
  1238. }
  1239. }
  1240. function ext_getBlank(dftVal) {
  1241. let rst = [], parentObj = this;
  1242. let dtObj = parentObj["myOwnRawDataObj"];
  1243. if (dtObj) {
  1244. for (let i = 0; i < dtObj.data.length; i++) {
  1245. if (dftVal !== null && dftVal !== undefined) {
  1246. rst.push(dftVal)
  1247. } else rst.push('');
  1248. }
  1249. }
  1250. return rst;
  1251. }
  1252. function ext_getPropertyByFlag(flagVal, rstKey, dftValIfEmpty) {
  1253. let rst = [], parentObj = this;
  1254. let dtObj = parentObj["myOwnRawDataObj"];
  1255. if (flagVal && rstKey && dtObj) {
  1256. let isArr = (flagVal instanceof Array);
  1257. for (let dItem of dtObj.data) {
  1258. let doc = (dItem._doc)?dItem._doc:dItem;
  1259. if (doc.hasOwnProperty("flags")) {
  1260. let bFlag = false;
  1261. for (let flagItem of doc.flags) {
  1262. if (isArr) {
  1263. bFlag = (flagVal.indexOf(flagItem.flag) >= 0);
  1264. } else {
  1265. if (flagItem.flag === flagVal) {
  1266. bFlag = true;
  1267. }
  1268. }
  1269. if (bFlag) break;
  1270. }
  1271. if (bFlag) {
  1272. let keys = rstKey.split(".");
  1273. if (keys[0] === "fees") {
  1274. rst.push(pri_getFee(doc, "common", keys[1]));
  1275. } else {
  1276. //其他,比如名称什么
  1277. }
  1278. break;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. if (rst.length === 0 && dftValIfEmpty !== null) {
  1284. rst.push(dftValIfEmpty);
  1285. }
  1286. return rst;
  1287. }
  1288. function ext_getPropertyByForeignId(foreignIdVal, adHocIdKey, propKey, dftValIfNotFound) {
  1289. let rst = [], parentObj = this;
  1290. let IdKey = (adHocIdKey)?adHocIdKey:"ID";
  1291. let dtObj = parentObj["myOwnRawDataObj"];
  1292. let splitPKey = propKey.split(".");
  1293. if (foreignIdVal !== null && foreignIdVal !== undefined) {
  1294. let isFound = false;
  1295. if (foreignIdVal instanceof Array) {
  1296. for (let idVal of foreignIdVal) {
  1297. isFound = false;
  1298. let dataArr = dtObj.data;
  1299. if (dtObj.moduleName === "projectGLJ") dataArr = dtObj.data.gljList;
  1300. for (let i = 0; i < dataArr.length; i++) {
  1301. let item = (dataArr[i]._doc)?dataArr[i]._doc:dataArr[i];
  1302. if (item[IdKey] === idVal) {
  1303. if (splitPKey.length > 1) {
  1304. let rstP = null;
  1305. for (let i = 0; i < splitPKey.length; i++) {
  1306. if (i === 0) {
  1307. rstP = item[splitPKey[i]];
  1308. } else {
  1309. if (splitPKey[i].indexOf("[") === 0 && splitPKey[i].indexOf("]") === (splitPKey[i].length - 1)) {
  1310. //考虑数组情况^_^!!!
  1311. } else {
  1312. //
  1313. }
  1314. rstP = rstP[splitPKey[i]];
  1315. }
  1316. }
  1317. rst.push(rstP);
  1318. } else {
  1319. rst.push(item[propKey]);
  1320. }
  1321. isFound = true;
  1322. break;
  1323. }
  1324. }
  1325. if (!isFound) {
  1326. rst.push(dftValIfNotFound);
  1327. }
  1328. }
  1329. } else {
  1330. for (let item of dtObj.data) {
  1331. if (item[IdKey] === foreignIdVal) {
  1332. rst.push(item[propKey]);
  1333. isFound = true;
  1334. break;
  1335. }
  1336. }
  1337. if (!isFound) {
  1338. rst.push(dftValIfNotFound);
  1339. }
  1340. }
  1341. }
  1342. return rst;
  1343. }
  1344. export default Rpt_Data_Extractor;