shandong_common.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. tender.bills.push(bill);
  118. }
  119. // 山东的 formula 还得调整
  120. // setupFormula(tender.bills);
  121. const BidEvaluationMainMaterial = arrayValue(EprjInfo, ['BidEvaluationMainMaterial']);
  122. for (let b of BidEvaluationMainMaterial) {
  123. tender.bidEvaluationList.push(setUpBidEvaluation(b))
  124. }
  125. return tender;
  126. }
  127. function setupBills(item, needClac = false) {
  128. const regBlank = new RegExp(' ', 'g');
  129. let bill = {
  130. code: item._ListCode,
  131. name: item._ListName,
  132. unit: item._Unit,
  133. quantity: item._Num,
  134. remark: item._Remarks,
  135. jobContentText: item._Content,
  136. specialProvisional: '',
  137. formulaCode: item._FormulaCode,
  138. qtyFormula: item._QtyFormula,
  139. children: []
  140. }
  141. // if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.qtyFormula && bill.qtyFormula !== '') {
  142. if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.qtyFormula) {
  143. let formula = getValue(item, ['CostComposition', 'Formula', '_Formulas']);
  144. let ratio = getValue(item, ['CostComposition', 'Formula', '_Ratio']);
  145. if (formula !== undefined && formula !== null && formula !== '') {
  146. bill.calcBase = formula; // 这个formula在后期还要处理的
  147. if (ratio && ratio !== '') {
  148. let dRation = parseFloat(ratio);
  149. if (!isNaN(dRation) && dRation != 1) {
  150. bill.calcBase = `(${formula}) * ${dRation}`; // 如果有费率且不等于1,还需要调整基数公式
  151. }
  152. }
  153. }
  154. }
  155. if (item._ProvisionalType == '0') bill.specialProvisional = '材料暂估';
  156. if (item._ProvisionalType == '1') bill.specialProvisional = '工程设备';
  157. if (item._ProvisionalType == '2') bill.specialProvisional = '专业工程';
  158. if (item._ProvisionalType == '3') bill.specialProvisional = '固定费用';
  159. if (item._ProvisionalType == '2') {
  160. let sumVal = getValue(item, ['_Sum']);
  161. bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: "0", totalFee: sumVal, unitFee: "0" }];
  162. bill.calcBase = sumVal;
  163. bill.calcFlag = 1;
  164. }
  165. if (item._ProvisionalType == '3') {
  166. let sumVal = getValue(item, ['_Sum']);
  167. let priceVal = getValue(item, ['_Price']);
  168. bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: priceVal, totalFee: sumVal, unitFee: priceVal }];
  169. bill.calcBase = sumVal;
  170. bill.calcFlag = 1;
  171. }
  172. let subItems = arrayValue(item, ['Item']);
  173. if (subItems && subItems.length > 0) {
  174. for (let i of subItems) {
  175. if (typeof i._ListName === 'string' && i._ListName.replace(regBlank, '') === '清单第100章总则') {
  176. bill.children.push(setupBills(i, true));
  177. } else {
  178. bill.children.push(setupBills(i, needClac));
  179. }
  180. }
  181. }
  182. return bill;
  183. }
  184. function setUpBidEvaluation(b) {
  185. return {
  186. seq: b._Code,
  187. code: b._Number,
  188. name: b._Name,
  189. specs: b._Specification,
  190. unit: b._Unit,
  191. market_price: b._Price,
  192. quantity: b._Quantity,
  193. remark:b._Remark
  194. }
  195. }
  196. return {
  197. name: CprjInfo._CprjName,
  198. info,
  199. tenders,
  200. };
  201. }
  202. async function handleAfterImport(importData) {
  203. function setupFormula(bills) {
  204. const cacheObj = {};
  205. const calcBills = [];
  206. function _transform(calc) {
  207. let rst = calc, tmpCalc = calc;
  208. let calcKeys = [], calcValues = [];
  209. let preIdx = tmpCalc.indexOf('{');
  210. while (preIdx >= 0) {
  211. let rearIdx = tmpCalc.indexOf('}');
  212. if (rearIdx > preIdx) {
  213. let fnStr = tmpCalc.substring(preIdx + 1, rearIdx);
  214. if (cacheObj[fnStr]) {
  215. calcKeys.push(`{${fnStr}}`);
  216. calcValues.push(`@${cacheObj[fnStr].ID}`);
  217. }
  218. tmpCalc = tmpCalc.substr(rearIdx + 1);
  219. preIdx = tmpCalc.indexOf('{');
  220. } else {
  221. //有异常了
  222. break;
  223. }
  224. }
  225. if (calcKeys.length > 0) {
  226. calcKeys.forEach((key, index)=> {
  227. rst = rst.replace(key, calcValues[index]);
  228. });
  229. }
  230. return rst;
  231. }
  232. //1. 先把有formulaCode的清单cache起来
  233. //2. 顺带过滤出有calcBase的清单
  234. for (let bill of bills) {
  235. if (typeof bill.formulaCode === 'string' && bill.formulaCode.indexOf('F') === 0) {
  236. cacheObj[bill.formulaCode] = bill;
  237. }
  238. if (typeof bill.calcBase === 'string' && bill.calcBase.length > 0) {
  239. calcBills.push(bill);
  240. }
  241. }
  242. //3. Action!
  243. for (let calcBill of calcBills) {
  244. calcBill.calcBase = _transform(calcBill.calcBase);
  245. }
  246. }
  247. importData.tenders.forEach((tender, index) => {
  248. setupFormula(tender.bills);
  249. });
  250. }
  251. return {
  252. entry,
  253. handleAfterImport,
  254. };
  255. })();