浏览代码

fix: 导入接口的时候,应导入一些初始化的单价文件数据如车船税等

vian 5 年之前
父节点
当前提交
90069168c5

+ 2 - 1
modules/main/facade/ration_facade.js

@@ -56,6 +56,7 @@ let complementaryGljLibModel = mongoose.model('complementary_glj_lib');
 
 let _= require('lodash');
 const projectDao = require('../../pm/models/project_model').project;
+const pmFacade = require('../../pm/facade/pm_facade');
 let projectModel = mongoose.model('projects');
 let unitPriceModel = mongoose.model('unit_price');
 let unitPriceFileModel = mongoose.model('unit_price_file');
@@ -566,7 +567,7 @@ async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义
 
 //对于多单价,多组成物消耗量的编办,通过这个方法获取单价、组成物消耗量的字段,
 function getExtendData(property,compilation) {
-    return projectDao.getExtendData(property,compilation);
+    return pmFacade.getExtendData(property,compilation);
 }
 
 

+ 33 - 6
modules/pm/facade/pm_facade.js

@@ -9,6 +9,7 @@
     };
 //先导出后require可以解决循环引用问题
 module.exports={
+    getExtendData,
     getBasicInfo,
     getImportTemplateData,
     getProjectByGranularity,
@@ -54,7 +55,7 @@ module.exports={
     importInterface,
     copyConstructionProject,
     isTenderOverrun,
-    getWelcomeInfo:getWelcomeInfo
+    getWelcomeInfo:getWelcomeInfo,
 };
 
 
@@ -138,6 +139,29 @@ let path = require("path");
 let request = require("request");
 const systemSettingModel = mongoose.model('system_setting');
 
+function getExtendData(property, compilation) {
+    let ext = {};
+    if (property) {
+        let region = property.region;
+        let taxType = property.taxType;
+        if (compilation.priceProperties && compilation.priceProperties.length > 0) {//如果是具有多单价的编办,取单价对应的字段
+            let priceProperty = _.find(compilation.priceProperties, { region: region, taxModel: parseInt(taxType) });
+            if (priceProperty) {
+                ext['priceField'] = priceProperty.price.dataCode;
+            }
+        }
+        if (compilation.consumeAmtProperties && compilation.consumeAmtProperties.length > 0) {
+            let consumeAmt = _.find(compilation.consumeAmtProperties, { region: region, taxModel: parseInt(taxType) });
+            if (consumeAmt) {
+                ext['quantityField'] = consumeAmt.consumeAmt.dataCode;
+            }
+        }
+    }
+    return _.isEmpty(ext) ? null : ext;
+}
+
+
+
 let qiniu_config = {
     "AccessKey": "_gR1ed4vi1vT2G2YITGSf4_H0fJu_nRS9Tzk3T4z",
     "SecretKey": "ty4zd0FHqgEDaiVzSLC8DfHlai99aS7bspLkw6s6",
@@ -1819,14 +1843,14 @@ async function handleImportInterface(key, session) {
             throw '无有效数据';
         }
         const userID = session.sessionUser.id;
-        const compilationID = session.sessionCompilation._id;
+        const compilation = session.sessionCompilation;
         const importData = JSON.parse(srcData);
         const tenderCount = importData.tenders.length;
         if (await isTenderOverrun(tenderCount, session)) {
             throw '您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。';
         }
         const overWriteUrl = session.sessionCompilation.overWriteUrl;
-        const projectID = await importInterfaceProject(importData, userID, compilationID, overWriteUrl);
+        const projectID = await importInterfaceProject(importData, userID, compilation, overWriteUrl);
         doc.projectID = projectID;
     } catch (err) {
         console.log(err);
@@ -1841,7 +1865,8 @@ async function handleImportInterface(key, session) {
 /*
 * 接口导入 项目详细数据都导入完成了,再生成项目数据(项目管理界面数据)
 * */
-async function importInterfaceProject(importObj, userID, compilationID, overWriteUrl) {
+async function importInterfaceProject(importObj, userID, compilation, overWriteUrl) {
+    const compilationID = compilation._id;
     const toInsertProjects = [importObj];  //待新增项目数据
     let defaultCalcMode;
     if (overWriteUrl) {
@@ -1855,7 +1880,7 @@ async function importInterfaceProject(importObj, userID, compilationID, overWrit
     for (const curTender of importObj.tenders) {
         await setupProject(curTender);
         // 插入单位工程的详细数据
-        await importTenderDetail(curTender);
+        await importTenderDetail(curTender, compilation);
         delete curTender.bills;
         toInsertProjects.push(curTender);
     }
@@ -1916,7 +1941,7 @@ async function importInterfaceProject(importObj, userID, compilationID, overWrit
 }
 
 //插入单位工程内部详细数据
-async function importTenderDetail(tenderData) {
+async function importTenderDetail(tenderData, compilation) {
     // 单价文件
     const upFile = {
         id: tenderData.property.unitPriceFile.id,
@@ -1926,6 +1951,8 @@ async function importTenderDetail(tenderData) {
         root_project_id: tenderData.property.rootProjectID
     };
     await unitPriceFileModel.create(upFile);
+    // 新增单价文件的同时,在项目工料机和空白的单价文件中先插入机械组成物等信息
+    await glj_facade.addMixRatioForNew(tenderData.ID, upFile.id, tenderData.property.engineering_id, getExtendData(tenderData.property, compilation))
     // 费率文件
     const feeRateFileID = await feeRate_facade.newFeeRateFile(tenderData.userID, tenderData);
     tenderData.property.feeFile = feeRateFileID ? feeRateFileID : -1;

+ 1 - 23
modules/pm/models/project_model.js

@@ -174,7 +174,7 @@ ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId
                     }
                     data.updateData.property.unitPriceFile.id = addResult.id;
                     //新增单价文件的同时,在项目工料机和空白的单价文件中先插入机械组成物等信息
-                    await gljFacade.addMixRatioForNew(data.updateData.ID,addResult.id,data.updateData.property.engineering_id,this.getExtendData(data.updateData.property,compilation));
+                    await gljFacade.addMixRatioForNew(data.updateData.ID,addResult.id,data.updateData.property.engineering_id,pmFacade.getExtendData(data.updateData.property,compilation));
                 }
                 if (data.updateData.projType === projectType.tender) {
                     //单价文件
@@ -693,28 +693,6 @@ ProjectsDAO.prototype.getProjectProperty = async function (projectId) {
     return projectData.property;
 };
 
-ProjectsDAO.prototype.getExtendData = function(property,compilation) {
-    let ext = {};
-    if(property){
-        let region = property.region;
-        let taxType = property.taxType;
-        if(compilation.priceProperties && compilation.priceProperties.length > 0){//如果是具有多单价的编办,取单价对应的字段
-            let priceProperty  = _.find(compilation.priceProperties,{region:region,taxModel:parseInt(taxType)});
-            if(priceProperty){
-                ext['priceField'] =  priceProperty.price.dataCode;
-            }
-        }
-        if(compilation.consumeAmtProperties && compilation.consumeAmtProperties.length > 0){
-            let  consumeAmt =   _.find(compilation.consumeAmtProperties,{region:region,taxModel:parseInt(taxType)});
-            if(consumeAmt){
-                ext['quantityField'] =  consumeAmt.consumeAmt.dataCode;
-            }
-        }
-    }
-    return _.isEmpty(ext)?null:ext;
-}
-
-
 /**
  * 获取当前用户的建设项目数据
  *

+ 3 - 2
modules/ration_glj/facade/ration_glj_facade.js

@@ -59,6 +59,7 @@ const complementaryGljModel = mongoose.model('complementary_glj_lib');
 const stdGljModel = mongoose.model('std_glj_lib_gljList');
 const gljClassModel = mongoose.model('std_glj_lib_gljClass');
 const projectDao = require('../../pm/models/project_model').project;
+const pmFacade = require('../../pm/facade/pm_facade');
 const commonFacade = require('../../main/facade/common_facade');
 const compleClassModel = mongoose.model('complementary_glj_section');
 const stdRationLibModel = mongoose.model('std_ration_lib_map');
@@ -740,7 +741,7 @@ function getGLJSearchInfo(ration_glj) {
 async function prepareExtData(projectID, compilation) {
   let ext, unitFileId;
   let property = await projectDao.getProjectProperty(projectID);
-  ext = projectDao.getExtendData(property, compilation);
+  ext = pmFacade.getExtendData(property, compilation);
   unitFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
   return [unitFileId, ext];
 }
@@ -1295,7 +1296,7 @@ async function getGLJDataByCodes(data, compilation) {
     });
     if (stdList.length > 0) {
       let property = await projectDao.getProjectProperty(data.projectID);
-      let ext = projectDao.getExtendData(property, compilation); //多单价处理
+      let ext = pmFacade.getExtendData(property, compilation); //多单价处理
       for (let s of stdList) {
         let tem = JSON.parse(JSON.stringify(s));
         if (ext && ext.priceField && tem && tem.priceProperty) {