Bläddra i källkod

update 4.4 bugs

zhangweicheng 7 år sedan
förälder
incheckning
66179b162d

+ 19 - 2
modules/glj/controllers/glj_controller.js

@@ -538,7 +538,7 @@ class GLJController extends BaseController {
         response.end('success');
     }
 
-    async  updateUnitPrice(req, res){
+    async updateUnitPrice(req, res){
         let result={
             error:0
         }
@@ -556,7 +556,24 @@ class GLJController extends BaseController {
         }
         res.json(result);
     }
-
+    async batchUpdatePrices(req, res){
+        let result={
+            error:0
+        }
+        try {
+            let data = req.body.data;
+            data = JSON.parse(data);
+            let unitPriceModel = new UnitPriceModel();
+            // 更新数据
+            let datas = await unitPriceModel.batchUpdatePrices(data);
+            result.data=datas;
+        }catch (err){
+            logger.err(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
     async modifyKeyValue(req,res){//修改工料机关键的属性:名称、类型、规格、型号等
         let result={
             error:0

+ 49 - 6
modules/glj/models/unit_price_model.js

@@ -250,12 +250,18 @@ class UnitPriceModel extends BaseModel {
 
     async updateUnitPrice(data){
         //查找并更新单价
-        let doc={};
+        let doc={},newValueMap={};
         doc[data.field]=data.newval;
+        newValueMap[data.id]=doc;
         let unitPrice = await this.db.findAndModify({id:data.id},doc);
         if(!unitPrice){
             throw "没有找到对应的单价";
         }
+        let rList= this.checkAndUpdateParent(unitPrice,data.field,data.project_id,newValueMap);
+        return rList;
+    }
+
+    async checkAndUpdateParent(unitPrice,field,project_id,newValueMap,batchUpdate=false){//检查是否属于某个工料机的组成物,如果是,并且不是批量更新的情况下,直接更新,如果是批量更新,返回更新任务
         //查找是否是属于某个项目工料机的组成物
         let mixRatioModel = new MixRatioModel();
         let condition = {unit_price_file_id:unitPrice.unit_price_file_id, code:unitPrice.code,name: unitPrice.name, specs: unitPrice.specs,unit:unitPrice.unit,type:unitPrice.type};
@@ -266,15 +272,34 @@ class UnitPriceModel extends BaseModel {
         if(mixRatioList&&mixRatioList.length>0){
             for(let m of mixRatioList){
                 if(!connectKeyMap.hasOwnProperty(m.connect_key)){//为了去重复,组成物会与其它项目同步,所以有可能重复。
-                    rList.push(await this.updateParentUnitPrice(m,data.field,data.project_id));
+                    rList.push(await this.updateParentUnitPrice(m,field,project_id,newValueMap,batchUpdate));
                     connectKeyMap[m.connect_key]=true;
                 }
             }
         }
         return rList;
     }
+    async batchUpdatePrices(data){//批量更新
+        let tasks = [];
+        let parentTask = [];
+        let newValueMap = {};
+        for(let d of data){//第一次循环生成更新提交的记录,并生成一个新值的映射表,为更新父节点使用
+            let condition = {id:d.unit_price.id};
+            let doc = {};
+            doc[d.field]=d.newval;
+            newValueMap[d.unit_price.id] = doc;
+            tasks.push(this.generateUpdateTask(condition,doc));
+        }
+        for(let d of data){//第二次更新父节点
+           let rList = await this.checkAndUpdateParent(d.unit_price,d.field,d.project_id,newValueMap,true);
+           parentTask = parentTask.concat(rList);
+        }
+        tasks = tasks.concat(parentTask);
+        tasks.length>0?this.model.bulkWrite(tasks):'';
+        return parentTask;
+    }
 
-    async updateParentUnitPrice(mixRatio,fieid,project_id){
+    async updateParentUnitPrice(mixRatio,fieid,project_id,newValueMap,batchUpdate){//batchUpdate 批量更新标记,如果true,只生成task
         let  decimalObject =await decimal_facade.getProjectDecimal(project_id);
         let quantity_decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
         let price_decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.unitPrice)?decimalObject.glj.unitPrice:2;
@@ -301,6 +326,9 @@ class UnitPriceModel extends BaseModel {
         for(let pk in priceMap){
             let price = scMathUtil.roundForObj(priceMap[pk][fieid],price_decimal);
             let consumption = scMathUtil.roundForObj(mixRatioMap[pk].consumption,quantity_decimal);
+            if(newValueMap[priceMap[pk].id]){//是需要更新的记录,取当前新的值
+                price = scMathUtil.roundForObj(newValueMap[priceMap[pk].id][fieid],price_decimal);
+            }
             sumPrice +=scMathUtil.roundForObj(price*consumption,price_decimal);
         }
         sumPrice= scMathUtil.roundForObj(sumPrice,price_decimal);
@@ -320,10 +348,25 @@ class UnitPriceModel extends BaseModel {
         }
         let doc={};
         doc[fieid]=sumPrice;
-        let uprice =  await this.db.findAndModify(pcondition,doc);
-        uprice[fieid]=sumPrice;
-        return uprice;
+        if(batchUpdate == true){
+            return this.generateUpdateTask(pcondition,doc);
+        }else {
+            let uprice =  await this.db.findAndModify(pcondition,doc,{new: true});
+            //uprice[fieid]=sumPrice;
+            return uprice;
+        }
     }
+
+    generateUpdateTask(condition,doc) {
+        let task = {
+            updateOne:{
+                filter:condition,
+                update:doc
+            }
+        };
+        return task
+}
+
     /**
      * 复制单价文件数据
      *

+ 1 - 0
modules/glj/routes/glj_router.js

@@ -22,6 +22,7 @@ router.post('/change-file', gljController.init, gljController.changeUnitPriceFil
 router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
 router.post('/get-composition', gljController.init, gljController.getComposition);
 router.post('/updatePrice', gljController.init, gljController.updateUnitPrice);
+router.post('/batchUpdatePrices', gljController.init, gljController.batchUpdatePrices);
 router.post('/modifyKeyValue',gljController.init, gljController.modifyKeyValue);
 
 router.get('/test', gljController.init, gljController.test);

+ 1 - 1
public/web/sheet/sheet_common.js

@@ -159,7 +159,7 @@ var sheetCommonObj = {
                     val =scMathUtil.roundToString(val,decimal);
                     sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
                 }else {
-                    val =scMathUtil.roundToString(val,2);
+                    val =val+'';
                 }
             }
             if(val!=null&&setting.header[col].cellType === "checkBox"){

+ 4 - 3
web/building_saas/main/js/models/fee_rate.js

@@ -209,6 +209,7 @@ var FeeRate = {
             if(socketObject.roomInfo){
                 //判断费率文件ID是否改变了
                 if(socketObject.roomInfo.feeRate == this.getActivateFeeRateFileID()){//如果没变,则是重选了标准
+                    project.markUpdateProject({projectID:project.ID(),feeRateID:this.getActivateFeeRateFileID()},"feeRate");
                     socket.emit('feeRateChangeNotify', socketObject.roomInfo.feeRate);
                 }else {
                     let data ={
@@ -216,7 +217,7 @@ var FeeRate = {
                         oldRoom:socketObject.roomInfo.feeRate,
                         newRoom:this.getActivateFeeRateFileID(),
                         name:'feeRate'
-                    }
+                    };
                     socket.emit('changeNewRoom',data);
                     socketObject.roomInfo.feeRate = this.getActivateFeeRateFileID();
                 }
@@ -274,14 +275,14 @@ var FeeRate = {
             calcProgramManage.refreshDetailSheet();
         };
         FeeRate.prototype.refreshBillsByRateID=function(rateID,value){
-            var nodes = _.filter(projectObj.project.mainTree.items,function (n) {
+            let nodes = _.filter(projectObj.project.mainTree.items,function (n) {
                 if(n.sourceType==ModuleNames.bills&&n.data.feeRateID==rateID){
                     n.data.feeRate=number_util.roundToString(value,getDecimal("feeRate"));
                     return true;
                 }else {
                     return false;
                 }
-            })
+            });
             if(nodes.length>0){
                 projectObj.mainController.refreshTreeNode(nodes)
             }

+ 63 - 3
web/building_saas/main/js/models/project_glj.js

@@ -270,7 +270,7 @@ ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb
             }
             //更新回传的父节点项目工料机价格
            let gljs = me.getProjectGLJs(data);
-            me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
+          //  me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
             projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
             gljOprObj.showRationGLJSheetData();
             me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
@@ -293,6 +293,66 @@ ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb
     }
 };
 
+ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) {
+    let me = this;
+    let projectGljs = me.datas.gljList;
+    let decimal = getDecimal('glj.unitPrice');
+    let updateData = [];
+    let newValueMap = {};
+    let gljs=[];
+    for(let ci of changeInfo){
+        let dataCode = projectGljObject.projectGljSetting.header[ci.col].dataCode;
+        let recode = projectGljObject.projectGljSheetData[ci.row];
+        if(dataCode=='basePrice'||dataCode=='marketPrice'){
+            let editField = dataCode === 'basePrice'?"base_price":"market_price";
+            let newValue= scMathUtil.roundForObj(ci.value,decimal);
+            let glj = _.find(projectGljs, {'id': recode.id});
+            if(glj&&glj.unit_price[editField]!=newValue){
+                updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
+                newValueMap[glj.id]={field:editField,value:newValue};
+                gljs.push(glj);
+            }
+        }
+    }
+    console.log(updateData);
+    if(updateData.length > 0){
+        $.bootstrapLoading.start();
+        CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
+            let parentData = [];
+            //更新缓存
+            for(let g of gljs){
+                g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
+                me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
+            }
+            //更新父工料机价格
+            for(let r of result){
+                let pdata = r.updateOne.filter;
+                let set = r.updateOne.update.$set;
+                for(let skey in set){
+                    pdata[skey] = set[skey];
+                }
+                parentData.push(pdata);
+            }
+            let pgljs = me.getProjectGLJs(parentData);
+            gljs = gljs.concat(pgljs);
+            let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
+            projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
+            gljOprObj.showRationGLJSheetData();
+            socket.emit('unitFileChangeNotify', JSON.stringify(gljs));
+            projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile");
+            if(callback){
+                callback(gljs);
+            }
+            $.bootstrapLoading.end();
+        }, function (err) {
+            $.bootstrapLoading.end();
+        });
+    }
+
+
+};
+
+
 ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
     let me = this;
     $.bootstrapLoading.start();
@@ -476,8 +536,8 @@ ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
             let glj = _.find(projectGljs, condition);
             if (glj) {
                 if(refreshPrice==true){
-                    glj.unit_price.base_price = d.base_price;
-                    glj.unit_price.market_price = d.market_price;
+                    d.base_price?glj.unit_price.base_price = d.base_price:'';
+                    d.market_price?glj.unit_price.market_price = d.market_price:'';
                     this.setAdjustPrice(glj);
                     this.refreshRationGLJPrice(glj);
                     this.refreshTreeNodePriceIfNeed(glj);

+ 6 - 2
web/building_saas/main/js/models/ration.js

@@ -374,18 +374,22 @@ var Ration = {
             }
         };
         ration.prototype.updateRationCodes = function (recodes) {
-            let libID = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
+            let libID =  rationLibObj.getCurrentStdRationLibID();
             let engineering = projectInfoObj.projectInfo.property.engineering;
             let projectID = projectInfoObj.projectInfo.ID;
             let project = projectObj.project;
             let mainTree = project.mainTree;
             let nodeInfo =[];
             let refershNodes = [];
+            if(libID == null){
+                return;
+            }
             for(let r of recodes){
                 let needInstall = false;
                 if(engineering==engineeringType.BUILD_IN) {//如果是安装工程,要看需不需要生成安装增加费
                     needInstall = project.Bills.isFBFX(r.node);
                 }
+                r.value = r.value.replace(/[\s\r\n]/g, "");//去掉空格回车换行等字符
                 nodeInfo.push({ID:r.node.data.ID,billsItemID:r.node.data.billsItemID,newCode:r.value,needInstall:needInstall});
                 refershNodes.push(r.node);
             }
@@ -503,7 +507,7 @@ var Ration = {
             projectObj.project.ration_glj.deleteByRation(ration);
             projectObj.project.ration_coe.deleteByRation(ration);
             projectObj.project.quantity_detail.deleteByRation(ration);
-            //to do 删除安装增加费
+            projectObj.project.ration_installation.deleteByRation(ration);
         };
         ration.prototype.replaceRation = function (ration, std) {
             this.project.beginUpdate('replaceRation');

+ 50 - 15
web/building_saas/main/js/views/project_glj_view.js

@@ -18,7 +18,7 @@ projectGljObject={
             {headerName: "市场价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"},
             {headerName: "是否暂估", headerWidth: 60, dataCode: "is_evaluate", hAlign: "center", dataType: "String",cellType:'checkBox'},
             {headerName: "供货方式", headerWidth: 80, dataCode: "supply", hAlign: "center", dataType: "String",cellType:'comboBox',editorValueType:true,options:supplyComboMap},
-            {headerName: "甲供数量", headerWidth: 100, dataCode: "supply_quantity", hAlign: "right", dataType: "String",validator:"number"},
+            {headerName: "甲供数量", headerWidth: 100, dataCode: "supply_quantity", hAlign: "right", dataType: "Number",validator:"number"},
             {headerName: "交货方式", headerWidth: 90, dataCode: "delivery", hAlign: "left", dataType: "String"},
             {headerName: "送达地点", headerWidth: 100, dataCode: "delivery_address", hAlign: "left", dataType: "String"},
             {headerName: "不调价", headerWidth: 55, dataCode: "is_adjust_price", dataType: "String",cellType: "checkBox"}
@@ -56,6 +56,7 @@ projectGljObject={
         this.initSheet(this.projectGljSheet,this.projectGljSetting);
         this.projectGljSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onProjectGljSelectionChange);
         this.projectGljSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onProjectGljEditStarting);
+        this.projectGljSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onProjectGljRangeChange);
         this.projectGljSheet.name('projectGljSheet');
     },
     initMixRatio:function () {
@@ -133,37 +134,71 @@ projectGljObject={
         let me = projectGljObject;
         let row = args.row;
         let col = args.col;
-        let dataCode = me.projectGljSetting.header[col].dataCode;
-        if(dataCode=='is_adjust_price'||dataCode=='is_evaluate'){
+        if(me.projectGljEditChecking(row,col)==false){
             args.cancel = true;
         }
     },
-    onProjectGljSelectionChange:function (sender, args) {
+    projectGljEditChecking:function (row,col) {//return false表示不能编码
         let me = projectGljObject;
-        let row = args.newSelections[0].row;
-        let col = args.newSelections[0].col;
         let data = me.projectGljSheetData[row];
         let dataCode = me.projectGljSetting.header[col].dataCode;
+        if(dataCode=='is_adjust_price'||dataCode=='is_evaluate'){
+            return false;
+        }
         if(dataCode=='basePrice'||dataCode=='marketPrice'||dataCode=='supply'){//有组成物时,市场单价、定额价、供货方式不能修改
-            let priceCell = false;
             if (data.ratio_data  && data.ratio_data.length > 0){
-                priceCell = true;
+               return false;
             }
-            if(priceCell==false&&dataCode=='basePrice'&&data.is_add!=1){//如果不是新增,定额价不可修改。
-                priceCell = true;
+            if(dataCode=='basePrice'&&data.is_add!=1){//如果不是新增,定额价不可修改。
+                return false;
             }
-            me.projectGljSheet.getCell(row, col,  GC.Spread.Sheets.SheetArea.viewport).locked(priceCell);
         }
         if(dataCode == 'supply_quantity'){
-            if (data.supply == 1) {// 如果为部分甲供则甲供数量需要可编辑
-                me.projectGljSheet.getCell(row, col,  GC.Spread.Sheets.SheetArea.viewport).locked(false);
-            }else {
-                me.projectGljSheet.getCell(row, col,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
+            if (data.supply != 1) {// 如果为部分甲供则甲供数量需要可编辑,其它的都不能编辑
+               return false;
             }
         }
+        return true;
+    },
+
+    onProjectGljSelectionChange:function (sender, args) {
+        let me = projectGljObject;
         me.showMixRatioData();
         me.projectGljSheet.repaint();
     },
+    onProjectGljRangeChange:function (sender,info) {
+        let me = projectGljObject;
+        let changeInfo=[];
+        let canChange = true;
+        for(let c of info.changedCells){
+            let value=  info.sheet.getCell(c.row, c.col).text();
+            changeInfo.push({row:c.row,col:c.col,value:value});
+            if(me.projectGljEditChecking(c.row,c.col)==false){//如果不能编辑
+                canChange = false;
+             }
+            if (canChange==true&&!me.checkData(c.col,me.projectGljSetting,value)) {
+                alert('输入的数据类型不对,请重新输入!');
+                canChange = false;
+            }
+        }
+        if(canChange == false){//恢复原来的值
+            console.log('1');
+            me.showProjectGljData();
+        }else {
+             me.batchUpdatePrice(changeInfo);
+        }
+    },
+    batchUpdatePrice(changeInfo){
+        let projectGLJ = projectObj.project.projectGLJ;
+        let me = projectGljObject;
+        projectGLJ.batchUpdatePrice(changeInfo,function (impactList) {
+            let selected = me.projectGljSheet.getSelections()[0];
+            me.showProjectGljData();
+            me.projectGljSheet.setSelection(selected.row,selected.col,selected.rowCount,selected.colCount);
+        });
+    },
+
+
     showProjectGljData:function () {
         let projectGljSheetData = [];
         let gljList = projectObj.project.projectGLJ.datas.gljList;

+ 12 - 0
web/building_saas/main/js/views/std_ration_lib.js

@@ -256,7 +256,19 @@ var rationLibObj = {
                 "font":"Arial"
             }
         }]
+    },
+    getCurrentStdRationLibID:function () {
+        if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
+            alert('当前项目无定额库,请添加定额库。');
+            return null;
+        }
+        if($('#stdRationLibSelect').val()){
+            return parseInt($('#stdRationLibSelect').val());
+        }else {
+            return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
+        }
     }
+
 };
 
 addEventOnResize(rationLibObj.refreshSettingForHint);