rpt_construct_data_util.js 73 KB

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