浏览代码

子目关联删除相关

zhangweicheng 7 年之前
父节点
当前提交
6f643efe3d

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

@@ -59,13 +59,14 @@ let controller = {
         let applyTasks = [
             ration_facade.addMultiRation(data.rations.create,req.session.sessionCompilation),//先生成新定额
             bill_facade.createNewBills(data.bills.create),
+            ration_facade.deleteMultiRation(data.rations.delete)
         ];
         //整理更新的数据,调用一个方法更新
         updateDatas.push(data.ration_template);
         if(data.rations.update.length > 0)  prepareUpdateNodes(data.rations.update,updateDatas,"ration");
         if(data.bills.update.length > 0)  prepareUpdateNodes(data.bills.update,updateDatas,"bills");
         applyTasks.push(project_facade.updateNodes(updateDatas));
-        let [rationResult,billsResult,updates] = await Promise.all(applyTasks);
+        let [rationResult,billsResult,deleteResult,updates] = await Promise.all(applyTasks);
         return {rationResult:rationResult,billsResult:billsResult,updateDatas:updateDatas};
     },
     //更新辅助定额

+ 12 - 9
modules/main/facade/project_facade.js

@@ -1,6 +1,17 @@
 /**
  * Created by zhang on 2018/1/26.
  */
+
+module.exports = {
+    markUpdateProject:markUpdateProject,
+    removeProjectMark:removeProjectMark,
+    updateNodes:updateNodes,
+    calcInstallationFee:calcInstallationFee,
+    saveProperty: saveProperty,
+    getDefaultColSetting: getDefaultColSetting,
+    markProjectsToChange:markProjectsToChange
+};
+
 let mongoose = require('mongoose');
 let logger = require("../../../logs/log_helper").logger;
 let  projectsModel = mongoose.model('projects');
@@ -18,15 +29,7 @@ const uuidV1 = require('uuid/v1');
 const gljUtil = require('../../../public/gljUtil');
 let stdColSettingModel = mongoose.model('std_main_col_lib');
 
