rpt_yanghu_data_util.js 79 KB

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