rpt_yanghu_data_util.js 79 KB

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