rpt_construct_data_util.js 75 KB

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