rpt_yanghu_data_util.js 79 KB

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