-module.exports = {
-    markUpdateProject:markUpdateProject,
-    removeProjectMark:removeProjectMark,
-    updateNodes:updateNodes,
-    calcInstallationFee:calcInstallationFee,
-    saveProperty: saveProperty,
-    getDefaultColSetting: getDefaultColSetting,
-    markProjectsToChange:markProjectsToChange
-};
+
 
 async function calcInstallationFee(data) {
     let result={};

+ 22 - 10
modules/main/facade/ration_facade.js

@@ -1,6 +1,20 @@
 /**
  * Created by zhang on 2018/2/9.
  */
+//先导出后require可以解决循环引用问题
+module.exports = {
+    replaceRations: replaceRations,
+    addNewRation:addNewRation,
+    addMultiRation: addMultiRation,
+    deleteMultiRation:deleteMultiRation,
+    getSameSectionRations:getSameSectionRations,
+    getExtendData:getExtendData,
+    getDefaultProgramID:getDefaultProgramID,
+    deleteSubListByQuery:deleteSubListByQuery,
+    updateCoeAdjust:updateCoeAdjust
+};
+
+
 let mongoose = require('mongoose');
 import SearchDao from '../../complementary_ration_lib/models/searchModel';
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
@@ -29,16 +43,6 @@ const projectDao = require('../../pm/models/project_model').project;
 let projectModel = mongoose.model('projects');
 const fs = require('fs');
 
-module.exports = {
-    replaceRations: replaceRations,
-    addNewRation:addNewRation,
-    addMultiRation: addMultiRation,
-    getSameSectionRations:getSameSectionRations,
-    getExtendData:getExtendData,
-    getDefaultProgramID:getDefaultProgramID,
-    deleteSubListByQuery:deleteSubListByQuery,
-    updateCoeAdjust:updateCoeAdjust
-};
 async function addNewRation(data,compilation) {
     let query = data.itemQuery;
     let stdRation = null;
@@ -72,6 +76,14 @@ async function addMultiRation(datas,compilation) {
     return rst;
 }
 
+async function deleteMultiRation(rations) {//这里是只有删除的情况,删除定额的同时删除定额下挂的其它子项目
+    if(rations.length > 0){//删除定额下的
+        let rationIDS = _.map(rations,'ID');
+        await deleteSubListByQuery({projectID:rations[0].projectID,rationID:{"$in": rationIDS}});
+        await ration_model.model.deleteMany({ID:{"$in": rationIDS}});
+    }
+}
+
 async function getSameSectionRations(data,userId,compilationId){
     //let userId
     //要先根据定额获取所属章节的ID

+ 7 - 0
web/building_saas/main/js/models/ration.js

@@ -108,6 +108,13 @@ var Ration = {
             });
             controller.sheet.getCell(selected[0].row,col).value(data[fieldName]);
         };
+        ration.prototype.getContain = function (billNode,quantity) {
+            if(billNode && billNode.data.quantity&&billNode.data.quantity!=0&&billNode.data.quantity!=""){
+                let billQuantity = scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode));
+                return scMathUtil.roundForObj(parseFloat(quantity)/billQuantity,getDecimal("process"));
+            }
+            return 0
+        };
         ration.prototype.getTempRationData = function (id, billsID, serialNo, rType,priceType) {
             let newData = {'ID': id, 'serialNo': serialNo, projectID: this.project.ID()};
             let pEngineer = projectInfoObj.projectInfo.property.projectEngineering;//量价默认使用后台设置的单位工程取费专业

+ 12 - 7
web/building_saas/main/js/views/mbzm_view.js

@@ -146,7 +146,7 @@ let mbzm_obj={
         let selected = projectObj.project.mainTree.selected;
         let template = projectObj.project.ration_template.getTemplateByRationID(selected.data.ID);
         let createLocation = $("#createLocation").val();
-        let rations = {update:[],create:[]},bills={update:[],create:[]};
+        let rations = {update:[],create:[],delete:[]},bills={update:[],create:[]};
         if(this.datas.length <= 0) return;
         for(let d of this.datas){
             if((gljUtil.isDef(d.quantity)&& parseFloat(d.quantity)>0)||(d.coe && d.coe!="0")){
@@ -231,7 +231,7 @@ let mbzm_obj={
         let mainRation = projectObj.project.mainTree.getNodeByID(referenceRationID);
         let billsID="";
         //先检查要更新的定额是否已经存在
-        let ration = this.getExistRation(data,referenceRationID,type);
+        let ration = this.getExistRation(data,referenceRationID,type,rations);
         if(ration) {//如果存在,则比较清耗量、工程量表达式是否一致
             let tem =  this.getRationData(ration,data,quantity);//取更新信息
 
@@ -244,8 +244,7 @@ let mbzm_obj={
         //定额不存在的情况下
         if(type == mbzm_obj.locateMap.AFTERRATION) {//如果是生成在主定额后面的位置
             this.createNewRationAfterMain(data,mainRation,quantity,rations);
-        }
-        if(type == mbzm_obj.locateMap.INMEASURE){//生成在措施项目下
+        }else if(type == mbzm_obj.locateMap.INMEASURE){//生成在措施项目下
             this.createNewRationInMeasure(data,mainRation,quantity,rations,bills);
         }else {
             this.createNewRationInFBFX(data,mainRation,quantity,rations,bills);
@@ -261,6 +260,7 @@ let mbzm_obj={
         if(!_.isEmpty(tem)) {
             tem.projectID = ration.projectID;
             tem.ID = ration.ID;
+            tem.contain = projectObj.project.Ration.getContain(projectObj.project.mainTree.findNode(ration.billsItemID),tem.quantity);
             return tem;
         }
         return null;
@@ -407,6 +407,8 @@ let mbzm_obj={
         newData.referenceRationID = referenceRationID;
         newData.quantity = quantity;
         newData.quantityEXP = gljUtil.isDef(data.coe) && data.coe != "0"?"MBGCL":quantity+"";
+        //这里还要生成根据清单生成含量,父清单如果是刚自动生成的,其工程量为0,含量也为0
+        newData.contain = projectObj.project.Ration.getContain(projectObj.project.mainTree.findNode(billsID),quantity);
         let temRation = this.getDefaultRationCreateData(newData,data.code,libID,isFBFX);
         return temRation;
     },
@@ -436,7 +438,7 @@ let mbzm_obj={
         }
         return quantity;
     },
-    getExistRation:function (data,referenceRationID,type) {
+    getExistRation:function (data,referenceRationID,type,updateRations) {
         let temRation = null;
         //先检查要更新的定额是否已经存在
         let rations =_.filter(projectObj.project.Ration.datas,{'referenceRationID':referenceRationID,'code':data.code});
@@ -470,6 +472,8 @@ let mbzm_obj={
                     }
                 }
             }
+            //如果没有执行到break,则说明这条定额是要被删除的
+            updateRations.delete.push({projectID:r.projectID,ID:r.ID});
         }
         return temRation;
     },
@@ -523,12 +527,13 @@ let mbzm_obj={
                         let t_times = parseInt(rnode.data.unit);
                         t_times = isNaN(t_times)?1:t_times;//工程量要乘以定额单位的倍数
                         rnode.data.quantity = scMathUtil.roundForObj(t_quantity/t_times,getDecimal('ration.quantity'));
-                        if(rnode.parent.data.quantity&&rnode.parent.data.quantity!=0&&rnode.parent.data.quantity!=""){
+                        rnode.data.contain = projectObj.project.Ration.getContain(rnode.parent,rnode.data.quantity);
+                       /* if(rnode.parent.data.quantity&&rnode.parent.data.quantity!=0&&rnode.parent.data.quantity!=""){
                             var billQuantity = scMathUtil.roundForObj(rnode.parent.data.quantity,getDecimal("quantity",node.parent));
                             rnode.data.contain = scMathUtil.roundForObj(rnode.data.quantity/billQuantity,getDecimal("process"));
                         }else {
                             rnode.data.contain=0;
-                        }
+                        }*/
                         rnode.change = true;
                         rationNodes.push(rnode)
                     }