rpt_construct_data_util.js 73 KB

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