rpt_construct_data_util.js 74 KB

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