rpt_construct_data_util.js 73 KB

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