Bläddra i källkod

山东接口(清单FormulaCode)

Tony Kang 2 år sedan
förälder
incheckning
65f994e6d9
1 ändrade filer med 91 tillägg och 17 borttagningar
  1. 91 17
      web/building_saas/standard_interface/export/shandong_common.js

+ 91 - 17
web/building_saas/standard_interface/export/shandong_common.js

@@ -950,7 +950,8 @@ INTERFACE_EXPORT = (() => {
         this.children.push(new SummaryOfCost(totalItem, proItem,safeItem,oneToSevenItem,feature));
         this.children.push(new MakeInfo(tenderProject));
         this.children.push(new Params(tenderProject));
-        this.children.push(new getBillsItems(tenderProject));
+        const cacheForFormula = _preCodeingForBills(tenderProject);
+        this.children.push(new getBillsItems(tenderProject, cacheForFormula));
         this.children.push(new getIndexs(tenderProject));
         let bidEvaluationMainMaterials = getBidEvaluationMainMaterial(tenderProject);
         if(bidEvaluationMainMaterials.length > 0) this.children.push(...bidEvaluationMainMaterials);
@@ -1830,7 +1831,7 @@ INTERFACE_EXPORT = (() => {
       }
   
   
-      function getBillsItems(tenderProject) {
+      function getBillsItems(tenderProject, cacheForFormula) {
         let items = new emptyElement("Items");
         let rootNodes = tenderProject.mainTree.roots;
         for (let r of rootNodes) {
@@ -1939,6 +1940,11 @@ INTERFACE_EXPORT = (() => {
               //判断公式(calcBase)是否为正常的计算公式(即非直接输入数量),
             }
 
+            let formulaCode = '';
+            if (cacheForFormula['_' + data.ID] && cacheForFormula['_' + data.ID].formulaCode) {
+              formulaCode = cacheForFormula['_' + data.ID].formulaCode;
+            }
+
             const attrs = [{
                 name: "ListCode",
                 value: ListCode,
@@ -2037,6 +2043,10 @@ INTERFACE_EXPORT = (() => {
                 name: "FomulaCode",
                 value: ""
               }, */
+              {
+                name: "FormulaCode",
+                value: formulaCode,
+              },
             ];
             //投标、招标控制价时。取单价。
             //招标时,如果是“安全生产费”或“暂列金额”,取单价,否则取0。
@@ -2060,20 +2070,7 @@ INTERFACE_EXPORT = (() => {
               // 当清单有清单基数和费率,那么应该就是没有定额,不输出定额;
               // 清单没有基数和费率,也没有下挂定额,那么也不输出定额相关字段;
               // 清单有下挂定额、量价,那么输出定额相关数据。
-              if (isBidInvitation) return null;
-              // let bSet = true;
-              // if (bNode.data.hasOwnProperty('calcBase')) {
-              //   let chkNaN = parseFloat(bNode.data.calcBase);
-              //   if (!isNaN(chkNaN)) {
-              //     bSet = false;
-              //   }
-              // } else {
-              //   bSet = false;
-              // }
-              // if (!bSet) return null;
-              // 1. 如果是招标清单,不输出定额
-              // 2. 其他情况,如果清单下有定额,就输出定额
-              // 上面写了一堆的废话,TNND,不就2句话解释的事情,非得扯基数判断
+              // if (isBidInvitation) return null; // 山东接口又要这个了
               let CostComposition = new emptyElement('CostComposition');
               let Norms = [];
               let Costs = [];
@@ -2106,7 +2103,7 @@ INTERFACE_EXPORT = (() => {
                   },
                   {
                     name: "Formulas",
-                    value: bills.calcBase
+                    value: _getFormulaDispName(cacheForFormula, bills)
                   },
                   {
                     name: "Ratio",
@@ -2610,6 +2607,83 @@ INTERFACE_EXPORT = (() => {
         // return hashHex;
         return hashHex.toUpperCase();
     }
+
+    function _extractBillCalcRefs(currentBill) {
+      const rst = [];
+      if (typeof currentBill.calcBase === 'string' && currentBill.calcBase.length > 37) {
+        let currentBillCalcBase = currentBill.calcBase;
+        let currentIdx = currentBillCalcBase.indexOf('@');
+        while (currentIdx >= 0) {
+          let bId = currentBillCalcBase.substr(currentIdx + 1, 36);
+          if (!rst.includes(bId)) {
+            rst.push(bId);
+          }
+          currentBillCalcBase = currentBillCalcBase.substr(currentIdx + 37);
+          currentIdx = currentBillCalcBase.indexOf('@');
+        }
+      }
+      return rst;
+    }
+
+    function _preCodeingForBills(tenderProject) {
+      const cacheObj = {};
+      function _setCache(bNode) {
+        cacheObj['_' + bNode.data.ID] = bNode.data;
+        if (bNode.children && bNode.children.length > 0) {
+          for (let subNode of bNode.children) {
+            _setCache(subNode);
+          }
+        }
+      }
+      let rootNodes = tenderProject.mainTree.roots;
+      for (let rootNode of rootNodes) {
+        _setCache(rootNode);
+      }
+
+      let cnt = 1;
+      for (let bill of tenderProject.Bills.datas) {
+        let billRefs = _extractBillCalcRefs(bill);
+        for (let refBillId of billRefs) {
+          if (cacheObj['_' + refBillId]) {
+            if (!cacheObj['_' + refBillId].hasOwnProperty('formulaCode')) {
+              cacheObj['_' + refBillId].formulaCode = `F${cnt}`;
+              cnt++;
+            }
+          }
+        }
+      }
+      return cacheObj;
+    }
+
+    function _getFormulaDispName(cacheForFormula, currentBill) {
+      let rst = currentBill.calcBase;
+      if (typeof currentBill.calcBase === 'string' && currentBill.calcBase.length > 37) {
+        let currentBillCalcBase = currentBill.calcBase;
+        let currentIdx = currentBillCalcBase.indexOf('@');
+        let bIdArr = [], replaceArr = [];
+        while (currentIdx >= 0) {
+          let bId = currentBillCalcBase.substr(currentIdx + 1, 36);
+          bIdArr.push(bId);
+          if (cacheForFormula['_' + bId]) {
+            if (cacheForFormula['_' + bId].hasOwnProperty('formulaCode')) {
+              replaceArr.push(cacheForFormula['_' + bId].formulaCode);
+            } else {
+              replaceArr.push(`{无formulaCode错误:${bId}}`);
+            }
+          } else {
+            replaceArr.push(`{引用错误:${bId}}`);
+          }
+          currentBillCalcBase = currentBillCalcBase.substr(currentIdx + 37);
+          currentIdx = currentBillCalcBase.indexOf('@');
+        }
+        let tempBillCalcBase = currentBill.calcBase;
+        for (let idx = 0; idx < bIdArr.length; idx++) {
+          tempBillCalcBase = tempBillCalcBase.replace('@' + bIdArr[idx], replaceArr[idx]);
+        }
+        rst = tempBillCalcBase;
+      }
+      return rst;
+    }
     
     return {
       entry,