rpt_yanghu_data_util.js 85 KB

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