shandong_common.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * @Descripttion: 山东导入接口(原始内容参考中山)
  3. * @Author: Tony
  4. * @Date: 2022-10-09
  5. */
  6. INTERFACE_IMPORT = (() => {
  7. 'use strict';
  8. /**
  9. *
  10. * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理
  11. * @param {Object} xmlObj - xml经过x2js转换后的xml对象
  12. * @return {Object} - 返回的格式需要统一,具体参考函数内返回的内容。返回的内容会经过一系列的统一处理形成可入库的数据。
  13. */
  14. const RoadGradeMap = {
  15. "0": "高速公路",
  16. "1": "一级公路",
  17. "2": "二级公路",
  18. "3": "三级公路",
  19. "4": "四级公路",
  20. "5": "等外公路",
  21. "6": "独立桥梁",
  22. "7":"独立隧道"
  23. }
  24. function formateDataString(dstring) {
  25. if (!dstring || dstring == "") return "";
  26. const strArr = dstring.split("T");
  27. return strArr[0]
  28. }
  29. async function entry(areaKey, xmlObj) {
  30. const {
  31. UTIL: {
  32. getValue,
  33. arrayValue,
  34. getBool,
  35. extractItemsRecur,
  36. }
  37. } = INTERFACE_EXPORT_BASE;
  38. let info = [];
  39. let tenders = [];
  40. let CprjInfo = getValue(xmlObj, ['CprjInfo']);
  41. let EprjInfos = arrayValue(CprjInfo, ["EprjInfo"]);
  42. if (EprjInfos.length > 0) {
  43. let MakeInfo = EprjInfos[0].MakeInfo;
  44. let Params = EprjInfos[0].Params;
  45. let BuildType = getValue(Params, ['_BuildType']);
  46. let natureConstruction = "";
  47. if (BuildType == "0") natureConstruction = "新建";
  48. if (BuildType == "1") natureConstruction = "改扩建";
  49. let terrainCategory = "";
  50. let Terrain = getValue(Params, ['_Terrain']);
  51. if (Terrain == "0") terrainCategory = "平原微丘";
  52. if (Terrain == "1") terrainCategory = "山岭重丘";
  53. let RoadGrade = getValue(Params, ['_RoadGrade']);
  54. let roadGrade = "";
  55. if (RoadGradeMap[RoadGrade]) roadGrade = RoadGradeMap[RoadGrade];
  56. info = [
  57. { key: 'constructingUnit', value: getValue(MakeInfo, ['_Manage']) },
  58. { key: 'designUnit', value: getValue(MakeInfo, ['_Designer']) },
  59. { key: 'compileUnit', value: getValue(MakeInfo, ['_Compile']) },
  60. { key: 'compileApprover', value: getValue(MakeInfo, ['_CompileApprover']) },
  61. { key: 'compileCertNo', value: getValue(MakeInfo, ['_CompileCertNo']) },
  62. { key: 'compileDate', value: formateDataString(getValue(MakeInfo, ['_CompileDate'])) },
  63. { key: 'reviewUnit', value: getValue(MakeInfo, ['_Review']) },
  64. { key: 'reviewApprover', value: getValue(MakeInfo, ['_ReviewApprover']) },
  65. { key: 'reviewCertNo', value: getValue(MakeInfo, ['_ReviewCertNo']) },
  66. { key: 'reviewDate', value: formateDataString(getValue(MakeInfo, ['_ReviewDate'])) },
  67. { key: 'startChainages', value: getValue(Params, ['_StartPileNo'])},
  68. { key: 'endChainages', value: getValue(Params, ['_EndPileNo']) },
  69. { key: 'location', value: getValue(Params, ['_PrjArea']) },
  70. { key: 'natureConstruction', value: natureConstruction },
  71. { key: 'terrainCategory', value: terrainCategory },
  72. { key: 'roadGrade', value: roadGrade },
  73. { key: 'makeDate', value: getValue(CprjInfo, ['SystemInfo','_MakeDate']) },
  74. ]
  75. for (let t of EprjInfos) {
  76. tenders.push(setupTender(t))
  77. }
  78. }
  79. function setupTender(EprjInfo) {
  80. let tender = {};
  81. let Params = EprjInfo.Params;
  82. let SummaryOfCost = EprjInfo.SummaryOfCost;
  83. tender.name = EprjInfo._Name;
  84. tender.bills = [];
  85. tender.bidEvaluationList = [];
  86. tender.evaluationList = [];
  87. let ProvisionalSums = getValue(SummaryOfCost, ['_ProvisionalSums']);
  88. let Structure = getValue(Params, ['_Structure']);
  89. let pavementStructure = "";
  90. if (Structure == "0") pavementStructure = "沥青路面";
  91. if (Structure == "1") pavementStructure = "水泥混凝土路面";
  92. if (Structure == "2") pavementStructure = "其他类型路面";
  93. tender.feature = [
  94. { key: 'tenderSumLimit', value: getValue(SummaryOfCost, ['_TenderSumLimit'])},//招标控制价
  95. { key: 'designSpeed', value: getValue(Params, ['_DesignSpeed']) },// --todo
  96. { key: 'pavementStructure', value: pavementStructure},// --todo
  97. { key: 'subgradeWidth', value: getValue(Params, ['_SubgradeWidth']) },
  98. { key: 'roadLength', value: getValue(Params, ['_RoadLength']) },// --todo
  99. { key: 'bridgeLength', value: getValue(Params, ['_BridgeLength']) },
  100. { key: 'tunnelLength', value: getValue(Params, ['_TunnelLength']) },// --todo
  101. { key: 'briTunRate', value: getValue(Params, ['_BriTunRate']) },// --todo
  102. { key: 'interchangeNum', value: getValue(Params, ['_InterchangeNum']) },// --todo
  103. { key: 'stubLengths', value: getValue(Params, ['_StubLengths']) },// --todo
  104. { key: 'laneLength', value: getValue(Params, ['_LaneLength']) },// --todo
  105. ]
  106. const items = arrayValue(EprjInfo, ['Items', 'Item']);
  107. for (let i of items) {
  108. let bill = setupBills(i);
  109. if (bill.name == "暂列金额(不含计日工总额)") {
  110. bill.fees = [{ fieldName: "common",tenderTotalFee:ProvisionalSums, tenderUnitFee: "0", totalFee: ProvisionalSums, unitFee: "0" }];
  111. if (bill.calcBase === undefined || bill.calcBase === null || bill.calcBase === '') {
  112. // 正常导入的暂列金额应该有公式(山东特有),没有公式再导ProvisionalSums
  113. bill.calcBase = ProvisionalSums;
  114. }
  115. bill.calcFlag = 1;
  116. }
  117. let formula = getValue(i, ['CostComposition', 'Formula', '_Formulas']);
  118. if (formula !== undefined && formula !== null && formula !== '') {
  119. bill.exCalcStr = formula; // 不仅仅'投标报价'有,其他的也要
  120. }
  121. // if (bill.name == '投标报价') {
  122. // bill.exCalcStr = formula || '';
  123. // }
  124. tender.bills.push(bill);
  125. }
  126. // 山东的 formula 还得调整
  127. // setupFormula(tender.bills);
  128. const BidEvaluationMainMaterial = arrayValue(EprjInfo, ['BidEvaluationMainMaterial']);
  129. for (let b of BidEvaluationMainMaterial) {
  130. tender.bidEvaluationList.push(setUpBidEvaluation(b))
  131. }
  132. return tender;
  133. }
  134. function handleBillPrice(bill, formula, totalFee, quantity) {
  135. if (formula) {
  136. bill.calcFlag = 1;
  137. bill.exCalcStr = formula;
  138. } else if (!formula && !quantity && totalFee) {
  139. // 没有基数、没有工程量时,有金额时,金额作为基数
  140. bill.exCalcStr = String(totalFee);
  141. bill.calcFlag = 1;
  142. } else {
  143. bill.calcFlag = 2;
  144. }
  145. }
  146. function setupBills(item, needClac = false) {
  147. const regBlank = new RegExp(' ', 'g');
  148. let bill = {
  149. code: item._ListCode,
  150. name: item._ListName,
  151. unit: item._Unit,
  152. quantity: item._Num,
  153. remark: item._Remarks,
  154. jobContentText: item._Content,
  155. specialProvisional: '',
  156. formulaCode: item._FormulaCode,
  157. qtyFormula: item._QtyFormula,
  158. children: []
  159. }
  160. const formula = getValue(item, ['CostComposition', 'Formula', '_Formulas']);
  161. // if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.qtyFormula && bill.qtyFormula !== '') {
  162. if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.hasOwnProperty('qtyFormula')) {
  163. let formula = getValue(item, ['CostComposition', 'Formula', '_Formulas']);
  164. let ratio = getValue(item, ['CostComposition', 'Formula', '_Ratio']);
  165. if (formula !== undefined && formula !== null && formula !== '') {
  166. bill.calcBase = formula; // 这个formula在后期还要处理的
  167. if (ratio && ratio !== '') {
  168. let dRation = parseFloat(ratio);
  169. if (!isNaN(dRation) && dRation != 1) {
  170. bill.calcBase = `(${formula}) * ${dRation}`; // 如果有费率且不等于1,还需要调整基数公式
  171. }
  172. }
  173. }
  174. }
  175. if (item._ProvisionalType == '0') bill.specialProvisional = '材料暂估';
  176. if (item._ProvisionalType == '1') bill.specialProvisional = '工程设备';
  177. if (item._ProvisionalType == '2') bill.specialProvisional = '专业工程';
  178. if (item._ProvisionalType == '3') bill.specialProvisional = '固定费用';
  179. if (item._ProvisionalType == '2') {
  180. let sumVal = getValue(item, ['_Sum']);
  181. bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: "0", totalFee: sumVal, unitFee: "0" }];
  182. // bill.calcBase = sumVal;
  183. // bill.calcFlag = 2;
  184. handleBillPrice(bill, formula, +sumVal, +bill.quantity);
  185. }
  186. if (item._ProvisionalType == '3') {
  187. let sumVal = getValue(item, ['_Sum']);
  188. let priceVal = getValue(item, ['_Price']);
  189. // if ((+sumVal) < (+priceVal)) sumVal = priceVal;
  190. bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: priceVal, totalFee: sumVal, unitFee: priceVal }];
  191. // bill.calcBase = sumVal;
  192. // bill.calcFlag = 2;
  193. handleBillPrice(bill, formula, +sumVal, +bill.quantity);
  194. }
  195. let subItems = arrayValue(item, ['Item']);
  196. if (subItems && subItems.length > 0) {
  197. for (let i of subItems) {
  198. if (typeof i._ListName === 'string' && i._ListName.replace(regBlank, '') === '清单第100章总则') {
  199. bill.children.push(setupBills(i, true));
  200. } else {
  201. bill.children.push(setupBills(i, needClac));
  202. }
  203. }
  204. }
  205. return bill;
  206. }
  207. function setUpBidEvaluation(b) {
  208. return {
  209. seq: b._Code,
  210. code: b._Number,
  211. name: b._Name,
  212. specs: b._Specification,
  213. unit: b._Unit,
  214. market_price: b._Price,
  215. quantity: b._Quantity,
  216. remark:b._Remark
  217. }
  218. }
  219. return {
  220. name: CprjInfo._CprjName,
  221. info,
  222. tenders,
  223. };
  224. }
  225. async function handleAfterImport(importData) {
  226. function setupFormula(bills) {
  227. const cacheObj = {};
  228. const calcBills = [];
  229. function _transform(calc) {
  230. let rst = calc, tmpCalc = calc;
  231. let calcKeys = [], calcValues = [];
  232. let preIdx = tmpCalc.indexOf('{');
  233. while (preIdx >= 0) {
  234. let rearIdx = tmpCalc.indexOf('}');
  235. if (rearIdx > preIdx) {
  236. let fnStr = tmpCalc.substring(preIdx + 1, rearIdx);
  237. if (cacheObj[fnStr]) {
  238. calcKeys.push(`{${fnStr}}`);
  239. calcValues.push(`@${cacheObj[fnStr].ID}`);
  240. }
  241. tmpCalc = tmpCalc.substr(rearIdx + 1);
  242. preIdx = tmpCalc.indexOf('{');
  243. } else {
  244. //有异常了
  245. break;
  246. }
  247. }
  248. if (calcKeys.length > 0) {
  249. calcKeys.forEach((key, index)=> {
  250. rst = rst.replace(key, calcValues[index]);
  251. });
  252. }
  253. return rst;
  254. }
  255. //1. 先把有formulaCode的清单cache起来
  256. //2. 顺带过滤出有calcBase的清单
  257. for (let bill of bills) {
  258. if (typeof bill.formulaCode === 'string' && bill.formulaCode.indexOf('F') === 0) {
  259. cacheObj[bill.formulaCode] = bill;
  260. }
  261. if (typeof bill.calcBase === 'string' && bill.calcBase.length > 0) {
  262. if (bill.exCalcStr) bill.calcBase = bill.exCalcStr;
  263. calcBills.push(bill);
  264. } else if (bill.exCalcStr) {
  265. bill.calcBase = bill.exCalcStr;
  266. calcBills.push(bill);
  267. }
  268. }
  269. //3. Action!
  270. for (let calcBill of calcBills) {
  271. calcBill.calcBase = _transform(calcBill.calcBase);
  272. }
  273. }
  274. importData.tenders.forEach((tender, index) => {
  275. setupFormula(tender.bills);
  276. });
  277. }
  278. return {
  279. entry,
  280. handleAfterImport,
  281. };
  282. })();