Просмотр исходного кода

fix: 浙江养护接口,养护类别、费用标准问题

vian 4 лет назад
Родитель
Сommit
7cd7ebf4af

+ 1 - 1
modules/pm/controllers/pm_controller.js

@@ -1052,7 +1052,7 @@ module.exports = {
     getImportTemplateData: async function (req, res) {
         try {
             const data = JSON.parse(req.body.data);
-            const templateData = await pm_facade.getImportTemplateData(req.session.sessionCompilation._id, data.valuationID, data.projectCount);
+            const templateData = await pm_facade.getImportTemplateData(req.session.sessionCompilation._id, data.valuationID, data.engineeringID, data.projectCount);
             callback(req, res, 0, 'success', templateData);
         } catch (err) {
             callback(req, res, 1, err, null);

+ 4 - 2
modules/pm/facade/pm_facade.js

@@ -2640,8 +2640,10 @@ async function getBasicInfo(compilationID, fileKind = null) {
 }
 
 // 获取导入接口功能的模板数据,用于将导入数据与模板数据进行合并生成新的项目
-async function getImportTemplateData(compilationID, valuationID, projectCount) {
-    const engineeringLib = await engineeringModel.findOne({ valuationID }).lean();
+async function getImportTemplateData(compilationID, valuationID, engineeringID, projectCount) {
+    const engineeringLib = engineeringID 
+        ? await engineeringModel.findOne({ _id: mongoose.Types.ObjectId(engineeringID) }).lean()
+        : await engineeringModel.findOne({ valuationID }).lean()
     if (!engineeringLib) {
         return null;
     }

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

@@ -371,7 +371,7 @@ const INTERFACE_EXPORT_BASE = (() => {
   }
 
   // 处理单位工程数据
-  function handleTenderData(tenders, templateData) {
+  function handleTenderData(tenders, templateData, rationValuationData, engineeringLib) {
     tenders.forEach((tender, index) => {
       tender.compilation = compilationData._id;
       tender.userID = userID;
@@ -380,9 +380,6 @@ const INTERFACE_EXPORT_BASE = (() => {
       tender.NextSiblingID = index === tenders.length - 1 ? -1 : templateData.projectBeginID + index + 2;
       tender.projType = projectType.tender;
       const featureTarget = _.cloneDeep(templateData.feature); // 必须拷贝出一份新数据,否则会被下一个单位工程覆盖
-      const rationValuationData = JSON.parse(rationValuation)[0];
-      const engineeringList = rationValuationData.engineering_list;
-      const engineeringLib = engineeringList.find(item => item.lib.visible);
       if (!engineeringLib) {
         throw '不存在可用工程专业。';
       }
@@ -392,6 +389,10 @@ const INTERFACE_EXPORT_BASE = (() => {
         { key: 'valuationType', value: '工程量清单' }, // 导入的时候以下项不一定有数据,但是需要自动生成
         { key: 'feeStandard', value: engineeringLib.lib.feeName },
       ];
+      const needEngineering = featureTarget && featureTarget.find(item => item.key === 'engineering');
+      if (needEngineering) {
+        featureSource.push({ key: 'engineering', value: engineeringLib.lib.name });
+      }
       tender.property = {
         rootProjectID: tender.ParentID,
         region: '全省',
@@ -445,7 +446,20 @@ const INTERFACE_EXPORT_BASE = (() => {
     }
     const projectCount = 1 + importData.tenders.length;
     // const feeName = compilationData.name === '安徽养护(2018)' ? '安徽养护' : '公路工程';
-    const templateData = await ajaxPost('/pm/api/getImportTemplateData', { user_id: userID, valuationID, projectCount });
+    // 一些接口需要根据导入文件,匹配工程专业库
+    const rationValuationData = rationValuation && JSON.parse(rationValuation)[0]; // 只有工程量清单才能导入接口
+    if (!rationValuationData) {
+      throw '无法获取工程量清单计价数据';
+    }
+    const engineeringList = (rationValuationData.engineering_list || []).filter(item => item.lib.visible);
+    let engineeringLib = engineeringList[0];
+    if (importData.engineeringName && importData.feeName) {
+      const matchLibs = engineeringList.filter(item => item.lib && item.lib.name === importData.engineeringName);
+      engineeringLib = matchLibs.find(item => item.lib.feeName === importData.feeName) || matchLibs[0] || engineeringList[0];
+    }
+    const engineeringID = engineeringLib.engineering_id || null;
+
+    const templateData = await ajaxPost('/pm/api/getImportTemplateData', { user_id: userID, valuationID, engineeringID, projectCount });
     if (!templateData) {
       throw '无法获取有效模板数据。';
     }
@@ -472,7 +486,7 @@ const INTERFACE_EXPORT_BASE = (() => {
     };
     delete importData.info;
     // 处理单位工程数据
-    handleTenderData(importData.tenders, templateData);
+    handleTenderData(importData.tenders, templateData, rationValuationData, engineeringLib);
     console.log(importData);
   }
 

+ 16 - 2
web/building_saas/standard_interface/import/zhejiang_ninghai.js

@@ -39,11 +39,23 @@ INTERFACE_IMPORT = (() => {
       '1': '一般计税',
       '2': '简易计税',
     };
+
+    // 工程专业
+    let engineeringName = '小修保养、大中修';
+    // 费用标准
+    let feeName = '高速公路';
+
     // 提取基本信息,xml中提取出来的基本信息,最终会与模板基本信息进行合并处理。(接口内不需要处理合并)
     function setupInformation(projectSrc) {
       const gcxx = getValue(projectSrc, ['工程信息']);
       const ztbxx = getValue(projectSrc, ['招投标信息', '招标控制价']) || getValue(projectSrc, ['招投标信息', '投标信息']) || getValue(projectSrc, ['招投标信息', '招标信息']);
       // key:基本信息模板中的key,作为合并时的匹配字段
+      const natureConstruction = natureConstructionMap[getValue(gcxx, ['_项目类型'])] || '';
+      if (natureConstruction === '养护(年度经费)') {
+        engineeringName = '小修保养年度经费';
+      }
+      const roadGrade = roadGradeMap[getValue(gcxx, ['_专业划分'])] || '';
+      feeName = roadGrade;
       const info = [
         { key: 'projNum', value: getValue(gcxx, ['_项目编号']) },
         { key: 'constructingUnits', value: getValue(gcxx, ['_建设单位']) },
@@ -51,8 +63,8 @@ INTERFACE_IMPORT = (() => {
         { 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: 'natureConstruction', value: natureConstruction },
+        { key: 'roadGrade', value: roadGrade },
         { key: 'roadDistance', value: getValue(gcxx, ['_道路里程-公里']) },
         { key: 'designUnit', value: getValue(gcxx, ['_设计单位']) },
         { key: 'taxMode', value: taxModeMap[getValue(gcxx, ['_计税方式'])] },
@@ -161,6 +173,8 @@ INTERFACE_IMPORT = (() => {
         GUID: getValue(projectSrc, ['工程信息', '_GUID']),
         info: setupInformation(projectSrc),
         tenders,
+        engineeringName,
+        feeName,
       };
     }
     return setupProject(getValue(xmlObj, ['浙江公路工程']));