rpt_yanghu_data_util.js 77 KB

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