Quellcode durchsuchen

feat: 安徽马鞍山类接口,导入基数处理变更

vian vor 4 Jahren
Ursprung
Commit
3bed53abba

+ 4 - 3
web/building_saas/standard_interface/import/anhui_maanshan.js

@@ -186,9 +186,10 @@ INTERFACE_IMPORT = (() => {
           item.rowCode = getValue(src, ['_Code']); // 注意:行号标记,用于后续(通用处理)清单基数进行转换(行引用转换为ID引用) 
           const titleType = getValue(src, ['_Lb']);
           item.titleType = titleType;
-          if (titleType === '5') { // 暂列金额才导入计算基数
+          /* if (titleType === '5') { // 暂列金额才导入计算基数
             item.calcBase = getValue(src, ['_Jsgs']);
-          }
+          } */
+          item.tempCalcBase = getValue(src, ['_Jsgs']);
         } else if (curField === qdmx) {
           item.code = getValue(src, ['_Qdbm']);
           item.unit = getValue(src, ['_Dw']);
@@ -196,7 +197,7 @@ INTERFACE_IMPORT = (() => {
           item.unitPriceAnalysis = +getBool(src, ['_Djfx']); // 单价分析
           item.specialProvisional = getBool(src, ['_Iszg']) ? '专业工程' : ''; // 是否暂定
           if (item.specialProvisional) {
-            item.calcBase = getValue(src, ['_Jsgs']);
+            item.tempCalcBase = getValue(src, ['_Jsgs']);
           }
         }
         return item;

+ 34 - 6
web/building_saas/standard_interface/import/base.js

@@ -299,7 +299,7 @@ const INTERFACE_EXPORT_BASE = (() => {
    * @param {Number} tenderID - 单位工程ID
    * @return {Array}
    */
-  function handleBills(tenderBills, billsTarget, tenderID) {
+   function handleBills(tenderBills, billsTarget, tenderID) {
     const rst = [];
     // 将提取的清单数据合并进清单模板数据
     mergeBills(tenderBills, billsTarget, null);
@@ -330,7 +330,7 @@ const INTERFACE_EXPORT_BASE = (() => {
           const regStr = /{[^{}]+}/.test(child.rowCode) ? child.rowCode : `\\b${child.rowCode}\\b`;
           rowCodeData.push({ reg: new RegExp(regStr, 'g'), ID: child.ID, rowCode: child.rowCode });
         }
-        if (child.calcBase) {
+        if (child.tempCalcBase) {
           toBeTransformBills.push(child);
         }
         if (child.children && child.children.length) {
@@ -339,16 +339,44 @@ const INTERFACE_EXPORT_BASE = (() => {
       });
     }
     setBills(billsTarget, -1);
-    // 转换计算基数,将行引用转换为ID引用
+    // 转换计算基数
     toBeTransformBills.forEach(bills => {
       rowCodeData.forEach(({ reg, ID, rowCode }) => {
         const rowCodeReg = new RegExp(`{${rowCode}}`);
-        if (rowCodeReg.test(bills.calcBase)) {
-          bills.calcBase = bills.calcBase.replace(rowCodeReg, `@${ID}`);
+        // 替换行号
+        if (rowCodeReg.test(bills.tempCalcBase)) {
+          bills.tempCalcBase = bills.tempCalcBase.replace(rowCodeReg, `@${ID}`);
         } else {
-          bills.calcBase = bills.calcBase.replace(reg, `@${ID}`);
+          bills.tempCalcBase = bills.tempCalcBase.replace(reg, `@${ID}`);
         }
+        // 替换基数,防止其他公司的软件导出没有{}
+        bills.tempCalcBase = bills.tempCalcBase.replace(/.?专项暂定合计.?/g, '{专项暂定合计}');
+        bills.tempCalcBase = bills.tempCalcBase.replace(/.?各章清单合计.?/g, '{各章清单合计}');
       });
+
+      /* 检查基数有效性,无效则使用模板的基数 */
+      // 消除ID引用对基数分割的影响
+      const IDs = bills.tempCalcBase.match(/@[\da-zA-Z-]{36}/g) || [];
+      const bases = [...IDs];
+      const str = bills.tempCalcBase.replace(/@[\da-zA-Z-]{36}/g, '');
+      const otherBases = str.split(/[+-/*]/).filter(item => !!item);
+      bases.push(...otherBases);
+      // 判定基数有效性
+      const isValid = bases.every(base => {
+        if (base === '{专项暂定合计}' || base === '{各章清单合计}') {
+          return true;
+        }
+        if (/^(\d+(\.\d+)?)%?$/.test(base)) { // 数值+%(可有可无)
+          return true;
+        }
+        if (/[\da-zA-Z-]{36}/.test(base)) { // ID引用
+          return true;
+        }
+        return false;
+      });
+      if (isValid) {
+        bills.calcBase = bills.tempCalcBase;
+      }
     });
     rst.forEach(bills => delete bills.children);
     return rst;