/* * @Descripttion: 山东导入接口(原始内容参考中山) * @Author: Tony * @Date: 2022-10-09 */ INTERFACE_IMPORT = (() => { 'use strict'; /** * * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理 * @param {Object} xmlObj - xml经过x2js转换后的xml对象 * @return {Object} - 返回的格式需要统一,具体参考函数内返回的内容。返回的内容会经过一系列的统一处理形成可入库的数据。 */ const RoadGradeMap = { "0": "高速公路", "1": "一级公路", "2": "二级公路", "3": "三级公路", "4": "四级公路", "5": "等外公路", "6": "独立桥梁", "7":"独立隧道" } function formateDataString(dstring) { if (!dstring || dstring == "") return ""; const strArr = dstring.split("T"); return strArr[0] } async function entry(areaKey, xmlObj) { const { UTIL: { getValue, arrayValue, getBool, extractItemsRecur, } } = INTERFACE_EXPORT_BASE; let info = []; let tenders = []; let CprjInfo = getValue(xmlObj, ['CprjInfo']); let EprjInfos = arrayValue(CprjInfo, ["EprjInfo"]); if (EprjInfos.length > 0) { let MakeInfo = EprjInfos[0].MakeInfo; let Params = EprjInfos[0].Params; let BuildType = getValue(Params, ['_BuildType']); let natureConstruction = ""; if (BuildType == "0") natureConstruction = "新建"; if (BuildType == "1") natureConstruction = "改扩建"; let terrainCategory = ""; let Terrain = getValue(Params, ['_Terrain']); if (Terrain == "0") terrainCategory = "平原微丘"; if (Terrain == "1") terrainCategory = "山岭重丘"; let RoadGrade = getValue(Params, ['_RoadGrade']); let roadGrade = ""; if (RoadGradeMap[RoadGrade]) roadGrade = RoadGradeMap[RoadGrade]; info = [ { key: 'constructingUnit', value: getValue(MakeInfo, ['_Manage']) }, { key: 'designUnit', value: getValue(MakeInfo, ['_Designer']) }, { key: 'compileUnit', value: getValue(MakeInfo, ['_Compile']) }, { key: 'compileApprover', value: getValue(MakeInfo, ['_CompileApprover']) }, { key: 'compileCertNo', value: getValue(MakeInfo, ['_CompileCertNo']) }, { key: 'compileDate', value: formateDataString(getValue(MakeInfo, ['_CompileDate'])) }, { key: 'reviewUnit', value: getValue(MakeInfo, ['_Review']) }, { key: 'reviewApprover', value: getValue(MakeInfo, ['_ReviewApprover']) }, { key: 'reviewCertNo', value: getValue(MakeInfo, ['_ReviewCertNo']) }, { key: 'reviewDate', value: formateDataString(getValue(MakeInfo, ['_ReviewDate'])) }, { key: 'startChainages', value: getValue(Params, ['_StartPileNo'])}, { key: 'endChainages', value: getValue(Params, ['_EndPileNo']) }, { key: 'location', value: getValue(Params, ['_PrjArea']) }, { key: 'natureConstruction', value: natureConstruction }, { key: 'terrainCategory', value: terrainCategory }, { key: 'roadGrade', value: roadGrade }, { key: 'makeDate', value: getValue(CprjInfo, ['SystemInfo','_MakeDate']) }, ] for (let t of EprjInfos) { tenders.push(setupTender(t)) } } function setupTender(EprjInfo) { let tender = {}; let Params = EprjInfo.Params; let SummaryOfCost = EprjInfo.SummaryOfCost; tender.name = EprjInfo._Name; tender.bills = []; tender.bidEvaluationList = []; tender.evaluationList = []; let ProvisionalSums = getValue(SummaryOfCost, ['_ProvisionalSums']); let Structure = getValue(Params, ['_Structure']); let pavementStructure = ""; if (Structure == "0") pavementStructure = "沥青路面"; if (Structure == "1") pavementStructure = "水泥混凝土路面"; if (Structure == "2") pavementStructure = "其他类型路面"; tender.feature = [ { key: 'tenderSumLimit', value: getValue(SummaryOfCost, ['_TenderSumLimit'])},//招标控制价 { key: 'designSpeed', value: getValue(Params, ['_DesignSpeed']) },// --todo { key: 'pavementStructure', value: pavementStructure},// --todo { key: 'subgradeWidth', value: getValue(Params, ['_SubgradeWidth']) }, { key: 'roadLength', value: getValue(Params, ['_RoadLength']) },// --todo { key: 'bridgeLength', value: getValue(Params, ['_BridgeLength']) }, { key: 'tunnelLength', value: getValue(Params, ['_TunnelLength']) },// --todo { key: 'briTunRate', value: getValue(Params, ['_BriTunRate']) },// --todo { key: 'interchangeNum', value: getValue(Params, ['_InterchangeNum']) },// --todo { key: 'stubLengths', value: getValue(Params, ['_StubLengths']) },// --todo { key: 'laneLength', value: getValue(Params, ['_LaneLength']) },// --todo ] const items = arrayValue(EprjInfo, ['Items', 'Item']); let hasOneHundredChapter = false; for (let i of items) { let bill = setupBills(i); if (bill.name.indexOf('第100章') >= 0 && bill.name.indexOf('总则') >= 0) hasOneHundredChapter = true; if (bill.name == "暂列金额(不含计日工总额)") { bill.fees = [{ fieldName: "common",tenderTotalFee:ProvisionalSums, tenderUnitFee: "0", totalFee: ProvisionalSums, unitFee: "0" }]; if (bill.calcBase === undefined || bill.calcBase === null || bill.calcBase === '') { // 正常导入的暂列金额应该有公式(山东特有),没有公式再导ProvisionalSums bill.calcBase = ProvisionalSums; } bill.calcFlag = 1; } let formula = getValue(i, ['CostComposition', 'Formula', '_Formulas']); if (formula !== undefined && formula !== null && formula !== '') { bill.exCalcStr = formula; // 不仅仅'投标报价'有,其他的也要 } // if (bill.name == '投标报价') { // bill.exCalcStr = formula || ''; // } tender.bills.push(bill); } tender.hasOneHundredChapter = hasOneHundredChapter; // 山东的 formula 还得调整 // setupFormula(tender.bills); const BidEvaluationMainMaterial = arrayValue(EprjInfo, ['BidEvaluationMainMaterial']); for (let b of BidEvaluationMainMaterial) { tender.bidEvaluationList.push(setUpBidEvaluation(b)) } return tender; } function handleBillPrice(bill, formula, totalFee, quantity) { if (formula) { bill.calcFlag = 1; bill.exCalcStr = formula; } else if (!formula && !quantity && totalFee) { // 没有基数、没有工程量时,有金额时,金额作为基数 bill.exCalcStr = String(totalFee); bill.calcFlag = 1; } else { bill.calcFlag = 2; } } function setupBills(item, needClac = false) { const regBlank = new RegExp(' ', 'g'); let bill = { code: item._ListCode, name: item._ListName, unit: item._Unit, quantity: item._Num, remark: item._Remarks, jobContentText: item._Content, specialProvisional: '', formulaCode: item._FormulaCode, qtyFormula: item._QtyFormula, children: [] } const formula = getValue(item, ['CostComposition', 'Formula', '_Formulas']); // if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.qtyFormula && bill.qtyFormula !== '') { if ((needClac || bill.name == "暂列金额(不含计日工总额)") && bill.hasOwnProperty('qtyFormula')) { let formula = getValue(item, ['CostComposition', 'Formula', '_Formulas']); let ratio = getValue(item, ['CostComposition', 'Formula', '_Ratio']); if (formula !== undefined && formula !== null && formula !== '') { bill.calcBase = formula; // 这个formula在后期还要处理的 if (ratio && ratio !== '') { let dRation = parseFloat(ratio); if (!isNaN(dRation) && dRation != 1) { bill.calcBase = `(${formula}) * ${dRation}`; // 如果有费率且不等于1,还需要调整基数公式 } } } } if (item._ProvisionalType == '0') bill.specialProvisional = '材料暂估'; if (item._ProvisionalType == '1') bill.specialProvisional = '工程设备'; if (item._ProvisionalType == '2') bill.specialProvisional = '专业工程'; if (item._ProvisionalType == '3') bill.specialProvisional = '固定费用'; if (item._ProvisionalType == '2') { let sumVal = getValue(item, ['_Sum']); let priceVal = getValue(item, ['_Price']); bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: priceVal, totalFee: sumVal, unitFee: priceVal }]; // bill.calcBase = sumVal; // bill.calcFlag = 2; handleBillPrice(bill, formula, +sumVal, +bill.quantity); } if (item._ProvisionalType == '3') { let sumVal = getValue(item, ['_Sum']); let priceVal = getValue(item, ['_Price']); // if ((+sumVal) < (+priceVal)) sumVal = priceVal; bill.fees = [{ fieldName: "common",tenderTotalFee:sumVal, tenderUnitFee: priceVal, totalFee: sumVal, unitFee: priceVal }]; // bill.calcBase = sumVal; // bill.calcFlag = 2; handleBillPrice(bill, formula, +sumVal, +bill.quantity); } let subItems = arrayValue(item, ['Item']); if (subItems && subItems.length > 0) { for (let i of subItems) { if (typeof i._ListName === 'string' && i._ListName.replace(regBlank, '') === '清单第100章总则') { bill.children.push(setupBills(i, true)); } else { bill.children.push(setupBills(i, needClac)); } } } return bill; } function setUpBidEvaluation(b) { return { seq: b._Code, code: b._Number, name: b._Name, specs: b._Specification, unit: b._Unit, market_price: b._Price, quantity: b._Quantity, remark:b._Remark } } return { name: CprjInfo._CprjName, info, tenders, }; } async function handleAfterImport(importData) { function setupFormula(bills) { const cacheObj = {}; const calcBills = []; function _transform(calc) { let rst = calc, tmpCalc = calc; let calcKeys = [], calcValues = []; let preIdx = tmpCalc.indexOf('{'); while (preIdx >= 0) { let rearIdx = tmpCalc.indexOf('}'); if (rearIdx > preIdx) { let fnStr = tmpCalc.substring(preIdx + 1, rearIdx); if (cacheObj[fnStr]) { calcKeys.push(`{${fnStr}}`); calcValues.push(`@${cacheObj[fnStr].ID}`); } tmpCalc = tmpCalc.substr(rearIdx + 1); preIdx = tmpCalc.indexOf('{'); } else { //有异常了 break; } } if (calcKeys.length > 0) { calcKeys.forEach((key, index)=> { rst = rst.replace(key, calcValues[index]); }); } return rst; } //1. 先把有formulaCode的清单cache起来 //2. 顺带过滤出有calcBase的清单 for (let bill of bills) { if (typeof bill.formulaCode === 'string' && bill.formulaCode.indexOf('F') === 0) { cacheObj[bill.formulaCode] = bill; } if (typeof bill.calcBase === 'string' && bill.calcBase.length > 0) { if (bill.exCalcStr) bill.calcBase = bill.exCalcStr; calcBills.push(bill); } else if (bill.exCalcStr) { bill.calcBase = bill.exCalcStr; calcBills.push(bill); } } //3. Action! for (let calcBill of calcBills) { calcBill.calcBase = _transform(calcBill.calcBase); } } importData.tenders.forEach((tender, index) => { setupFormula(tender.bills); if (!tender.hasOneHundredChapter) { for (let idx = tender.bills.length - 1; idx >= 0; idx--) { const bName = tender.bills[idx].name || ''; if (bName.indexOf('第100章') >= 0 && bName.indexOf('总则') > 0) { tender.bills.splice(idx, 1); break; } } } delete tender.hasOneHundredChapter; }); } return { entry, handleAfterImport, }; })();