shandong_common.js 11 KB

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