rpt_yanghu_data_util.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  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 scMathUtil = require("../../../public/scMathUtil");
  11. let _ = require("lodash");
  12. let treeUtil = require('../../../public/treeUtil');
  13. let projectConst = consts.projectConst;
  14. let projectConstList = consts.projectConstList;
  15. const gljUtil = require('../../../public/gljUtil');
  16. const gljType = require('../../common/const/glj_type_const');
  17. // const pm_facade = require('../../pm/facade/pm_facade');
  18. const GLJID_PRE = `gljId_`, COMPONENT_GLJID_PRE = `componetGljId_`;
  19. const GLJ_TYPE = {
  20. Labour: 1,
  21. Material: 2,
  22. Machine: 3,
  23. Main_Material: 4,
  24. Equipment: 5,
  25. OTHER_MATERIAL: 207,
  26. MACHINE_LABOUR: 303,
  27. INSTRUMENT: 304,
  28. FUEL_POWER_FEE: 305
  29. };
  30. const oprMachines = [306, 307, 308, 309, 310, 311, 312];
  31. class Rpt_Common{
  32. initialize(rpt_tpl, currentDataObj) {
  33. this.template = rpt_tpl;
  34. this.currentDataObj = currentDataObj;
  35. };
  36. Multiply(val1, val2, fixFormat) {
  37. let rst = [], maxLen = val1.length, minLen = val2.length;
  38. if (minLen > maxLen) {
  39. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  40. }
  41. for (let i = 0; i < maxLen; i++) {
  42. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) * ((i < val2.length)?val2[i]:val2[minLen - 1]);
  43. if (value === null || value === undefined) {
  44. value = '0';
  45. }
  46. if (fixFormat) value = value.toFixed(fixFormat);
  47. rst.push(value);
  48. }
  49. return rst;
  50. };
  51. Divide(val1, val2, fixFormat) {
  52. let rst = [], maxLen = val1.length, minLen = val2.length;
  53. if (minLen > maxLen) {
  54. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  55. }
  56. for (let i = 0; i < maxLen; i++) {
  57. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) / ((i < val2.length)?val2[i]:val2[minLen - 1]);
  58. if (fixFormat) value = value.toFixed(fixFormat);
  59. rst.push(value);
  60. }
  61. return rst;
  62. };
  63. Plus(val1, val2, fixFormat) {
  64. let rst = [], maxLen = val1.length, minLen = val2.length;
  65. if (minLen > maxLen) {
  66. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  67. }
  68. for (let i = 0; i < maxLen; i++) {
  69. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) + ((i < val2.length)?val2[i]:val2[minLen - 1]);
  70. if (fixFormat) value = value.toFixed(fixFormat);
  71. rst.push(value);
  72. }
  73. return rst;
  74. };
  75. MultiPlus(arrVal, fixFormat) {
  76. let rst = [];
  77. for (let i = 0; i < arrVal.length; i++) {
  78. let valItem = arrVal[i];
  79. if (i === 0) {
  80. for (let dtl of valItem) {
  81. let value = parseFloat(dtl);
  82. if (fixFormat) value = value.toFixed(fixFormat);
  83. rst.push(value);
  84. }
  85. } else {
  86. for (let j = 0; j < valItem.length; j++) {
  87. if (j < rst.length) {
  88. let value = rst[j] + valItem[j];
  89. if (fixFormat) value = value.toFixed(fixFormat);
  90. rst[j] = value;
  91. } else {
  92. let value = parseFloat(valItem[j]);
  93. if (fixFormat) value = value.toFixed(fixFormat);
  94. rst.push(value);
  95. }
  96. }
  97. }
  98. }
  99. return rst;
  100. };
  101. Minus(val1, val2, fixFormat) {
  102. let rst = [], maxLen = val1.length, minLen = val2.length;
  103. if (minLen > maxLen) {
  104. maxLen = maxLen + minLen; minLen = maxLen - minLen; maxLen = maxLen - minLen;
  105. }
  106. for (let i = 0; i < maxLen; i++) {
  107. let value = ((i < val1.length)?val1[i]:val1[minLen - 1]) - ((i < val2.length)?val2[i]:val2[minLen - 1]);
  108. if (fixFormat) value = value.toFixed(fixFormat);
  109. rst.push(value);
  110. }
  111. return rst;
  112. };
  113. FormatString(arrVal, formatStr){
  114. let rst = [];
  115. for (let val of arrVal) {
  116. rst.push(stringUtil.replaceAll(formatStr, '%S', val));
  117. }
  118. return rst;
  119. };
  120. }
  121. class Rpt_Data_Extractor {
  122. constructor () {
  123. this.COMMON = new Rpt_Common();
  124. };
  125. initialize(tpl) {
  126. this.rptTpl = tpl;
  127. };
  128. //-- 根据报表模板映射指标(非离散指标)的定义,罗列出所有需要用到的data对象key,作为数据请求的过滤依据
  129. getDataRequestFilter(summaryRst) {
  130. let rst = [];
  131. let tpl = this.rptTpl;
  132. let pri_func_chk_filter = function (field) {
  133. for (let key of projectConstList) {
  134. if (rst.indexOf(key) < 0) {
  135. if (field[JV.PROP_FIELD_EXP_MAP]) {
  136. if (field[JV.PROP_FIELD_EXP_MAP].indexOf('.' + key + '.') >= 0) {
  137. rst.push(key);
  138. if (key === projectConst.RATION_GLJ && (rst.indexOf(projectConst.PROJECTGLJ) < 0)) {
  139. rst.push(projectConst.PROJECTGLJ);
  140. }
  141. if (key === projectConst.PROJECTGLJ) {
  142. if (rst.indexOf(projectConst.RATION_GLJ) < 0) rst.push(projectConst.RATION_GLJ);
  143. if (field[JV.PROP_FIELD_EXP_MAP].indexOf("'quantity'") > 0 ||
  144. field[JV.PROP_FIELD_EXP_MAP].indexOf("'subdivisionQuantity'") > 0 ||
  145. field[JV.PROP_FIELD_EXP_MAP].indexOf("'techQuantity'") > 0 ) {
  146. if (rst.indexOf(projectConst.RATION) < 0) rst.push(projectConst.RATION);
  147. if (rst.indexOf(projectConst.BILLS) < 0) rst.push(projectConst.BILLS);
  148. //备注:项目工料机的数量是需要根据定额清单来计算的!这里的逻辑是对的
  149. }
  150. }
  151. }
  152. }
  153. } else if (key === projectConst.PROJECTGLJ) {
  154. if (rst.indexOf(projectConst.RATION_GLJ) < 0) rst.push(projectConst.RATION_GLJ);
  155. if (field[JV.PROP_FIELD_EXP_MAP].indexOf("'quantity'") > 0 ||
  156. field[JV.PROP_FIELD_EXP_MAP].indexOf("'subdivisionQuantity'") > 0 ||
  157. field[JV.PROP_FIELD_EXP_MAP].indexOf("'techQuantity'") > 0 ) {
  158. if (rst.indexOf(projectConst.RATION) < 0) rst.push(projectConst.RATION);
  159. if (rst.indexOf(projectConst.BILLS) < 0) rst.push(projectConst.BILLS);
  160. //备注:项目工料机的数量是需要根据定额清单来计算的!这里的逻辑是对的
  161. }
  162. }
  163. }
  164. if (summaryRst instanceof Array) {
  165. for (let key of consts.summaryConstList) {
  166. if (summaryRst.indexOf(key) < 0) {
  167. if (field[JV.PROP_FIELD_EXP_MAP]) {
  168. if (field[JV.PROP_FIELD_EXP_MAP].indexOf('.' + key + '.') >= 0) {
  169. summaryRst.push(key);
  170. }
  171. }
  172. }
  173. }
  174. }
  175. };
  176. let pri_setup_filter = function (FIELD_LIST_KEY) {
  177. if (tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  178. for (let field of tpl[JV.NODE_FIELD_MAP][FIELD_LIST_KEY]) {
  179. pri_func_chk_filter(field);
  180. }
  181. }
  182. };
  183. pri_setup_filter(JV.NODE_DISCRETE_FIELDS);
  184. pri_setup_filter(JV.NODE_MASTER_FIELDS);
  185. pri_setup_filter(JV.NODE_DETAIL_FIELDS);
  186. pri_setup_filter(JV.NODE_MASTER_FIELDS_EX);
  187. pri_setup_filter(JV.NODE_DETAIL_FIELDS_EX);
  188. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO] && tpl[JV.NODE_MAP_DATA_HANDLE_INFO].length > 0) {
  189. for (let preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  190. if (rst.indexOf(preHandle[JV.PROP_DATA_KEY]) < 0) {
  191. rst.push(preHandle[JV.PROP_DATA_KEY]);
  192. }
  193. if (preHandle[JV.PROP_HANDLE_TYPE] === JV.PROP_HANDLE_TYPE_FILTER) {
  194. if (preHandle[JV.PROP_FILTER_KEYS]) {
  195. for (let filter of preHandle[JV.PROP_FILTER_KEYS]) {
  196. if (filter[JV.PROP_FILTER_COMPARE_OBJ] && rst.indexOf(filter[JV.PROP_FILTER_COMPARE_OBJ]) < 0) {
  197. rst.push(filter[JV.PROP_FILTER_COMPARE_OBJ]);
  198. }
  199. }
  200. }
  201. } else if (preHandle[JV.PROP_HANDLE_TYPE] === JV.PROP_HANDLE_TYPE_SUM) {
  202. if (preHandle[JV.PROP_SUM_GROUP_KEYS]) {
  203. for (let grpKey of preHandle[JV.PROP_SUM_GROUP_KEYS]) {
  204. if (grpKey.seeking_parent && rst.indexOf(grpKey.seeking_parent) < 0) {
  205. rst.push(grpKey.seeking_parent);
  206. }
  207. }
  208. }
  209. } else if (preHandle[JV.PROP_PARENT_CHILD_SORT_KEY] && preHandle[JV.PROP_PARENT_CHILD_SORT_KEY].length > 0) {
  210. for (let item of preHandle[JV.PROP_PARENT_CHILD_SORT_KEY]) {
  211. if (rst.indexOf(item[JV.PROP_PARENT_DATA_KEY]) < 0) {
  212. rst.push(item[JV.PROP_PARENT_DATA_KEY]);
  213. }
  214. }
  215. }
  216. }
  217. }
  218. if (rst.indexOf(projectConst.RATION) >= 0 &&
  219. rst.indexOf(projectConst.RATION_GLJ) >= 0 && rst.indexOf(projectConst.RATION_COE) < 0) {
  220. rst.push(projectConst.RATION_COE);
  221. //备注:在此情况下,根据业务特点,有可能需要额外计算project工料机的基价单价及市场单价,需要用到一些额外信息处理。
  222. // 这里也不精细控制,直接多加一个请求类型。以后说不定还有其他类型的请求,到时候再加。
  223. }
  224. if (rst.length === 0) {
  225. rst.push(projectConst.RATION_ASS);
  226. }
  227. return rst;
  228. };
  229. //--- 装配数据(把收集到的数据,依据报表模板的指示,预处理(如:排序、过滤、合计)及装配到相关指标) ---//
  230. assembleData(rawDataObj) {
  231. let $PROJECT = {"COMMON": null, "MAIN": {}, "DETAIL": {}};
  232. let tpl = this.rptTpl;
  233. this.COMMON.initialize(tpl, rawDataObj);
  234. $PROJECT.COMMON = this.COMMON;
  235. if (rawDataObj.hasOwnProperty(`prj`) && rawDataObj.hasOwnProperty(`prjData`)) {
  236. setupMainFunc($PROJECT, `MAIN`, rawDataObj.prj._doc);
  237. // $PROJECT.MAIN["myOwnRawDataObj"] = rawDataObj.prj._doc;
  238. // $PROJECT.MAIN.getProperty = ext_mainGetPropety;
  239. // $PROJECT.MAIN.getFee = ext_mainGetFee;
  240. for (let item of rawDataObj.prjData) {
  241. setupFunc($PROJECT.DETAIL, item.moduleName, item);
  242. }
  243. let projectGLJDatas = getModuleDataByKey(rawDataObj.prjData, "projectGLJ");
  244. if (projectGLJDatas) {
  245. //增加一个辅助对象,方便通过gljid key直接获取数据,省去循环时间
  246. let gljAssitantObj = {"gljIds": {}, "componentGljIds": {}};
  247. projectGLJDatas.data.gljAssistant = gljAssitantObj;
  248. for (let gljItem of projectGLJDatas.data.gljList) {
  249. gljAssitantObj.gljIds[GLJID_PRE + gljItem.id] = gljItem;
  250. if (!(gljItem.ratio_data) || gljItem.ratio_data.length === 0) {
  251. gljAssitantObj.componentGljIds[COMPONENT_GLJID_PRE + gljItem.glj_id] = gljItem;
  252. }
  253. }
  254. //顺便做个排序(跟UI一致的排序)
  255. }
  256. let rationGLJDatas = getModuleDataByKey(rawDataObj.prjData, "ration_glj");
  257. let rationDatas = getModuleDataByKey(rawDataObj.prjData, "ration");
  258. let billsDatas = getModuleDataByKey(rawDataObj.prjData, "bills");
  259. let decimal = rawDataObj.prj.property.decimal.glj.quantity;
  260. if (projectGLJDatas && rationGLJDatas && rationDatas && billsDatas) {
  261. gljUtil.calcProjectGLJQuantity(projectGLJDatas.data, rationGLJDatas.data, rationDatas.data, billsDatas.data, decimal);
  262. }
  263. }
  264. //还有汇总的...
  265. if (rawDataObj.hasOwnProperty(`Construct`) || rawDataObj.hasOwnProperty(`ConstructDetail`) || rawDataObj.hasOwnProperty(`Segment`) || rawDataObj.hasOwnProperty(`SegmentDetail`)
  266. || rawDataObj.hasOwnProperty(`SummaryAudit`) || rawDataObj.hasOwnProperty(`SummaryAuditDetail`)) {
  267. $PROJECT.SUMMARY = {};
  268. if (rawDataObj.Construct) {
  269. setupMainFunc($PROJECT.SUMMARY, `Construct`, rawDataObj.Construct);
  270. }
  271. if (rawDataObj.ConstructDetail) {
  272. setupFunc($PROJECT.SUMMARY, `ConstructDetail`, {"data": rawDataObj.ConstructDetail});
  273. }
  274. if (rawDataObj.Segment) {
  275. setupMainFunc($PROJECT.SUMMARY, `Segment`, rawDataObj.Segment);
  276. }
  277. if (rawDataObj.SegmentDetail) {
  278. setupFunc($PROJECT.SUMMARY, `SegmentDetail`, {"data": rawDataObj.SegmentDetail});
  279. }
  280. if (rawDataObj.SummaryAudit) {
  281. setupMainFunc($PROJECT.SUMMARY, `SummaryAudit`, rawDataObj.SummaryAudit);
  282. }
  283. if (rawDataObj.SummaryAuditDetail) {
  284. setupFunc($PROJECT.SUMMARY, `SummaryAuditDetail`, {"data": rawDataObj.SummaryAuditDetail});
  285. }
  286. }
  287. //综合费率
  288. let feeRate = getModuleDataByKey(rawDataObj.prjData, "feeRate");
  289. if (feeRate) {
  290. //把综合费率树结构数据拉扁
  291. // console.log(feeRate);
  292. let newFeeRates = setupFeeRate(feeRate.data._doc);
  293. // console.log(newFeeRates);
  294. feeRate.data._doc.rates = newFeeRates;
  295. }
  296. if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  297. for (let preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
  298. let srcData = getModuleDataByKey(rawDataObj.prjData, preHandle[JV.PROP_DATA_KEY]);
  299. switch(preHandle[JV.PROP_HANDLE_TYPE]) {
  300. case JV.PROP_HANDLE_TYPE_SORT:
  301. sortData(srcData, preHandle, rawDataObj.prjData);
  302. break;
  303. case JV.PROP_HANDLE_TYPE_FILTER:
  304. filterData(srcData, preHandle, rawDataObj.prjData);
  305. break;
  306. case JV.PROP_HANDLE_TYPE_SUM:
  307. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData10.jsp");
  308. summaryData(srcData, preHandle, rawDataObj.prjData, rawDataObj.prj);
  309. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData11.jsp");
  310. break;
  311. case JV.PROP_HANDLE_TYPE_ADD_DUMMY:
  312. addDummyData(srcData, preHandle);
  313. break;
  314. case JV.PROP_HANDLE_TYPE_ADJUST:
  315. adjustData(srcData, preHandle);
  316. break;
  317. case JV.PROP_HANDLE_TYPE_BILLS_DATA_MOVE:
  318. //把显示在清单中的量材转移到工料机去, 顺带把项目工料机的组成物工料机分解出来,分解的工料机作为定额工料机保存(02表用)
  319. moveRationData(srcData, rawDataObj);
  320. break;
  321. case JV.PROP_HANDLE_TYPE_COMPONENT_MOVE:
  322. //把定额下的组成物的工料机分解出来,分解的工料机作为定额工料机保存(02表用)
  323. moveRationComponentData(srcData, rawDataObj);
  324. break;
  325. case JV.PROP_HANDLE_TYPE_COMPONENT_REPLACEMENT:
  326. //重庆2018 09-x表专用,机械数据用 组成物替换掉 ^_^!
  327. componentReplacement(rawDataObj);
  328. break;
  329. default:
  330. break;
  331. }
  332. }
  333. }
  334. //一些计算(不保存数据,需要动态计算的)
  335. if (rawDataObj.hasOwnProperty(`prj`) && rawDataObj.hasOwnProperty(`prjData`)) {
  336. let calcOptions = rawDataObj.prj._doc.property.calcOptions;
  337. let decimalObj = rawDataObj.prj._doc.property.decimal;
  338. let labourCoeDatas = getModuleDataByKey(rawDataObj.prjData, "labour_coe");
  339. let prjGLJDatas = getModuleDataByKey(rawDataObj.prjData, "projectGLJ");
  340. let rationDatas = getModuleDataByKey(rawDataObj.prjData, "ration");
  341. if (calcOptions && decimalObj && labourCoeDatas && labourCoeDatas && prjGLJDatas && rationDatas) {
  342. for (let rationItem of rationDatas.data) {
  343. let glj = _.find(prjGLJDatas.data.gljList, {'id': rationItem.projectGLJID});
  344. if (glj) {
  345. let newGlj = gljUtil.getGLJPrice(glj, prjGLJDatas.data, calcOptions, labourCoeDatas, decimalObj, false, _, scMathUtil);
  346. rationItem.marketPrice = newGlj.marketPrice;
  347. rationItem.basePrice = newGlj.basePrice;
  348. rationItem.adjustPrice = newGlj.adjustPrice;
  349. rationItem.marketUnitFee = newGlj.marketPrice;//更新树节点市场单价列的值
  350. }
  351. }
  352. }
  353. // console.log("重新计算!");
  354. }
  355. //
  356. let rptDataObj = {};
  357. rptDataObj[JV.DATA_DISCRETE_DATA] = [];
  358. rptDataObj[JV.DATA_MASTER_DATA] = [];
  359. rptDataObj[JV.DATA_DETAIL_DATA] = [];
  360. rptDataObj[JV.DATA_MASTER_DATA_EX] = [];
  361. rptDataObj[JV.DATA_DETAIL_DATA_EX] = [];
  362. if (rawDataObj.hasOwnProperty(`prj`) && rawDataObj.hasOwnProperty(`prjData`)) {
  363. rptDataObj.DecimalObj = {};
  364. rptDataObj.DecimalObj.prjDecimal = $PROJECT.MAIN["myOwnRawDataObj"].decimal; //为函数 P_REF() 准备数据
  365. rptDataObj.DecimalObj.unitDecimal = getUnitDecimal($PROJECT.MAIN["myOwnRawDataObj"].billsQuantityDecimal); //为函数 U_REF() 准备数据
  366. }
  367. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS], rptDataObj[JV.DATA_DISCRETE_DATA], $PROJECT);
  368. // console.log(JV.DATA_DISCRETE_DATA);
  369. // console.log(rptDataObj[JV.DATA_DISCRETE_DATA]);
  370. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], rptDataObj[JV.DATA_MASTER_DATA], $PROJECT);
  371. // console.log(JV.DATA_MASTER_DATA);
  372. // console.log(rptDataObj[JV.DATA_MASTER_DATA]);
  373. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS], rptDataObj[JV.DATA_DETAIL_DATA], $PROJECT);
  374. // console.log(JV.DATA_DETAIL_DATA);
  375. // console.log(rptDataObj[JV.DATA_DETAIL_DATA]);
  376. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS_EX], rptDataObj[JV.DATA_MASTER_DATA_EX], $PROJECT);
  377. // console.log(JV.DATA_MASTER_DATA_EX);
  378. // console.log(rptDataObj[JV.DATA_MASTER_DATA_EX]);
  379. assembleFields(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS_EX], rptDataObj[JV.DATA_DETAIL_DATA_EX], $PROJECT);
  380. // console.log(JV.DATA_DETAIL_DATA_EX);
  381. // console.log(rptDataObj[JV.DATA_DETAIL_DATA_EX]);
  382. // fsUtil.writeObjToFile(rptDataObj, "D:/GitHome/ConstructionCost/tmp/insertedOriginalData.jsp");
  383. // fsUtil.writeObjToFile(rawDataObj, "D:/GitHome/ConstructionCost/tmp/insertedRawDataData.jsp");
  384. // fsUtil.writeObjToFile($PROJECT, "D:/GitHome/ConstructionCost/tmp/$PROJECTData.jsp");
  385. // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS], "D:/GitHome/ConstructionCost/tmp/masterFieldsAfterAssemble.jsp");
  386. // fsUtil.writeObjToFile(tpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS], "D:/GitHome/ConstructionCost/tmp/detailFieldsAfterAssemble.jsp");
  387. return rptDataObj;
  388. };
  389. }
  390. //小数位数依据单位来调整(如吨、公斤的精度要求就不同)
  391. function getUnitDecimal(unitDecimalArr) {
  392. let rst = {"default_decimal": 2};
  393. if (unitDecimalArr) {
  394. for (let item of unitDecimalArr) {
  395. if (item.unit === "其他未列单位") {
  396. rst["default_decimal"] = item.decimal;
  397. } else {
  398. rst['unit_decimal_' + item.unit] = item.decimal;
  399. }
  400. }
  401. }
  402. return rst;
  403. }
  404. function getModuleDataByKey(prjData, key) {
  405. let rst = null;
  406. if (prjData) {
  407. for (let item of prjData) {
  408. if (item.moduleName === key) {
  409. rst = item;
  410. break;
  411. }
  412. }
  413. }
  414. return rst;
  415. }
  416. function summaryData(sourceData, handleCfg, prjData, prjMain){
  417. let rstArr = [], tempRstArr = [];
  418. let curParentPrjData = {};
  419. let precision = 6;
  420. if (handleCfg[JV.PROP_HANDLE_TYPE_PRECISION]) {
  421. if (isNaN(parseInt(handleCfg[JV.PROP_HANDLE_TYPE_PRECISION]))) {
  422. let properties = handleCfg[JV.PROP_HANDLE_TYPE_PRECISION].split('.');
  423. let currentProperty = prjMain[properties[0]];
  424. for (let idx = 1; idx < properties.length; idx++) {
  425. currentProperty = currentProperty[properties[idx]];
  426. }
  427. if (!isNaN(parseInt(currentProperty))) {
  428. precision = parseInt(currentProperty);
  429. }
  430. } else {
  431. precision = parseInt(handleCfg[JV.PROP_HANDLE_TYPE_PRECISION]);
  432. }
  433. }
  434. for (let item of getActDataArr(sourceData)) {
  435. if (item._doc) {
  436. tempRstArr.push(item._doc);
  437. } else {
  438. tempRstArr.push(item);
  439. }
  440. }
  441. let private_cal_before_sum = function () {
  442. for (let calcAheadObj of handleCfg[JV.PROP_SUM_CALC_AHEAD]) {
  443. if (!curParentPrjData[calcAheadObj["seeking_parent"]]) curParentPrjData[calcAheadObj["seeking_parent"]] = getModuleDataByKey(prjData, calcAheadObj["seeking_parent"]);
  444. for (let idxP = 0; idxP < curParentPrjData[calcAheadObj["seeking_parent"]].data.length; idxP++) {
  445. let pDataItem = curParentPrjData[calcAheadObj["seeking_parent"]].data[idxP];
  446. let data = (pDataItem._doc)?pDataItem._doc:pDataItem;
  447. for (let idx = 0; idx < tempRstArr.length; idx++) {
  448. let dtlItem = tempRstArr[idx];
  449. if (dtlItem[calcAheadObj["seeking_key"]] === data[calcAheadObj["parent_key"]]) {
  450. for (let sumKey of handleCfg[JV.PROP_SUM_SUM_KEYS]) {
  451. switch (calcAheadObj[JV.PROP_SUM_CACL_TYPE]) {
  452. case "+":
  453. dtlItem[sumKey] = parseFloat(dtlItem[sumKey]) + parseFloat(data[calcAheadObj["calc_property"]]);
  454. break;
  455. case "-":
  456. dtlItem[sumKey] = parseFloat(dtlItem[sumKey]) - parseFloat(data[calcAheadObj["calc_property"]]);
  457. break;
  458. case "*":
  459. dtlItem[sumKey] = dtlItem[sumKey] * parseFloat(data[calcAheadObj["calc_property"]]);
  460. break;
  461. case "/":
  462. dtlItem[sumKey] = dtlItem[sumKey] / parseFloat(data[calcAheadObj["calc_property"]]);
  463. break;
  464. default:
  465. break;
  466. }
  467. }
  468. // break;
  469. }
  470. }
  471. }
  472. }
  473. };
  474. let private_get_grp_key = function (item) {
  475. let keys = [];
  476. for (let cfg of handleCfg[JV.PROP_SUM_GROUP_KEYS]) {
  477. if (typeof cfg === "string") {
  478. keys.push(item[cfg]);
  479. } else {
  480. if (!curParentPrjData[cfg["seeking_parent"]]) curParentPrjData[cfg["seeking_parent"]] = getModuleDataByKey(prjData, cfg["seeking_parent"]);
  481. for (let pDataItem of curParentPrjData[cfg["seeking_parent"]].data) {
  482. let data = (pDataItem._doc)?pDataItem._doc:pDataItem;
  483. if (item[cfg["seeking_key"]] === data[cfg["parent_key"]]) {
  484. keys.push(data[cfg["parent_grp_key"]]);
  485. break;
  486. }
  487. }
  488. }
  489. }
  490. return ( "grp_key_" + keys.join('_'));
  491. };
  492. let sumObj = {};
  493. if (handleCfg[JV.PROP_SUM_CALC_AHEAD] && handleCfg[JV.PROP_SUM_CALC_AHEAD].length > 0) {
  494. private_cal_before_sum();
  495. }
  496. for (let dtl of tempRstArr) {
  497. let grpKey = private_get_grp_key(dtl);
  498. if (sumObj[grpKey] === null || sumObj[grpKey] === undefined) {
  499. sumObj[grpKey] = dtl;
  500. rstArr.push(dtl);
  501. } else {
  502. for (let sumKey of handleCfg[JV.PROP_SUM_SUM_KEYS]) {
  503. if (dtl[sumKey]) {
  504. // sumObj[grpKey][sumKey] += dtl[sumKey];
  505. sumObj[grpKey][sumKey] = parseFloat(parseFloat(sumObj[grpKey][sumKey]).toFixed(precision)) + parseFloat(parseFloat(dtl[sumKey]).toFixed(precision));
  506. }
  507. }
  508. }
  509. }
  510. replaceActDataArr(sourceData, rstArr);
  511. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/sumRst.jsp");
  512. }
  513. function filterData(sourceData, handleCfg, prjData) {
  514. let rstArr = [], tempRstArr = [];
  515. for (let item of getActDataArr(sourceData)) {
  516. if (item._doc) {
  517. tempRstArr.push(item._doc);
  518. } else {
  519. tempRstArr.push(item);
  520. }
  521. }
  522. let private_chkVal = function (src, compVal, compStr) {
  523. let rst = true;
  524. switch (compStr) {
  525. case "==" :
  526. rst = (src == compVal);
  527. break;
  528. case "===" :
  529. rst = (src === compVal);
  530. break;
  531. case ">" :
  532. rst = (src > compVal);
  533. break;
  534. case ">=" :
  535. rst = (src >= compVal);
  536. break;
  537. case "<" :
  538. rst = (src < compVal);
  539. break;
  540. case "<=" :
  541. rst = (src <= compVal);
  542. break;
  543. case "!=" :
  544. rst = (src != compVal);
  545. break;
  546. case "!==" :
  547. rst = (src !== compVal);
  548. break;
  549. case "in" :
  550. if (compVal instanceof Array) {
  551. rst = compVal.indexOf(src) >= 0;
  552. } else {
  553. //string,需要转类型
  554. let newInCv = JSON.parse(compVal);
  555. if (newInCv instanceof Array) {
  556. rst = newInCv.indexOf(src) >= 0;
  557. } else {
  558. rst = false;
  559. }
  560. }
  561. break;
  562. case "not in":
  563. if (compVal instanceof Array) {
  564. rst = compVal.indexOf(src) < 0;
  565. } else {
  566. //string,需要转类型
  567. let newNotInCv = JSON.parse(compVal);
  568. if (newNotInCv instanceof Array) {
  569. rst = (newNotInCv.indexOf(src) < 0);
  570. } else {
  571. rst = true;
  572. }
  573. }
  574. break;
  575. default:
  576. rst = true;
  577. }
  578. return rst;
  579. };
  580. let private_chkArrVal = function(arr, key, compVal, compStr){
  581. let rst = false;
  582. if (arr.length > 0) {
  583. for (let arrItem of arr) {
  584. if (arrItem[key] !== undefined) {
  585. // 可以为null值去判断
  586. rst = private_chkVal(arrItem[key], compVal, compStr);
  587. }
  588. if (rst) {
  589. break;
  590. }
  591. }
  592. } else {
  593. //在某些判断条件下(含有'非'判断),如arr没有数组项,默认结果反而是true
  594. switch (compStr) {
  595. case "!=" :
  596. case "!==" :
  597. case "not in":
  598. rst = true;
  599. break;
  600. default:
  601. break;
  602. }
  603. }
  604. return rst;
  605. };
  606. let private_filter_compare = function (item, filterCfg) {
  607. let compareObj = {};
  608. let compRst = true;
  609. let curComparePrjData = null;
  610. let startIdx = 0;
  611. let private_ref_join = function(refKey, targetDataKey, targetPropertyKey) {
  612. let rst = null, objDataArr = null;
  613. curComparePrjData = getModuleDataByKey(prjData, targetDataKey);
  614. try {
  615. if (curComparePrjData !== null) {
  616. objDataArr = getActDataArr(curComparePrjData);
  617. for (let dtl of objDataArr) {
  618. if (item[refKey] === dtl[targetPropertyKey]) {
  619. rst = dtl;
  620. break;
  621. }
  622. }
  623. }
  624. } finally {
  625. curComparePrjData = null;
  626. }
  627. return rst;
  628. };
  629. for (let cfg of filterCfg[JV.PROP_FILTER_KEYS]) {
  630. if (cfg[JV.PROP_FILTER_COMPARE_VAL]) {
  631. //比较key值
  632. let keys = cfg.key.split(".");
  633. if (keys.length > 1) {
  634. let lastObj = item;
  635. for (let i = 0; i < keys.length - 1; i++) {
  636. if (keys[i].indexOf("ref_join(") === 0) {
  637. let params = keys[i].slice(9, keys[i].length - 1).split(",");
  638. if (params.length === 3) {
  639. lastObj = private_ref_join(params[0], params[1], params[2]);
  640. }
  641. if (!(lastObj)) {
  642. compRst = false;
  643. break;
  644. }
  645. } else {
  646. lastObj = item[keys[i]];
  647. if (!(lastObj)) {
  648. compRst = false;
  649. break;
  650. }
  651. }
  652. }
  653. if (lastObj) {
  654. if (lastObj instanceof Array) {
  655. compRst = private_chkArrVal(lastObj, keys[keys.length - 1], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  656. } else {
  657. compRst = private_chkVal(lastObj[keys[keys.length - 1]], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  658. }
  659. }
  660. } else {
  661. compRst = private_chkVal(item[cfg.key], cfg[JV.PROP_FILTER_COMPARE_VAL], cfg[JV.PROP_FILTER_CONDITION]);
  662. }
  663. } else if (cfg[JV.PROP_FILTER_COMPARE_OBJ] && cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]){
  664. //通过其他对象来过滤
  665. if (!curComparePrjData) {
  666. curComparePrjData = getModuleDataByKey(prjData, cfg[JV.PROP_FILTER_COMPARE_OBJ]);
  667. }
  668. if (cfg[JV.PROP_FILTER_CONDITION] === "in" || cfg[JV.PROP_FILTER_CONDITION] === "not in") {
  669. let compareArr = null;
  670. if (!compareObj.hasOwnProperty(cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString())) {
  671. compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()] = [];
  672. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  673. for (let data of getActDataArr(curComparePrjData)) {
  674. if (compareArr.indexOf(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]) < 0) {
  675. compareArr.push(data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]]);
  676. }
  677. }
  678. } else {
  679. compareArr = compareObj[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY] + startIdx.toString()];
  680. }
  681. compRst = private_chkVal(item[cfg.key], compareArr, cfg[JV.PROP_FILTER_CONDITION]);
  682. } else {
  683. for (let data of getActDataArr(curComparePrjData)) {
  684. compRst = private_chkVal(item[cfg.key], data[cfg[JV.PROP_FILTER_COMPARE_OBJ_KEY]], cfg[JV.PROP_FILTER_CONDITION]);
  685. if (compRst) break;
  686. }
  687. }
  688. }
  689. startIdx++;
  690. if (!compRst) {
  691. break; //有不符合条件的数据则退出(这里的判断条件是and关系)
  692. }
  693. }
  694. return compRst;
  695. };
  696. let private_sub_filter_compare = function (dtlItem, subFilters) {
  697. let cmpRst = false;
  698. for (let dtlCfg of subFilters) {
  699. cmpRst = private_filter_compare(dtlItem, dtlCfg);
  700. if (cmpRst) {
  701. if (dtlCfg[JV.PROP_OTHER_SUB_FILTER] && dtlCfg[JV.PROP_OTHER_SUB_FILTER].length > 0) {
  702. cmpRst = private_sub_filter_compare(dtlItem, dtlCfg[JV.PROP_OTHER_SUB_FILTER]);
  703. if (cmpRst) break;
  704. } else {
  705. break;
  706. }
  707. }
  708. }
  709. return cmpRst;
  710. };
  711. for (let item of tempRstArr) {
  712. if (private_filter_compare(item, handleCfg)) {
  713. rstArr.push(item);
  714. }
  715. }
  716. if (handleCfg[JV.PROP_OTHER_SUB_FILTER] && handleCfg[JV.PROP_OTHER_SUB_FILTER].length > 0) {
  717. let newRstArr = [];
  718. for (let dtlItem of rstArr) {
  719. let cmpRst = private_sub_filter_compare(dtlItem, handleCfg[JV.PROP_OTHER_SUB_FILTER]);
  720. if (cmpRst) {
  721. newRstArr.push(dtlItem);
  722. }
  723. }
  724. rstArr = newRstArr;
  725. }
  726. replaceActDataArr(sourceData, rstArr);
  727. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/filteredRst.jsp");
  728. }
  729. function adjustData(sourceData, adjustCfg) {
  730. let rstArr = [];
  731. for (let item of getActDataArr(sourceData)) {
  732. if (item._doc) {
  733. rstArr.push(item._doc);
  734. } else {
  735. rstArr.push(item);
  736. }
  737. }
  738. for (let item of adjustCfg[JV.PROP_ADJUST_COLLECTION]) {
  739. for (let rec of rstArr) {
  740. if (item[JV.PROP_ADJUST_ACTION] === "prefix") {
  741. rec[item.key] = item[JV.PROP_ADJUST_ACTION_VAL] + rec[item.key];
  742. } else if (item[JV.PROP_ADJUST_ACTION] === "suffix") {
  743. rec[item.key] = rec[item.key] + item[JV.PROP_ADJUST_ACTION_VAL];
  744. }
  745. }
  746. }
  747. replaceActDataArr(sourceData, rstArr);
  748. }
  749. function componentReplacement(rawDataObj) {
  750. let rationGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION_GLJ),
  751. prjGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.PROJECTGLJ),
  752. gljAssistant = prjGljData.data.gljAssistant;
  753. let connectStrArr = [], dataArr = getActDataArr(rationGljData), rvRGljIds = [], replaceGljItems = [];
  754. for (let idx = 0; idx < dataArr.length; idx++) {
  755. let rationGljItem = dataArr[idx];
  756. if (rationGljItem.type === 301 || rationGljItem.type === 302) {
  757. connectStrArr[0] = rationGljItem.code;
  758. connectStrArr[1] = rationGljItem.name;
  759. connectStrArr[2] = rationGljItem.specs;
  760. connectStrArr[3] = rationGljItem.unit;
  761. connectStrArr[4] = rationGljItem.type;
  762. let mapData = prjGljData.data.mixRatioMap[connectStrArr.join('|-|')];
  763. if (mapData) {
  764. rvRGljIds.push(idx);
  765. let rgItems = [];
  766. replaceGljItems.push(rgItems);
  767. for (let mapItem of mapData) {
  768. let copyItem = {};
  769. rgItems.push(copyItem);
  770. copyItem.ID = `Replace_` + rationGljItem.ID;
  771. copyItem.projectID = rationGljItem.projectID;
  772. copyItem.GLJID = rationGljItem.GLJID;
  773. copyItem.rationID = rationGljItem.rationID;
  774. if (gljAssistant.componentGljIds[COMPONENT_GLJID_PRE + mapItem.glj_id]) {
  775. copyItem.projectGLJID = gljAssistant.componentGljIds[COMPONENT_GLJID_PRE + mapItem.glj_id].id; //关键key
  776. } else {
  777. copyItem.projectGLJID = mapItem.glj_id; //不应该走到这一步,否则就是错误!!!
  778. }
  779. copyItem.rationItemQuantity = rationGljItem.rationItemQuantity;
  780. // copyItem.quantity = rationGljItem.quantity;
  781. copyItem.quantity = rationGljItem.quantity * mapItem.consumption;
  782. copyItem.name = mapItem.name;
  783. copyItem.code = mapItem.code;
  784. copyItem.original_code = mapItem.code;
  785. copyItem.unit = mapItem.unit;
  786. copyItem.specs = mapItem.specs;
  787. copyItem.model = gljAssistant.gljIds['gljId_'+rationGljItem.projectGLJID].model;
  788. copyItem.shortName = mapItem.shortName;
  789. copyItem.billsItemID = rationGljItem.billsItemID;
  790. copyItem.type = mapItem.type; //关键key
  791. }
  792. }
  793. }
  794. }
  795. if (rvRGljIds.length > 0) {
  796. for (let lIdx = rvRGljIds.length - 1; lIdx >= 0; lIdx--) {
  797. dataArr.splice(rvRGljIds[lIdx],1);
  798. }
  799. for (let componentItems of replaceGljItems) {
  800. for (let compItem of componentItems) {
  801. dataArr.push(compItem);
  802. //gljAssistant[COMPONENT_GLJID_PRE + mapItem.glj_id]
  803. }
  804. }
  805. }
  806. }
  807. function moveRationData(rationData, rawDataObj) {
  808. if (rawDataObj) {
  809. // let rationData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION);
  810. let rationGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION_GLJ);
  811. let prjGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.PROJECTGLJ);
  812. let dummyCode = " ", dummyPRJID = 10101010;
  813. for (let rationItem of getActDataArr(rationData)) {
  814. if (rationItem.type === 2 || rationItem.type === 3) {
  815. //2: 量材(人工/材料/机械/主材/设备) 3:材料(材料/主材/设备)
  816. let copyItem = {};
  817. copyItem.ID = rationItem.ID;
  818. copyItem.projectID = rationItem.projectID;
  819. copyItem.GLJID = rationItem.GLJID;
  820. copyItem.rationID = rationItem.ID;
  821. copyItem.rationItemQuantity = 1;
  822. copyItem.quantity = 1;
  823. // copyItem.specialType_quantity = rationItem.quantity;
  824. copyItem.name = rationItem.name;
  825. if (rationItem.code) {
  826. copyItem.code = rationItem.ID + "_" + rationItem.code;
  827. } else {
  828. copyItem.code = dummyCode;
  829. dummyCode = dummyCode + " ";
  830. }
  831. copyItem.original_code = rationItem.original_code;
  832. copyItem.unit = rationItem.unit;
  833. copyItem.specs = rationItem.specs;
  834. copyItem.shortName = rationItem.shortName;
  835. copyItem.billsItemID = rationItem.billsItemID;
  836. copyItem.type = rationItem.subType;
  837. if (rationItem.projectGLJID) {
  838. copyItem.projectGLJID = rationItem.projectGLJID;
  839. } else {
  840. //add dummy project GLJ
  841. let dummyPrjItem = {};
  842. copyItem.projectGLJID = dummyPRJID;
  843. dummyPrjItem.id = dummyPRJID;
  844. dummyPRJID++;
  845. dummyPrjItem.name = rationItem.name;
  846. dummyPrjItem.unit_price = {};
  847. dummyPrjItem.unit_price.base_price = 0;
  848. dummyPrjItem.unit_price.market_price = (rationItem["marketUnitFee"])?rationItem["marketUnitFee"]:0;
  849. dummyPrjItem.quantity = 1; //这里设置为1只是为了不被误过滤
  850. dummyPrjItem.is_evaluate = 0;
  851. prjGljData.data.gljList.push(dummyPrjItem);
  852. }
  853. rationGljData.data.push(copyItem);
  854. } else {
  855. //无
  856. }
  857. }
  858. // fsUtil.writeObjToFile(rationGljData.data, "D:/GitHome/ConstructionCost/tmp/afterMoveGLJ.jsp");
  859. }
  860. }
  861. //有些项目工料机有组成物,有些表需要显示这些组成物,此函数把这些组成物抽出并归类到定额工料机下
  862. function moveRationComponentData(rationData, rawDataObj) {
  863. let rationGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.RATION_GLJ);
  864. let prjGljData = getModuleDataByKey(rawDataObj.prjData, projectConst.PROJECTGLJ);
  865. let newComponentItem = [];
  866. for (let rationGljItem of getActDataArr(rationGljData)) {
  867. for (let prjGljItem of prjGljData.data.gljList) {
  868. if (prjGljItem.id === rationGljItem.projectGLJID) {
  869. if (prjGljItem.ratio_data && prjGljItem.ratio_data.length > 0 && !gljUtil.isConcreteType(prjGljItem.type)) {
  870. //有组成物
  871. for (let comItem of prjGljItem.ratio_data) {
  872. let copyItem = {};
  873. copyItem.ID = comItem._id.toString();
  874. copyItem.projectID = rationGljItem.projectID;
  875. copyItem.rationID = rationGljItem.rationID;
  876. // copyItem.rationItemQuantity = rationGljItem.quantity;
  877. copyItem.quantity = parseFloat(rationGljItem.quantity) * parseFloat(comItem.consumption);
  878. copyItem.name = comItem.name;
  879. copyItem.code = comItem.code;
  880. copyItem.unit = comItem.unit;
  881. copyItem.specs = comItem.specs;
  882. // copyItem.shortName = comItem.shortName;
  883. copyItem.billsItemID = rationGljItem.billsItemID;
  884. copyItem.type = comItem.type;
  885. //其他属性,要根据工料机ID来查找
  886. for (let gljIdx = 0; gljIdx < prjGljData.data.gljList.length; gljIdx++) {
  887. if (prjGljData.data.gljList[gljIdx].code === comItem.code) {
  888. copyItem.projectGLJID = prjGljData.data.gljList[gljIdx].id;
  889. copyItem.original_code = prjGljData.data.gljList[gljIdx].original_code;
  890. copyItem.is_main_material = prjGljData.data.gljList[gljIdx].is_main_material;
  891. copyItem.is_adjust_price = prjGljData.data.gljList[gljIdx].is_adjust_price;
  892. copyItem.unit_price = {};
  893. copyItem.unit_price.base_price = prjGljData.data.gljList[gljIdx].unit_price.base_price;
  894. copyItem.unit_price.market_price = prjGljData.data.gljList[gljIdx].unit_price.market_price;
  895. break;
  896. }
  897. }
  898. newComponentItem.push(copyItem);
  899. }
  900. }
  901. break;
  902. }
  903. }
  904. }
  905. rationGljData.data = rationGljData.data.concat(newComponentItem);
  906. }
  907. function getDupGrpKeyVals(sourceData, segKeys) {
  908. let rst = [];
  909. function pushKeyVal(item) {
  910. let tr = {};
  911. for (let i = 0; i < segKeys.length; i++) {
  912. tr[segKeys[i]] = item[segKeys[i]];
  913. }
  914. rst.push(tr);
  915. }
  916. for (let idx = 0; idx < sourceData.length; idx++) {
  917. let itemRec = sourceData[idx];
  918. if (idx === 0) {
  919. pushKeyVal(itemRec);
  920. continue;
  921. }
  922. let hasDiff = false;
  923. for (let i = 0; i < segKeys.length; i++) {
  924. if (itemRec[segKeys[i]] !== sourceData[idx - 1][segKeys[i]]) {
  925. hasDiff = true;
  926. break;
  927. }
  928. }
  929. if (hasDiff) {
  930. pushKeyVal(itemRec);
  931. }
  932. }
  933. return rst;
  934. }
  935. function addDummyData(sourceData, addCfg) {
  936. let rstArr = [], tempRstArr = [];
  937. for (let item of getActDataArr(sourceData)) {
  938. if (item._doc) {
  939. tempRstArr.push(item._doc);
  940. } else {
  941. tempRstArr.push(item);
  942. }
  943. }
  944. for (let item of addCfg[JV.PROP_DUMMY_COLLECTION]) {
  945. let newRecStr = JSON.stringify(item[JV.PROP_DUMMY_VAL]), cacheGrpKeyRecs = null;
  946. if (item[JV.PROP_FREQUENCY] === "OncePerGrp") {
  947. if (!cacheGrpKeyRecs) {
  948. cacheGrpKeyRecs = {};
  949. }
  950. let cacheKey = "";
  951. for (let key of item[JV.PROP_GRP_KEYS]) {
  952. cacheKey += "_" + key;
  953. }
  954. if (!cacheGrpKeyRecs[cacheKey]) {
  955. cacheGrpKeyRecs[cacheKey] = getDupGrpKeyVals(tempRstArr, item[JV.PROP_GRP_KEYS]);
  956. }
  957. for (let kv of cacheGrpKeyRecs[cacheKey]) {
  958. let rec = JSON.parse(newRecStr);
  959. for (let key of item[JV.PROP_GRP_KEYS]) {
  960. rec[key] = kv[key];
  961. }
  962. rstArr.push(rec);
  963. }
  964. } else if (item[JV.PROP_FREQUENCY] === "Once") {
  965. rstArr.push(JSON.parse(newRecStr));
  966. }
  967. }
  968. rstArr = rstArr.concat(tempRstArr);
  969. replaceActDataArr(sourceData, rstArr);
  970. }
  971. function getGLJBizType2018(orgType, orgCode, orgName) {
  972. let rst = orgType;
  973. if (orgType === GLJ_TYPE.Labour) {
  974. rst = 11;
  975. if (orgCode === "000000") rst = 10;
  976. } else if (orgType === GLJ_TYPE.Material || (orgType >= 200 && orgType < 300)) {
  977. //材料
  978. if (orgCode === "000000") {
  979. rst = 200; //2.材料
  980. } else if (orgCode === "000000_1") {
  981. rst = 230; //(1) 计价材料
  982. } else if (orgCode === "000000_2") {
  983. rst = 240; //(2) 其他材料费
  984. } else {
  985. if (orgType === GLJ_TYPE.OTHER_MATERIAL) {
  986. //其他材料
  987. rst = 245;
  988. } else {
  989. //计价材料
  990. rst = 235;
  991. }
  992. }
  993. } else if (orgType === GLJ_TYPE.Machine || (orgType >= 300 && orgType < 400)) {
  994. //机械
  995. if (orgCode === "000000") {
  996. rst = 300; //3.机械
  997. } else if (orgCode === "000000_1") {
  998. rst = 330; //(1) 机上人工
  999. } else if (orgCode === "000000_2") {
  1000. rst = 340; //(2) 燃油动力费
  1001. } else if (orgCode === "000000_3") {
  1002. rst = 350; //(2) 施工机具摊销费
  1003. } else {
  1004. if (orgType === GLJ_TYPE.MACHINE_LABOUR) {
  1005. //机上人工
  1006. rst = 335;
  1007. } else if (orgType === GLJ_TYPE.FUEL_POWER_FEE) {
  1008. //燃油动力费
  1009. rst = 345;
  1010. } else if (oprMachines.indexOf(orgType) >= 0) {
  1011. //施工机具摊销费
  1012. rst = 355 + oprMachines.indexOf(orgType);
  1013. }
  1014. }
  1015. }
  1016. return rst;
  1017. }
  1018. function getGLJBizType(orgType, orgCode, orgName) {
  1019. let rst = orgType;
  1020. if (orgName.indexOf("其他材料费") >= 0) {
  1021. rst = 299;
  1022. } else if (orgType === GLJ_TYPE.Labour) {
  1023. rst = 11;
  1024. if (orgCode === "000000") rst = 10;
  1025. } else if (orgType === GLJ_TYPE.Main_Material || orgType === GLJ_TYPE.Equipment) {
  1026. //未计价材料(主材 + 设备)
  1027. rst = 30 + orgType;
  1028. } else if (orgType === GLJ_TYPE.Material || (orgType >= 200 && orgType < 300)) {
  1029. //材料
  1030. if (orgCode === "000000") {
  1031. rst = 20; //2.材料
  1032. } else if (orgCode === "000000_1") {
  1033. rst = 30; //(1) 未计价材料
  1034. } else if (orgCode === "000000_2") {
  1035. rst = 40; //(2) 辅助材料
  1036. } else if (orgCode === "000000_3") {
  1037. rst = 50; //(3) 其他材料费
  1038. } else {
  1039. rst = 45; //到这里就只有辅助材料没有预处理了
  1040. }
  1041. } else if (orgType === GLJ_TYPE.Machine || (orgType >= 300 && orgType < 400)) {
  1042. //机械
  1043. if (orgCode === "000000") {
  1044. rst = 300; //3.机械
  1045. } else if (orgType === GLJ_TYPE.Machine) {
  1046. rst = 300.5;
  1047. } else {
  1048. rst = orgType;
  1049. }
  1050. }
  1051. return rst;
  1052. }
  1053. function sortData(sourceData, sortCfg, prjData) {
  1054. let rst = getActDataArr(sourceData), tempRstArr = [];
  1055. let sortType = sortCfg[JV.PROP_SORT_TYPE];
  1056. let srcData = getActDataArr(sourceData);
  1057. for (let item of srcData) {
  1058. if (item._doc) {
  1059. tempRstArr.push(item._doc);
  1060. } else {
  1061. tempRstArr.push(item);
  1062. }
  1063. }
  1064. function private_normal_sort(destArr, sortKeys) {
  1065. destArr.sort(function(a, b){
  1066. let compRst = 0;
  1067. for (let comp of sortKeys) {
  1068. let reverse = (comp.order === 'ascend')?1:(-1);
  1069. //
  1070. if (a[comp.key] > b[comp.key]) {
  1071. compRst = reverse;
  1072. break;
  1073. } else if (a[comp.key] < b[comp.key]) {
  1074. compRst = -reverse;
  1075. break;
  1076. }
  1077. }
  1078. return compRst;
  1079. });
  1080. }
  1081. function private_parent_sort(parentArr, parentKeys, childArr, childKeys) {
  1082. let tmpRst = {}, rst = [];
  1083. for (let pItem of parentArr) {
  1084. let pKey = "key";
  1085. for (let key of parentKeys) {
  1086. pKey += "_" + pItem[key];
  1087. }
  1088. tmpRst[pKey] = [];
  1089. }
  1090. for (let cItem of childArr) {
  1091. let cKey = "key";
  1092. for (let key of childKeys) {
  1093. cKey += "_" + cItem[key];
  1094. }
  1095. if (tmpRst[cKey]) {
  1096. tmpRst[cKey].push(cItem);
  1097. } else {
  1098. //unknown child value! should be filtered!
  1099. }
  1100. }
  1101. // childArr.splice(0);
  1102. for (let pItem of parentArr) {
  1103. let pKey = "key";
  1104. for (let key of parentKeys) {
  1105. pKey += "_" + pItem[key];
  1106. }
  1107. rst.push(tmpRst[pKey]);
  1108. // for (let rItem of tmpRst[pKey]) {
  1109. // childArr.push(rItem);
  1110. // }
  1111. }
  1112. return rst;
  1113. }
  1114. switch (sortType) {
  1115. case "tree":
  1116. let addLevel = true;
  1117. rst = treeUtil.buildTreeNodeDirectly(tempRstArr, addLevel);
  1118. let newTopArr = [];
  1119. if ((sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES] && sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].length > 0) ||
  1120. (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0)) {
  1121. let local_check_bills = function(tItem) {
  1122. let chkDtl = false;
  1123. if (tItem.flags && tItem.flags.length > 0) {
  1124. for (let flagItem of tItem.flags) {
  1125. if (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  1126. newTopArr.push(tItem);
  1127. chkDtl = true;
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. if (!chkDtl && tItem.items && tItem.items.length > 0) {
  1133. for (let dtlItem of tItem.items) {
  1134. local_check_bills(dtlItem);
  1135. }
  1136. }
  1137. };
  1138. for (let topItem of rst) {
  1139. let chkTop = false;
  1140. if (topItem.flags && topItem.flags.length > 0) {
  1141. for (let flagItem of topItem.flags) {
  1142. if (sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
  1143. newTopArr.push(topItem);
  1144. chkTop = true;
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. if (!chkTop && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0) {
  1150. local_check_bills(topItem);
  1151. }
  1152. }
  1153. } else {
  1154. newTopArr = rst;
  1155. }
  1156. let destArr = [];
  1157. // fsUtil.writeObjToFile(newTopArr, "D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRstBefore.jsp");
  1158. treeUtil.getFlatArray(newTopArr, destArr, true);
  1159. // console.log(destArr);
  1160. replaceActDataArr(sourceData, destArr);
  1161. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRst.jsp");
  1162. break;
  1163. case "normal":
  1164. private_normal_sort(tempRstArr, sortCfg[JV.PROP_SORT_KEYS]);
  1165. replaceActDataArr(sourceData, tempRstArr);
  1166. // fsUtil.writeObjToFile(sourceData.data, "D:/GitHome/ConstructionCost/tmp/normalSortedRst.jsp");
  1167. break;
  1168. case "accord_to_parent":
  1169. let pcKey = sortCfg[JV.PROP_PARENT_CHILD_SORT_KEY];
  1170. let parentSrcData = getModuleDataByKey(prjData, pcKey[JV.PROP_PARENT_DATA_KEY]);
  1171. if (parentSrcData) {
  1172. let tempParentArr = [];
  1173. for (let item of getActDataArr(parentSrcData)) {
  1174. if (item._doc) {
  1175. tempParentArr.push(item._doc);
  1176. } else {
  1177. tempParentArr.push(item);
  1178. }
  1179. }
  1180. let sortedRstArr = private_parent_sort(tempParentArr, pcKey[JV.PROP_PARENT_SORT_KEYS], tempRstArr, pcKey[JV.PROP_CHILD_SORT_KEYS]);
  1181. if (sortCfg[JV.PROP_OTHER_SUB_SORT] && sortCfg[JV.PROP_OTHER_SUB_SORT].length > 0) {
  1182. for (let sort of sortCfg[JV.PROP_OTHER_SUB_SORT]) {
  1183. if (sort[JV.PROP_SORT_TYPE] === 'normal') {
  1184. for (let subArr of sortedRstArr) {
  1185. private_normal_sort(subArr, sort[JV.PROP_SORT_KEYS]);
  1186. }
  1187. } else if (sort[JV.PROP_SORT_TYPE] === 'self_define') {
  1188. for (let subArr of sortedRstArr) {
  1189. // console.log(subArr);
  1190. let selfDefFunc = null;
  1191. eval('selfDefFunc = ' + sort[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  1192. subArr.sort(selfDefFunc);
  1193. // console.log(subArr);
  1194. }
  1195. }
  1196. }
  1197. }
  1198. tempRstArr.splice(0);
  1199. for (let item of sortedRstArr) {
  1200. for (let subItem of item) {
  1201. tempRstArr.push(subItem);
  1202. }
  1203. }
  1204. }
  1205. replaceActDataArr(sourceData, tempRstArr);
  1206. break;
  1207. case "self_define":
  1208. if (sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]) {
  1209. let selfDefFuncA = null;
  1210. eval('selfDefFuncA = ' + sortCfg[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
  1211. if (selfDefFuncA !== null) {
  1212. tempRstArr.sort(selfDefFuncA);
  1213. } else {
  1214. console.log('sorting function is null!!!');
  1215. }
  1216. }
  1217. replaceActDataArr(sourceData, tempRstArr);
  1218. break;
  1219. default:
  1220. //
  1221. }
  1222. return rst;
  1223. }
  1224. function setupMainFunc(obj, prop, ownRawObj) {
  1225. obj[prop] = {};
  1226. obj[prop]["myOwnRawDataObj"] = ownRawObj;
  1227. obj[prop].getProperty = ext_mainGetPropety;
  1228. obj[prop].getFee = ext_mainGetFee;
  1229. }
  1230. function setupFeeRate(feeRateData){
  1231. let cacheObj = {}, topArr = [], rstArr = [], id_pre = 'ID_';
  1232. const rateProperties = [];
  1233. for (let rate of feeRateData.rates) {
  1234. cacheObj[id_pre + rate._doc.ID] = {"obj": rate._doc, "items": []};
  1235. // cacheObj[id_pre + rate.ID].items = [];
  1236. if (rate._doc.ParentID === null || rate._doc.ParentID === undefined) {
  1237. topArr.push(cacheObj[id_pre + rate._doc.ID]);
  1238. }
  1239. }
  1240. for (let rate of feeRateData.rates) {
  1241. if (rate._doc.ParentID && cacheObj[id_pre + rate._doc.ParentID]) {
  1242. cacheObj[id_pre + rate._doc.ParentID].items.push(cacheObj[id_pre + rate._doc.ID]);
  1243. if (rateProperties.indexOf(rate._doc.name) < 0) {
  1244. rateProperties.push(rate._doc.name);
  1245. }
  1246. }
  1247. }
  1248. let pri_func_set_property_rate = function (orgRateItem, rstRateItem) {
  1249. rstRateItem[orgRateItem.obj.name] = orgRateItem.obj.rate;
  1250. for (let subOrgRateItem of orgRateItem.items) {
  1251. pri_func_set_property_rate(subOrgRateItem, rstRateItem);
  1252. }
  1253. };
  1254. for (let topRate of topArr) {
  1255. let rstItem = {"name": topRate.obj.name, "ID": topRate.obj.ID};
  1256. for (let property of rateProperties) {
  1257. rstItem[property] = 0;
  1258. }
  1259. for (let dtlRateItem of topRate.items) {
  1260. pri_func_set_property_rate(dtlRateItem, rstItem);
  1261. }
  1262. rstArr.push(rstItem);
  1263. }
  1264. return rstArr;
  1265. }
  1266. function setupFunc(obj, prop, ownRawObj) {
  1267. obj[prop] = {};
  1268. obj[prop]["myOwnRawDataObj"] = ownRawObj;
  1269. obj[prop]["myOwnOrgRawDataObj"] = ownRawObj.data;
  1270. obj[prop].getProperty = ext_getProperty;
  1271. obj[prop].getGljFreightProperty = ext_getGljFreightProperty;
  1272. obj[prop].getPropertyByRefId = ext_getPropertyByRefId;
  1273. obj[prop].getFee = ext_getFee;
  1274. obj[prop].getPropertyByForeignId = ext_getPropertyByForeignId;
  1275. obj[prop].getArrayValues = ext_getArrayValues;
  1276. obj[prop].getArrayItemByKey = ext_getArrayItemByKey;
  1277. obj[prop].getPropertyByFlag = ext_getPropertyByFlag;
  1278. obj[prop].getSubRateProperty = ext_getRateProperty;
  1279. obj[prop].getRateProperty = ext_getRateProperty;
  1280. obj[prop].getBlank = ext_getBlank;
  1281. obj[prop].getRatioDataProperty = ext_getRatioDataProperty;
  1282. obj[prop].getRatioDataParentProperty = ext_getRatioDataParentProperty;
  1283. obj[prop].getRatioDataPriceMapProperty = ext_getRatioDataPriceMapProperty;
  1284. if (prop === projectConst.CALC_PROGRAM) obj[prop].getCalcProperty = ext_getCalcProperty;
  1285. if (prop === projectConst.FEERATE) obj[prop].getFeeRate = ext_getFeeRate;
  1286. }
  1287. function assembleFields(fieldList, rstDataArr, $PROJECT) {
  1288. if (fieldList) {
  1289. for (let field of fieldList) {
  1290. shielded_exec_env($PROJECT, field, rstDataArr);
  1291. if ("Precision" in field) {
  1292. if (field["Precision"]["type"] === "fixed") {
  1293. let vrst = eval(field["Precision"]["fixedMapExpression"]);
  1294. if (vrst && vrst.length === 1) {
  1295. field.fixedPrecisionNum = vrst[0];
  1296. vrst.splice(0,1);
  1297. }
  1298. } else if (field["Precision"]["type"] === "flexible") {
  1299. let vrst = eval(field["Precision"]["flexibleMapExpression"]);
  1300. if (vrst && vrst.length === 1) {
  1301. field.flexiblePrecisionRefObj =vrst[0];
  1302. vrst.splice(0,1);
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. function shielded_exec_env($PROJECT, $ME, rptDataItemObj) {
  1310. if ($ME[JV.PROP_FIELD_EXP_MAP]) {
  1311. rptDataItemObj.push(eval($ME[JV.PROP_FIELD_EXP_MAP]));
  1312. }
  1313. }
  1314. function getActPropertyVal(firstPropKey, secPropKey, orgObj) {
  1315. let rst = null;
  1316. if (orgObj[firstPropKey]) {
  1317. rst = orgObj[firstPropKey];
  1318. } else if (orgObj[secPropKey]){
  1319. rst = orgObj[secPropKey];
  1320. }
  1321. return rst;
  1322. }
  1323. function getDeepProperty(propKey, orgObj, destArr) {
  1324. let keys = propKey.split(".");
  1325. let dftPropKey = "key", dftPropVal = "value", secDftPropVal = "items";
  1326. let parent = orgObj, lastVal = null;
  1327. for (let key of keys) {
  1328. if (parent instanceof Array) {
  1329. for (let item of parent) {
  1330. if (item[dftPropKey] === key) {
  1331. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  1332. break;
  1333. }
  1334. }
  1335. } else {
  1336. lastVal = null;
  1337. if (parent[key] !== undefined) {
  1338. lastVal = parent[key];
  1339. } else if (parent[secDftPropVal]){
  1340. for (let item of parent[secDftPropVal]) {
  1341. if (item[dftPropKey] === key) {
  1342. // lastVal = item[dftPropVal];
  1343. lastVal = getActPropertyVal(dftPropVal, secDftPropVal, item);
  1344. break;
  1345. }
  1346. }
  1347. }
  1348. }
  1349. parent = lastVal;
  1350. if (parent === null) break;
  1351. }
  1352. if (destArr && destArr instanceof Array) {
  1353. destArr.push(lastVal);
  1354. }
  1355. }
  1356. function ext_mainGetPropety(propKey) {
  1357. let rst = [], parentObj = this;
  1358. let dtObj = parentObj["myOwnRawDataObj"];
  1359. if (propKey && dtObj) {
  1360. if (dtObj.hasOwnProperty("property")) {
  1361. if (!dtObj["property"][propKey] && dtObj[propKey]) {
  1362. rst.push(dtObj[propKey]);
  1363. } else {
  1364. getDeepProperty(propKey, dtObj["property"], rst);
  1365. }
  1366. } else {
  1367. // rst.push(dtObj[propKey]);
  1368. getDeepProperty(propKey, dtObj, rst);
  1369. }
  1370. }
  1371. return rst;
  1372. }
  1373. function ext_getRateProperty(propKey) {
  1374. let rst = [], parentObj = this;
  1375. let dtObj = parentObj["myOwnRawDataObj"];
  1376. if (propKey && dtObj) {
  1377. for (let rate of dtObj.data._doc.rates) {
  1378. rst.push(rate[propKey]);
  1379. }
  1380. }
  1381. return rst;
  1382. }
  1383. function ext_getRatioDataProperty(propKey) {
  1384. //获取工料机的组成物属性
  1385. let rst = [], parentObj = this;
  1386. let dtObj = parentObj["myOwnRawDataObj"];
  1387. if (propKey && dtObj) {
  1388. for (let dItem of getActDataArr(dtObj)) {
  1389. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1390. for (let ratioItem of doc.ratio_data) {
  1391. rst.push(ratioItem[propKey]);
  1392. }
  1393. }
  1394. }
  1395. return rst;
  1396. }
  1397. function pri_push_property(propKey, doc, rst) {
  1398. if (propKey instanceof Array) {
  1399. //备注:这里的key数组表示取value的优先级
  1400. for (let pi = 0; pi < propKey.length; pi++) {
  1401. if (doc.hasOwnProperty("property")) {
  1402. if (doc["property"].hasOwnProperty(propKey[pi])) {
  1403. rst.push(doc["property"][propKey[pi]]);
  1404. break;
  1405. }
  1406. } else if (doc.hasOwnProperty(propKey[pi])) {
  1407. rst.push(doc[propKey[pi]]);
  1408. break;
  1409. } else {
  1410. let lenBefore = rst.length;
  1411. getDeepProperty(propKey[pi], doc, rst);
  1412. if (rst.length === (lenBefore + 1)) {
  1413. if (rst[lenBefore] !== null && rst[lenBefore] !== undefined && rst[lenBefore] !== "") {
  1414. break;
  1415. } else {
  1416. rst.splice(-1, 1); //删除末尾一条数据,给后面留空间
  1417. }
  1418. }
  1419. }
  1420. if (pi === propKey.length - 1) rst.push('');
  1421. }
  1422. } else {
  1423. if (doc.hasOwnProperty("property") && doc["property"].hasOwnProperty(propKey)) {
  1424. rst.push(doc["property"][propKey]);
  1425. } else if (doc.hasOwnProperty(propKey)) {
  1426. rst.push(doc[propKey]);
  1427. } else {
  1428. getDeepProperty(propKey, doc, rst);
  1429. }
  1430. }
  1431. }
  1432. function ext_getRatioDataParentProperty(propKey) {
  1433. //获取组成物的父项属性
  1434. let rst = [], parentObj = this;
  1435. let dtObj = parentObj["myOwnRawDataObj"];
  1436. if (propKey && dtObj) {
  1437. for (let dItem of getActDataArr(dtObj)) {
  1438. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1439. for (let ratioItem of doc.ratio_data) {
  1440. pri_push_property(propKey, doc, rst);
  1441. }
  1442. }
  1443. }
  1444. return rst;
  1445. }
  1446. function ext_getRatioDataPriceMapProperty(propKey) {
  1447. //获取组成物的单价映射属性
  1448. let rst = [], parentObj = this;
  1449. let dtObj = parentObj["myOwnRawDataObj"];
  1450. if (propKey && dtObj) {
  1451. let unitPriceMap = dtObj.data.unitPriceMap;
  1452. let upmDoc = (unitPriceMap._doc === null || unitPriceMap._doc === undefined)?unitPriceMap:unitPriceMap._doc;
  1453. for (let dItem of getActDataArr(dtObj)) {
  1454. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1455. for (let ratioItem of doc.ratio_data) {
  1456. let connectionKeys = [];
  1457. connectionKeys.push(ratioItem.code);
  1458. connectionKeys.push(ratioItem.name);
  1459. connectionKeys.push((ratioItem.specs === "")?"null":ratioItem.specs);
  1460. connectionKeys.push(ratioItem.unit);
  1461. connectionKeys.push(ratioItem.type);
  1462. connectionKeys.join("|-|");
  1463. let strPK = connectionKeys.join("|-|");
  1464. let dtlDoc = (upmDoc[strPK]._doc)?upmDoc[strPK]._doc:upmDoc[strPK];
  1465. rst.push(dtlDoc[propKey]);
  1466. }
  1467. }
  1468. }
  1469. return rst;
  1470. }
  1471. function ext_getAdHocGljProperty(adhocDataKey, propKey) {
  1472. let rst = [], parentObj = this;
  1473. let dtObj = parentObj["myOwnRawDataObj"];
  1474. if (propKey && dtObj) {
  1475. // for (let dItem of getActDataArr(dtObj)) {
  1476. // let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1477. // pri_push_property(propKey, doc, rst);
  1478. // }
  1479. }
  1480. return rst;
  1481. }
  1482. function ext_getGljFreightProperty(propKey) {
  1483. let rst = [], parentObj = this;
  1484. let dtObj = parentObj["myOwnRawDataObj"];
  1485. if (propKey && dtObj) {
  1486. for (let dItem of getActDataArr(dtObj, "freightList")) {
  1487. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1488. pri_push_property(propKey, doc, rst);
  1489. }
  1490. }
  1491. return rst;
  1492. }
  1493. function ext_getProperty(propKey) {
  1494. let rst = [], parentObj = this;
  1495. let dtObj = parentObj["myOwnRawDataObj"];
  1496. if (propKey && dtObj) {
  1497. for (let dItem of getActDataArr(dtObj)) {
  1498. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1499. pri_push_property(propKey, doc, rst);
  1500. }
  1501. }
  1502. return rst;
  1503. }
  1504. function ext_getPropertyByRefId(baseKey, refIDKey, propertyKey){
  1505. let rst = [], parentObj = this;
  1506. let dtObj = parentObj["myOwnRawDataObj"];
  1507. let orgDtObj = parentObj["myOwnOrgRawDataObj"];
  1508. if (baseKey && refIDKey && propertyKey && dtObj) {
  1509. for (let dItem of getActDataArr(dtObj)) {
  1510. let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
  1511. let tmpRst = doc[baseKey];
  1512. if (typeof tmpRst === "string" && tmpRst[0] === "@") {
  1513. let refKey = tmpRst.slice(1);
  1514. let hasGetRef = false;
  1515. for (let orgDItem of orgDtObj) {
  1516. let oDoc = (orgDItem._doc === null || orgDItem._doc === undefined)?orgDItem:orgDItem._doc;
  1517. if (oDoc[refIDKey] === refKey) {
  1518. rst.push(oDoc[propertyKey]);
  1519. hasGetRef = true;
  1520. break;
  1521. }
  1522. }
  1523. if (!hasGetRef) {
  1524. rst.push(tmpRst);
  1525. }
  1526. } else {
  1527. rst.push(tmpRst);
  1528. }
  1529. }
  1530. }
  1531. return rst;
  1532. }
  1533. function ext_mainGetFee(feeKey, dtlFeeKey) {
  1534. let rst = [];
  1535. let parentObj = this;
  1536. let dtObj = parentObj["myOwnRawDataObj"];
  1537. if ((dtObj) && (feeKey)) {
  1538. if (dtObj.hasOwnProperty("fees")) {
  1539. for (let fee of dtObj["fees"]) {
  1540. if (fee["fieldName"] === feeKey) {
  1541. if (dtlFeeKey) {
  1542. rst.push(fee[dtlFeeKey]);
  1543. } else {
  1544. rst.push(fee["unitFee"]);
  1545. }
  1546. break;
  1547. }
  1548. }
  1549. } else if (dtObj.hasOwnProperty(feeKey)) {
  1550. rst.push(dtObj[feeKey]);
  1551. } else {
  1552. //
  1553. }
  1554. }
  1555. return rst;
  1556. }
  1557. function ext_getFee(feeKey, dtlFeeKey) {
  1558. let rst = [], parentObj = this;
  1559. let dtObj = parentObj["myOwnRawDataObj"];
  1560. if (feeKey && dtObj) {
  1561. for (let dItem of getActDataArr(dtObj)) {
  1562. rst.push(pri_getFee(dItem, feeKey, dtlFeeKey));
  1563. }
  1564. }
  1565. for (let i = 0; i < rst.length; i++) {
  1566. rst[i] = parseFloat(rst[i]);
  1567. }
  1568. return rst;
  1569. }
  1570. function pri_getFee(dItem, feeKey, dtlFeeKey) {
  1571. let rst = 0;
  1572. let hasValue = false;
  1573. if (dItem["fees"]) {
  1574. for (let fee of dItem["fees"]) {
  1575. if (fee["fieldName"] === feeKey) {
  1576. if (dtlFeeKey) {
  1577. rst = fee[dtlFeeKey];
  1578. } else {
  1579. rst = fee["unitFee"];
  1580. }
  1581. hasValue = true;
  1582. break;
  1583. }
  1584. }
  1585. } else if (dItem[feeKey]) {
  1586. hasValue = true;
  1587. rst = parseFloat(dItem[feeKey]);
  1588. } else {
  1589. hasValue = true;
  1590. rst = 0;
  1591. }
  1592. if (!hasValue) {
  1593. rst = 0;
  1594. }
  1595. return rst;
  1596. }
  1597. function ext_getCalcProperty(templateIDs, calcItemKey, calcItemKeyVal, calcItemRstKey){
  1598. let rst = [], parentObj = this; //this should be "calc_program" object
  1599. let dtObj = parentObj["myOwnRawDataObj"];
  1600. let optimizeObj = {};
  1601. let private_getProperty = function (cId) {
  1602. let calcTplObj = optimizeObj["calc_program_" + cId];
  1603. if (!calcTplObj) {
  1604. let templates = (dtObj.data._doc)?dtObj.data._doc.templates:dtObj.data.templates;
  1605. for (let tpl of templates) {
  1606. if (cId === tpl.ID) {
  1607. optimizeObj["calc_program_" + cId] = tpl;
  1608. calcTplObj = tpl;
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. if (calcTplObj) {
  1614. for (let calcItem of calcTplObj.calcItems) {
  1615. if (calcItem[calcItemKey] === calcItemKeyVal) {
  1616. rst.push(calcItem[calcItemRstKey]);
  1617. break;
  1618. }
  1619. }
  1620. }
  1621. };
  1622. if (templateIDs instanceof Array) {
  1623. for (let tplId of templateIDs) {
  1624. private_getProperty(tplId);
  1625. }
  1626. } else {
  1627. private_getProperty(templateIDs);
  1628. }
  1629. optimizeObj = null;
  1630. return rst;
  1631. }
  1632. function ext_getFeeRate(fee_Ids, feeName){
  1633. let rst = [], parentObj = this; //this should be "feeRate" object
  1634. let dtObj = parentObj["myOwnRawDataObj"];
  1635. let optimizeObj = {};
  1636. let private_getFeeRate = function (fId) {
  1637. let feeRateItemObj = optimizeObj["fee_rates_" + fId];
  1638. if (!feeRateItemObj) {
  1639. let rates = (dtObj.data._doc)?dtObj.data._doc.rates:dtObj.data.rates;
  1640. for (let feeItem of rates) {
  1641. if (fId === feeItem.ID) {
  1642. optimizeObj["fee_rates_" + fId] = feeItem;
  1643. feeRateItemObj = feeItem;
  1644. break;
  1645. }
  1646. }
  1647. }
  1648. if (feeRateItemObj) {
  1649. //rst.push(feeRateItemObj.rate);
  1650. rst.push(feeRateItemObj[feeName]);
  1651. } else {
  1652. rst.push(0);
  1653. }
  1654. };
  1655. if (fee_Ids instanceof Array) {
  1656. for (let fId of fee_Ids) {
  1657. private_getFeeRate(fId);
  1658. }
  1659. } else {
  1660. private_getFeeRate(fee_Ids);
  1661. }
  1662. optimizeObj = null;
  1663. return rst;
  1664. }
  1665. function ext_getArrayValues(itemKey) {
  1666. let rst = [], parentObj = this;
  1667. let dtObj = parentObj["myOwnRawDataObj"];
  1668. let keysArr = itemKey.split(".");
  1669. for (let dataItem of getActDataArr(dtObj)) {
  1670. let itemArr = [];
  1671. if (keysArr.length <= 2) {
  1672. if (dataItem[keysArr[0]] instanceof Array) {
  1673. if (keysArr.length === 2) {
  1674. for (let item of dataItem[keysArr[0]]) {
  1675. itemArr.push(item[keysArr[1]]);
  1676. }
  1677. } else {
  1678. itemArr = itemArr.concat(dataItem[keysArr[0]]);
  1679. }
  1680. } else {
  1681. if (keysArr.length === 2) {
  1682. let subProperty = dataItem[keysArr[0]][keysArr[1]];
  1683. if (subProperty instanceof Array) {
  1684. itemArr = itemArr.concat(subProperty);
  1685. } else {
  1686. itemArr.push(subProperty);
  1687. }
  1688. } else {
  1689. itemArr.push(dataItem[keysArr[0]]);
  1690. }
  1691. }
  1692. }
  1693. rst.push(itemArr);
  1694. }
  1695. return rst;
  1696. }
  1697. function ext_getArrayItemByKey(arrayKey, itemKey, itemKeyValue, itemRstKey){
  1698. let rst = [], parentObj = this;
  1699. let dtObj = parentObj["myOwnRawDataObj"];
  1700. let private_getItemValue = function (arr, dtlItKV) {
  1701. for (let item of arr) {
  1702. if (item[itemKey] === dtlItKV) {
  1703. if (itemRstKey) {
  1704. rst.push(item[itemRstKey]);
  1705. } else {
  1706. rst.push(item);
  1707. }
  1708. break;
  1709. }
  1710. }
  1711. };
  1712. let arr = dtObj[arrayKey];
  1713. if (arr && arr instanceof Array) {
  1714. if (itemKeyValue instanceof Array) {
  1715. for (let dtlItemKeyVal of itemKeyValue) {
  1716. private_getItemValue(arr, dtlItemKeyVal);
  1717. }
  1718. } else {
  1719. private_getItemValue(arr, itemKeyValue);
  1720. }
  1721. }
  1722. }
  1723. function ext_getBlank(dftVal) {
  1724. let rst = [], parentObj = this;
  1725. let dtObj = parentObj["myOwnRawDataObj"];
  1726. if (dtObj) {
  1727. let dtData = getActDataArr(dtObj);
  1728. for (let i = 0; i < dtData.length; i++) {
  1729. if (dftVal !== null && dftVal !== undefined) {
  1730. rst.push(dftVal)
  1731. } else rst.push('');
  1732. }
  1733. }
  1734. return rst;
  1735. }
  1736. function ext_getPropertyByFlag(flagVal, rstKey, dftValIfEmpty) {
  1737. let rst = [], parentObj = this;
  1738. let dtObj = parentObj["myOwnRawDataObj"];
  1739. if (flagVal && rstKey && dtObj) {
  1740. let isArr = (flagVal instanceof Array);
  1741. for (let dItem of getActDataArr(dtObj)) {
  1742. let doc = (dItem._doc)?dItem._doc:dItem;
  1743. if (doc.hasOwnProperty("flags")) {
  1744. let bFlag = false;
  1745. for (let flagItem of doc.flags) {
  1746. if (isArr) {
  1747. bFlag = (flagVal.indexOf(flagItem.flag) >= 0);
  1748. } else {
  1749. if (flagItem.flag === flagVal) {
  1750. bFlag = true;
  1751. }
  1752. }
  1753. if (bFlag) break;
  1754. }
  1755. if (bFlag) {
  1756. let keys = rstKey.split(".");
  1757. if (keys[0] === "fees") {
  1758. rst.push(pri_getFee(doc, "common", keys[1]));
  1759. } else {
  1760. //其他,比如名称什么
  1761. }
  1762. break;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. if (rst.length === 0 && dftValIfEmpty !== null) {
  1768. rst.push(dftValIfEmpty);
  1769. }
  1770. return rst;
  1771. }
  1772. function ext_getPropertyByForeignId(foreignIdVal, adHocIdKey, propKey, dftValIfNotFound) {
  1773. let rst = [], parentObj = this;
  1774. let IdKey = (adHocIdKey)?adHocIdKey:"ID";
  1775. let dtObj = parentObj["myOwnRawDataObj"];
  1776. let splitPKey = propKey.split(".");
  1777. if (foreignIdVal !== null && foreignIdVal !== undefined) {
  1778. let isFound = false;
  1779. if (foreignIdVal instanceof Array) {
  1780. for (let idVal of foreignIdVal) {
  1781. isFound = false;
  1782. let dataArr = getActDataArr(dtObj);
  1783. for (let i = 0; i < dataArr.length; i++) {
  1784. let item = (dataArr[i]._doc)?dataArr[i]._doc:dataArr[i];
  1785. if (item[IdKey] === idVal) {
  1786. if (splitPKey.length > 1) {
  1787. let rstP = null;
  1788. for (let i = 0; i < splitPKey.length; i++) {
  1789. if (i === 0) {
  1790. rstP = item[splitPKey[i]];
  1791. } else {
  1792. if (splitPKey[i].indexOf("[") === 0 && splitPKey[i].indexOf("]") === (splitPKey[i].length - 1)) {
  1793. //考虑数组情况^_^!!!
  1794. } else {
  1795. //
  1796. }
  1797. rstP = rstP[splitPKey[i]];
  1798. }
  1799. }
  1800. rst.push(rstP);
  1801. } else {
  1802. rst.push(item[propKey]);
  1803. }
  1804. isFound = true;
  1805. break;
  1806. }
  1807. }
  1808. if (!isFound) {
  1809. rst.push(dftValIfNotFound);
  1810. }
  1811. }
  1812. } else {
  1813. for (let item of getActDataArr(dtObj)) {
  1814. if (item[IdKey] === foreignIdVal) {
  1815. rst.push(item[propKey]);
  1816. isFound = true;
  1817. break;
  1818. }
  1819. }
  1820. if (!isFound) {
  1821. rst.push(dftValIfNotFound);
  1822. }
  1823. }
  1824. }
  1825. return rst;
  1826. }
  1827. function getActDataArr(dtObj, adhocKey) {
  1828. let rst = null;
  1829. if (dtObj) {
  1830. rst = dtObj.data;
  1831. if (dtObj.moduleName === "projectGLJ") {
  1832. if (adhocKey) {
  1833. rst = dtObj.data[adhocKey];
  1834. } else {
  1835. rst = dtObj.data.gljList;
  1836. }
  1837. }
  1838. if (dtObj.moduleName === "calc_program") {
  1839. rst = dtObj.data.templates;
  1840. }
  1841. }
  1842. return rst;
  1843. }
  1844. function replaceActDataArr(dtObj, newArr) {
  1845. if (dtObj.moduleName === "projectGLJ") {
  1846. delete dtObj.data.gljList;
  1847. dtObj.data.gljList = newArr;
  1848. } else {
  1849. delete dtObj.data;
  1850. dtObj.data = newArr;
  1851. }
  1852. }
  1853. export default Rpt_Data_Extractor;