Browse Source

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

chenshilong 6 years ago
parent
commit
536ac079bb

+ 5 - 1
modules/common/std/std_glj_lib_glj_list_model.js

@@ -64,7 +64,11 @@ class STDGLJLibGLJListModel extends BaseModel {
         // 整理数据
         for (let component of libGljData.component) {
             componentIdList.push(component.ID);
-            componentConsume[component.ID] = component.consumeAmt;
+            if(component.consumeAmt != undefined && component.consumeAmt != null) {
+                componentConsume[component.ID] = component.consumeAmt;
+            }else if(component.consumeAmtProperty){
+                componentConsume[component.ID] = component.consumeAmtProperty;
+            }
         }
 
         let condition = {ID: {$in: componentIdList}};

+ 1 - 0
modules/complementary_glj_lib/models/gljModel.js

@@ -286,6 +286,7 @@ class GljDao {
                 componentIdListCpt.push(component.ID);
             }
             let isStdFlag = component.isStd ? 'std' : 'cpt';
+            //对于补充人材机的组成物,不会有多单价的情况
             componentConsume[component.ID + '_' + isStdFlag] = component.consumeAmt;
         }
 

+ 16 - 7
modules/glj/models/glj_list_model.js

@@ -235,7 +235,7 @@ class GLJListModel extends BaseModel {
      * @param {object} data
      * @return {Promise} 返回插入成功的数据id
      */
-    async addList(data,unitFileId) {
+    async addList(data,unitFileId,ext) {
         let result = null;
         try {
             if (Object.keys(data).length <= 0) {
@@ -277,11 +277,11 @@ class GLJListModel extends BaseModel {
             if(this.ownCompositionTypes.indexOf(data.type)!=-1) {
                 //如果是新增
                 if(isAddProjectGLJ ){
-                    await this.compositionInit(data, unitPriceFileId);
+                    await this.compositionInit(data, unitPriceFileId,ext);
                 }
                 CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
                 if(isAddProjectGLJ==false&&CompositionGLJ.length==0){//如果不是新增,并且是有组成物的类型但又没有发现组成物的情况下,有可能是错误数据,重新在库中查找一下组成物,有则插入
-                    await this.compositionInit(data, unitPriceFileId);
+                    await this.compositionInit(data, unitPriceFileId,ext);
                     CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
 
                     if(CompositionGLJ.length>0){//如果这次发现又有组成物了,则把旧的单价数据删除,在后面的操作中会重新增加
@@ -535,7 +535,7 @@ class GLJListModel extends BaseModel {
      * @param {Number} projectId
      * @return {void}
      */
-    async compositionInit(data, unitPriceFileId) {
+    async compositionInit(data, unitPriceFileId,ext) {
         let gljId = data.glj_id === undefined ? 0 : data.glj_id;
         let projectId = data.project_id === undefined ? 0 : data.project_id;
         let mixRatioModel = new MixRatioModel();
@@ -553,6 +553,11 @@ class GLJListModel extends BaseModel {
         let e_mList = await mixRatioModel.findDataByCondition({unit_price_file_id: unitPriceFileId,connect_key: connect_key},null,false);
         if(e_mList.length <= 0){
             for (let tmp of compositionGljList) {
+                let consumpiton = tmp.consumption;
+                //只有标准的工料机的组成物才会有多单价、多组成物消耗量的情况 fromTable
+                if(fromTable == 'std' && ext && ext.quantityField &&( tmp.consumption[ext.quantityField]!= undefined && tmp.consumption[ext.quantityField]!=null)){
+                    consumpiton = tmp.consumption[ext.quantityField];
+                }
                 // 配合比数据插入
                 let mixRatioData = {
                     consumption: tmp.consumption,
@@ -601,7 +606,13 @@ class GLJListModel extends BaseModel {
                 };
                 gljInsertData.push(gljData);
             }
-            let basePrice = scMathUtil.roundTo(tmp.basePrice,-6);
+            let basePrice = tmp.basePrice;
+            //只有标准的工料机的组成物才会有多单价、多组成物消耗量的情况 fromTable
+            if(fromTable == 'std' && ext && ext.priceField &&( tmp.priceProperty[ext.priceField]!= undefined && tmp.priceProperty[ext.priceField]!=null)){
+                basePrice = tmp.priceProperty[ext.priceField];
+            }
+            basePrice = scMathUtil.roundTo(basePrice,-6);
+
             // 单价文件插入的数据
             let unitPriceData = {
                 base_price: basePrice,
@@ -630,8 +641,6 @@ class GLJListModel extends BaseModel {
         if(unitPriceInsertData.length >0) await unitPriceModel.add(unitPriceInsertData);
        //插入项目工料机
         if(gljInsertData.length > 0) await this.add(gljInsertData);
-
-
         return
     }
 

+ 1 - 1
modules/main/controllers/ration_controller.js

@@ -9,7 +9,7 @@ let controller = {
     insertGLJAsRation:async function (req){
         let data = req.body.data;
         data = JSON.parse(data);
-        return await ration_glj_facade.insertGLJAsRation(data);
+        return await ration_glj_facade.insertGLJAsRation(data,req.session.sessionCompilation);
     },
     replaceRations:async function (req) {
         let data = req.body.data;

+ 38 - 8
modules/main/facade/ration_facade.js

@@ -30,7 +30,8 @@ module.exports = {
     replaceRations: replaceRations,
     addNewRation:addNewRation,
     addMultiRation: addMultiRation,
-    getSameSectionRations:getSameSectionRations
+    getSameSectionRations:getSameSectionRations,
+    getExtendData:getExtendData
 };
 async function addNewRation(data,compilation) {
     let query = data.itemQuery;
@@ -181,7 +182,7 @@ async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuanti
 
 async function addRationSubList(stdRation,newRation,needInstall,compilation) {
     let startTime = +new Date();
-    let ration_gljs = await addRationGLJ(stdRation,newRation);
+    let ration_gljs = await addRationGLJ(stdRation,newRation,compilation);
     let addRationGLJTime = +new Date();
     console.log("添加定额工料机时间-----"+(addRationGLJTime - startTime));
     let ration_coes = await addRationCoe(stdRation,newRation,compilation);
@@ -310,13 +311,38 @@ async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义
    }
 }
 
+//对于多单价,多组成物消耗量的编办,通过这个方法获取单价、组成物消耗量的字段,
+function getExtendData(property,compilation) {
+    let ext = {};
+    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;
+}
+
 
 
-async function addRationGLJ(std,newRation) {
+
+async function addRationGLJ(std,newRation,compilation) {
     let newRationGLJList = [];
     let rationGLJShowList = [];
-    let unitPriceFileId = await projectDao.getUnitPriceFileId(newRation.projectID);
-    let sum=0;
+    let unitPriceFileId = 0;
+    let property = await projectDao.getProjectProperty(newRation.projectID);
+    if(property){
+        unitPriceFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
+    }
+    let ext = getExtendData(property,compilation);
     let first = +new Date();
     if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
         let stdGLJID =[];//标准工料机ID数组
@@ -350,8 +376,12 @@ async function addRationGLJ(std,newRation) {
                 std_glj = cptGLJMap[sub.gljId];
                 newGLJ.from = 'cpt';
             }else {
-               std_glj = stdGLJMap[sub.gljId];
-               newGLJ.from = 'std';
+                std_glj = stdGLJMap[sub.gljId];
+                newGLJ.from = 'std';
+                //多单价情况处理
+                if(ext && ext.priceField && std_glj && std_glj.priceProperty){
+                    std_glj.basePrice =  std_glj.priceProperty[ext.priceField];
+                }
             }
             let std_gljTime = +new Date();
             if(std_glj){
@@ -370,7 +400,7 @@ async function addRationGLJ(std,newRation) {
                 newGLJ.materialType = std_glj.materialType;
                 newGLJ.materialCoe = std_glj.materialCoe;
                 newGLJ.createType = 'normal';
-                let info = await  ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId);
+                let info =  await  ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
                 newGLJ = ration_glj_facade.createNewRecord(info);
                 newRationGLJList.push(newGLJ);
                 rationGLJShowList.push(info);

+ 16 - 0
modules/pm/models/project_model.js

@@ -681,6 +681,22 @@ ProjectsDAO.prototype.getUnitPriceFileId = async function (projectId) {
 };
 
 /**
+ * 根据项目id获取项目property信息
+ *
+ * @param {Number} projectId
+ * @return {Promise}
+ */
+ProjectsDAO.prototype.getProjectProperty = async function (projectId) {
+    let result = null;
+    let projectData = await Projects.findOne({ID: projectId},['property']);
+    if (projectData === null) {
+        return result;
+    }
+    return projectData.property;
+};
+
+
+/**
  * 获取当前用户的建设项目数据
  *
  * @paraconsolem {Number} userId

+ 5 - 3
modules/ration_glj/controllers/ration_glj_controller.js

@@ -49,6 +49,8 @@ async function getGLJData(req, res) {
                 result.error=1;
                 result.message = err.message;
             }else {
+                //多单价字段
+                if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
                 result.datas = datas;
             }
             res.json(result);
@@ -68,7 +70,7 @@ async function addGLJ(req, res){
     try {
         let data = req.body.data;
         data = JSON.parse(data);
-        let datas= await ration_glj_facade.addGLJ(data);
+        let datas= await ration_glj_facade.addGLJ(data,req.session.sessionCompilation);
         result.data=datas;
     }catch (err){
         logger.err(err);
@@ -85,7 +87,7 @@ async function replaceGLJ(req, res){
     try {
         let data = req.body.data;
         data = JSON.parse(data);
-        let rdata= await ration_glj_facade.replaceGLJ(data);
+        let rdata= await ration_glj_facade.replaceGLJ(data,req.session.sessionCompilation);
         result.data=rdata;
     }catch (err){
         logger.err(err);
@@ -102,7 +104,7 @@ async function mReplaceGLJ(req, res){
     try {
         let data = req.body.data;
         data = JSON.parse(data);
-        let mresult= await ration_glj_facade.mReplaceGLJ(data);
+        let mresult= await ration_glj_facade.mReplaceGLJ(data,req.session.sessionCompilation);
         result.data=mresult;
     }catch (err){
         logger.err(err);

+ 25 - 12
modules/ration_glj/facade/ration_glj_facade.js

@@ -26,7 +26,7 @@ import GljDao from "../../complementary_glj_lib/models/gljModel";
 const complementaryGljModel = mongoose.model('complementary_glj_lib');
 const stdGljModel = mongoose.model('std_glj_lib_gljList');
 const gljClassModel = mongoose.model('std_glj_lib_gljClass');
-import  projCounter from '../../main/models/proj_counter_model';
+const projectDao = require('../../pm/models/project_model').project;
 
 module.exports = {
     save: save,
@@ -175,11 +175,11 @@ function createNewRecord(ration_glj) {
     return newRecoed
 }
 
-async function getInfoFromProjectGLJ(ration_glj,unitPriceFileId) {
+async function getInfoFromProjectGLJ(ration_glj,unitPriceFileId,ext) {
     let data = getGLJSearchInfo(ration_glj);
     try {
         let projectGljModel = new GLJListModel();
-        let result = await projectGljModel.addList(data,unitPriceFileId);
+        let result = await projectGljModel.addList(data,unitPriceFileId,ext);
         let typeString = result.type+"";
         ration_glj.marketPrice = result.unit_price.market_price;
         ration_glj.adjustPrice = result.unit_price.base_price;
@@ -590,12 +590,22 @@ function getGLJSearchInfo(ration_glj) {
     return data;
 }
 
+async function prepareExtData(projectID,compilation) {
+    let ext , unitFileId ;
+    let property = await projectDao.getProjectProperty(projectID);
+    ext = projectDao.getExtendData(property,compilation);
+    unitFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
+    return [unitFileId,ext];
+}
+
 
-async function addGLJ(rgList) {
+async function addGLJ(rgList,compilation) {
     let newRecodes = [];
+    if (rgList.length <= 0) return {};
+    let [unitFileId,ext] = await  prepareExtData(rgList[0].projectGLJID,compilation);
     for (let g of rgList) {
         let projectGljModel = new GLJListModel();
-        let result = await projectGljModel.addList(getGLJSearchInfo(g));
+        let result = await projectGljModel.addList(getGLJSearchInfo(g),unitFileId,ext);
         let typeString = result.type+'';
         g.marketPrice = result.unit_price.market_price;
         g.adjustPrice = result.unit_price.base_price;
@@ -625,10 +635,11 @@ async function addGLJ(rgList) {
     return result;
 }
 
-async function replaceGLJ(data) {
+async function replaceGLJ(data,compilation) {
     let rdata = {};
     let projectGljModel = new GLJListModel();
-    let result = await projectGljModel.addList(getGLJSearchInfo(data));
+    let [unitFileId,ext] = await  prepareExtData(data.projectID,compilation);
+    let result = await projectGljModel.addList(getGLJSearchInfo(data),unitFileId,ext);
     let typeString = result.type+'';
     data.projectGLJID = result.id;
 
@@ -653,10 +664,12 @@ async function replaceGLJ(data) {
     rdata.name = stateResult.rationName;
     return rdata;
 }
-async function mReplaceGLJ(data) {
+async function mReplaceGLJ(data,compilation) {
     let mresult = {};
     let projectGljModel = new GLJListModel();
-    let result = await projectGljModel.addList(getGLJSearchInfo(data.doc));
+    let [unitFileId,ext] = await prepareExtData(data.doc.projectID,compilation);
+    //
+    let result = await projectGljModel.addList(getGLJSearchInfo(data.doc),unitFileId,ext);
     let typeString = result.type+'';
     let newDoc = {};
     newDoc.projectGLJID = result.id;
@@ -771,7 +784,7 @@ async function getGLJClass(info, data) {
     return result;
 }
 
-async function insertGLJAsRation(data) {
+async function insertGLJAsRation(data,compilation) {
     let gljList = data.gljList;
     if (data.hasOwnProperty("selectedSerialNo")) { //如果需要,更新序列号。
         let query = {
@@ -781,11 +794,11 @@ async function insertGLJAsRation(data) {
         }
         await ration.update(query, {$inc: {serialNo: gljList.length}}, {multi: true});
     }
-
+    let [unitFileId,ext] = await prepareExtData(data.doc.projectID,compilation);
     for (let glj of gljList) {
         let p_glj = getGLJSearchInfo(glj);
         let projectGljModel = new GLJListModel();
-        let result = await projectGljModel.addList(p_glj);//逐条添加到项目工料机
+        let result = await projectGljModel.addList(p_glj,unitFileId,ext);//逐条添加到项目工料机
         let typeString = result.type+'';
         glj.marketPrice = result.unit_price.market_price;
         glj.adjustPrice = result.unit_price.base_price;

+ 12 - 1
web/building_saas/main/js/models/ration_glj.js

@@ -494,8 +494,19 @@ let ration_glj = {
            return node
         };
         ration_glj.prototype.getGLJData = function (cb) {
-            let engineerID = projectInfoObj.projectInfo.property.engineering_id;
+            let property = projectInfoObj.projectInfo.property;
+            let engineerID = property.engineering_id;
             CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
+                //编办中有多单价设置
+                if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
+                     let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});
+                     if(tem){
+                         let dataCode = tem.price.dataCode;
+                         for(let glj of data.datas.stdGLJ){
+                             if(glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) glj.basePrice = glj.priceProperty[dataCode];
+                         }
+                     }
+                };
                 cb(data);
             })
         };