Browse Source

feat: 浙江宁海导入接口

vian 4 years ago
parent
commit
7d9487ec7c
1 changed files with 170 additions and 0 deletions
  1. 170 0
      web/building_saas/standard_interface/import/zhejiang_ninghai.js

+ 170 - 0
web/building_saas/standard_interface/import/zhejiang_ninghai.js

@@ -0,0 +1,170 @@
+// 浙江宁海导入接口
+// INTERFACE_EXPORT =,必须这么写,这样才能在导入时动态加载脚本后,覆盖前端代码
+INTERFACE_IMPORT = (() => {
+  'use strict';
+  /**
+   * 
+   * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理
+   * @param {Object} xmlObj - xml经过x2js转换后的xml对象
+   * @return {Object} - 返回的格式需要统一,具体参考函数内返回的内容。返回的内容会经过一系列的统一处理形成可入库的数据。
+   */
+  async function entry(areaKey, xmlObj) {
+    const {
+      UTIL: {
+        getValue,
+        arrayValue,
+        extractItemsRecur,
+      }
+    } = INTERFACE_EXPORT_BASE;
+
+    const subArea = areaKey.split('@')[1];
+
+    const natureConstructionMap = {
+      '1': '新建',
+      '2': '改扩建',
+      '3': '养护',
+      '4': '养护(年度经费)',
+    };
+    const roadGradeMap = {
+      '1': '高速公路',
+      '2': '一级公路',
+      '3': '二级公路',
+      '4': '三级公路',
+      '5': '四级公路',
+      '6': '桥梁工程',
+      '7': '隧道工程',
+      '8': '其他工程',
+    };
+    const taxModeMap = {
+      '1': '一般计税',
+      '2': '简易计税',
+    };
+    // 提取基本信息,xml中提取出来的基本信息,最终会与模板基本信息进行合并处理。(接口内不需要处理合并)
+    function setupInformation(projectSrc) {
+      const gcxx = getValue(projectSrc, ['工程信息']);
+      const ztbxx = getValue(projectSrc, ['招投标信息', '招标控制价']) || getValue(projectSrc, ['招投标信息', '投标信息']) || getValue(projectSrc, ['招投标信息', '招标信息']);
+      // key:基本信息模板中的key,作为合并时的匹配字段
+      const info = [
+        { key: 'projNum', value: getValue(gcxx, ['_项目编号']) },
+        { key: 'constructingUnits', value: getValue(gcxx, ['_建设单位']) },
+        { key: 'startChainages', value: getValue(gcxx, ['_起始桩号']) },
+        { key: 'endChainages', value: getValue(gcxx, ['_终点桩号']) },
+        { key: 'constructionAddress', value: getValue(gcxx, ['_建设地址']) },
+        { key: 'projOverview', value: getValue(gcxx, ['_项目概况']) },
+        { key: 'natureConstruction', value: natureConstructionMap[getValue(gcxx, ['_项目类型'])] || '' },
+        { key: 'roadGrade', value: roadGradeMap[getValue(gcxx, ['_专业划分'])] || '' },
+        { key: 'roadDistance', value: getValue(gcxx, ['_道路里程-公里']) },
+        { key: 'designUnit', value: getValue(gcxx, ['_设计单位']) },
+        { key: 'taxMode', value: taxModeMap[getValue(gcxx, ['_计税方式'])] },
+        { key: 'tendereeName', value: getValue(ztbxx, ['_招标人']) },
+        { key: 'tenderAuthorizer', value: getValue(ztbxx, ['_招标法定代表人或其授权人']) },
+        { key: 'compileApprover', value: getValue(ztbxx, ['_编制人']) },
+        { key: 'compileCertNo', value: getValue(ztbxx, ['_编制人资格证号']) },
+        { key: 'compileDate', value: getValue(ztbxx, ['_编制日期']) },
+        { key: 'proxy', value: getValue(ztbxx, ['_招标代理机构']) },
+        { key: 'scopeofBidding', value: getValue(ztbxx, ['_招标范围']) },
+        { key: 'timeLimit', value: getValue(ztbxx, ['_总工期日历天']) },
+        { key: 'compileDate', value: getValue(ztbxx, ['_编制日期']) },
+        { key: 'preparationDescription', value: getValue(ztbxx, ['_编制说明']) },
+        { key: 'reviewApprover', value: getValue(ztbxx, ['_复核人']) },
+        { key: 'reviewCertNo', value: getValue(ztbxx, ['_复核人资格证号']) },
+        { key: 'reviewDate', value: getValue(ztbxx, ['_复核日期']) },
+        { key: 'examineApprover', value: getValue(ztbxx, ['_审核人']) },
+        { key: 'examineCertNo', value: getValue(ztbxx, ['_审核人资格证号']) },
+        { key: 'examineDate', value: getValue(ztbxx, ['_审核日期']) },
+        { key: 'bidderName', value: getValue(ztbxx, ['_投标人']) },
+        { key: 'bidderAuthorizer', value: getValue(ztbxx, ['_投标人法人或其授权人']) },
+        { key: 'bidderCertNo', value: getValue(ztbxx, ['_投标人资质证号']) },
+        { key: 'downwardFloatingRateOfBid', value: getValue(ztbxx, ['_投标下浮率']) },
+        { key: 'descriptionOfTenderOffer', value: getValue(ztbxx, ['_投标报价说明']) },
+        { key: 'qualityCommitment', value: getValue(ztbxx, ['_质量承诺']) },
+        { key: 'bidBond', value: getValue(ztbxx, ['_投标保证金']) },
+        { key: 'projectManagers', value: getValue(ztbxx, ['_项目经理或项目负责人']) },
+        { key: 'projectmanagersCertNo', value: getValue(ztbxx, ['_项目经理或项目负责人资格证号']) },
+      ];
+      return info;
+    }
+
+    // 提取清单数据
+    function setupBills(rootSrc, oneSevenSrc, dayWorkSrc) {
+      // 章次为空的造价汇总表数据,为大项费用数据
+      const roots = arrayValue(rootSrc, ['造价汇总明细'])
+        .filter(item => !getValue(item, ['_章次']))
+        .map(item => ({
+          name: getValue(item, ['_名称']),
+          remark: getValue(item, ['_备注']),
+          titleType: getValue(item, ['_类别'])
+        }));
+      let oneSevenBills;
+      let dayWorkBills;
+      roots.forEach(item => {
+        const simpleName = item.name ? item.name.replace(/\s/g, '') : '';
+        if (item.titleType === '1' || /100章至第700章|100章至700章/.test(simpleName)) {
+          oneSevenBills = item;
+        } else if (/计日工合计/.test(simpleName)) {
+          dayWorkBills = item;
+        }
+      });
+      // 第100-700章的数据
+      if (oneSevenBills) {
+        oneSevenBills.children = extractItemsRecur(oneSevenSrc, [['工程量清单明细']], (src) => ({
+          sectionCode: getValue(src, ['_清单章节号']),
+          code: getValue(src, ['_子目号']),
+          name: getValue(src, ['_子目名称']),
+          unit: getValue(src, ['_单位']),
+          quantity: getValue(src, ['_数量']),
+          remark: getValue(src, ['_备注']),
+          appraisalBills: +getValue(src, ['_评审清单']),
+        }));
+      }
+      // 计日工数据
+      if (dayWorkBills) {
+        const title = '计日工信息标题';
+        const detail = '计日工信息明细';
+        dayWorkBills.children = extractItemsRecur(dayWorkSrc, [[title], [detail]], (src, curField) => {
+          const name = getValue(src, ['_名称']);
+          const simpleName = name ? name.replace(/\s/g, '') : ''
+          if (curField === title && /计日工合计/.test(simpleName)) { // 计日工标题在根节点中已经提取了,不重复提取
+            return null;
+          }
+          const item = { name };
+          if (curField === detail) {
+            item.code = getValue(src, ['_编号']);
+            item.unit = getValue(src, ['_单位']);
+            item.quantity = getValue(src, ['_暂定数量']);
+          }
+          return item;
+        });
+      }
+      return roots;
+    }
+
+    // 提取单位工程数据
+    function setupTender(tenderSrc) {
+      const oneSevenSrc = getValue(tenderSrc, ['工程量清单表']);
+      const dayWorkSrc = getValue(tenderSrc, ['计日工信息表']);
+      const rootSrc = getValue(tenderSrc, ['造价汇总表']);
+      return {
+        name: getValue(tenderSrc, ['_标段名称']),
+        bills: setupBills(rootSrc, oneSevenSrc, dayWorkSrc)
+      };
+    }
+
+    // 从xml对象提取需要的数据
+    function setupProject(projectSrc) {
+      const tenders = arrayValue(projectSrc, ['公路工程数据', '公路标段工程'])
+        .map(tenderSrc => setupTender(tenderSrc));
+      return {
+        name: getValue(projectSrc, ['工程信息', '_项目名称']),
+        info: setupInformation(projectSrc),
+        tenders,
+      };
+    }
+    return setupProject(getValue(xmlObj, ['浙江公路工程']));
+  }
+
+  return {
+    entry
+  };
+
+})();