rpt_construct_data_util.js 75 KB

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