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

新的项目工料机和组成物结构

zhangweicheng 7 лет назад
Родитель
Сommit
c9bf60a427

+ 17 - 1
modules/common/base/base_model.js

@@ -61,7 +61,13 @@ class BaseModel {
         if (indexBy !== null && !singleData && result.length > 0) {
             let tmpResult = {};
             for(let tmp of result) {
-                tmpResult[tmp[indexBy]] = tmp;
+                let key="";
+                if (indexBy instanceof Array){
+                    key = this.getIndex(tmp,indexBy);
+                }else {
+                    key =tmp[indexBy]?tmp[indexBy]:"";
+                }
+                tmpResult[key] = tmp;
             }
             result = tmpResult;
         }
@@ -125,6 +131,16 @@ class BaseModel {
 
         return result.ok !== undefined && result.ok === 1;
     }
+    getIndex(obj,pops){
+        let t_index = '';
+        let k_arr=[];
+        for(let p of pops){
+            let tmpK = (obj[p]==undefined||obj[p]==null||obj[p]=='')?'null':obj[p];
+            k_arr.push(tmpK);
+        }
+        t_index=k_arr.join("|-|");
+        return t_index;
+    }
 
 }
 

+ 21 - 0
modules/glj/controllers/glj_controller.js

@@ -11,6 +11,7 @@ import GLJListModel from "../models/glj_list_model";
 import UnitPriceModel from "../models/unit_price_model";
 import MixRatioModel from "../models/mix_ratio_model";
 import UnitPriceFileModel from "../models/unit_price_file_model";
+let logger = require("../../../logs/log_helper").logger;
 
 const ProjectModel = require('../../pm/models/project_model').project;
 class GLJController extends BaseController {
@@ -565,6 +566,26 @@ class GLJController extends BaseController {
         }
         response.end('success');
     }
+
+    async  updateUnitPrice(req, res){
+        let result={
+            error:0
+        }
+        try {
+            let data = req.body.data;
+            data = JSON.parse(data);
+            let unitPriceModel = new UnitPriceModel();
+            // 更新数据
+            let datas = await unitPriceModel.updateUnitPrice(data);
+            result.data=datas;
+        }catch (err){
+            logger.err(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
+
 }
 
 export default GLJController;

+ 250 - 92
modules/glj/models/glj_list_model.js

@@ -107,47 +107,50 @@ class GLJListModel extends BaseModel {
             // 整理数据
             for (let tmp of quantityData) {
                 let tmpNum = parseFloat(tmp.rationQuantity);
-                tmpNum = isNaN(tmpNum) ? 1 : tmpNum;
+                tmpNum = isNaN(tmpNum) ||tmpNum==0? 1 : tmpNum;
                 if (quantityList[tmp.projectGLJID] === undefined) {
                     quantityList[tmp.projectGLJID] = tmp.quantity * tmpNum;
                 } else {
                     quantityList[tmp.projectGLJID] += tmp.quantity * tmpNum;
                 }
             }
-            // 整理获取有组成物的项目工料机编码
-            let projectGLJCode = [];
+            // 整理获取有组成物的项目工料机的数据
+            let connect_keys = [];
             for(let tmp of gljData) {
                 // 有组成物的类型且消耗量大于0才查找
                 if (quantityList[tmp.id] !== undefined) {
-                    projectGLJCode.push(tmp.code);
+                   let key = this.getIndex(tmp,['code','name','specs','unit','type']);
+                    connect_keys.push(key);
                 }
             }
             // 查找组成物的消耗量
             let totalComposition = {};
             let mixRatioData = {};
-            if (projectGLJCode.length > 0) {
+            if (connect_keys.length > 0) {
                 let mixRatioModel = new MixRatioModel();
-                condition = {connect_code: {"$in": projectGLJCode}, unit_price_file_id: unitPriceFileId};
+                condition = {connect_key: {"$in": connect_keys}, unit_price_file_id: unitPriceFileId};
                 let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
                 for (let tmp of mixRatioList) {
-                    totalComposition[tmp.connect_code] = totalComposition[tmp.connect_code] === undefined ? tmp.consumption :
-                        totalComposition[tmp.connect_code] + tmp.consumption;
-                    totalComposition[tmp.connect_code] = scMathUtil.roundTo(totalComposition[tmp.connect_code], -4);
-
-                    if (mixRatioData[tmp.glj_id] !== undefined) {
-                        mixRatioData[tmp.glj_id].push(tmp);
+                   let t_index = tmp.connect_key;
+                    let consumption=parseFloat(tmp.consumption);
+                    totalComposition[t_index] = totalComposition[t_index] === undefined ? consumption :
+                        totalComposition[t_index] + consumption;
+                    totalComposition[t_index] = scMathUtil.roundTo(totalComposition[t_index], -4);
+
+                    if (mixRatioData[t_index] !== undefined) {
+                        mixRatioData[t_index].push(tmp);
                     } else {
-                        mixRatioData[tmp.glj_id] = [tmp];
+                        mixRatioData[t_index] = [tmp];
                     }
-                    if(mixRationMap[tmp.connect_code]!=undefined){
-                        mixRationMap[tmp.connect_code].push(tmp);
+                    if(mixRationMap[t_index]!=undefined){
+                        mixRationMap[t_index].push(tmp);
                     }else {
-                        mixRationMap[tmp.connect_code]=[tmp];
+                        mixRationMap[t_index]=[tmp];
                     }
                     if (mixRatioConnectData[tmp.glj_id] !== undefined) {
-                        mixRatioConnectData[tmp.glj_id].push(tmp.connect_code);
+                        mixRatioConnectData[tmp.glj_id].push(tmp.connect_key);
                     } else {
-                        mixRatioConnectData[tmp.glj_id] = [tmp.connect_code];
+                        mixRatioConnectData[tmp.glj_id] = [tmp.connect_key];
                     }
                 }
             }
@@ -167,7 +170,6 @@ class GLJListModel extends BaseModel {
 
         return [gljData, mixRatioConnectData,mixRationMap];
     }
-
     /**
      * 组合工料机数据和单价文件数据
      *
@@ -184,8 +186,9 @@ class GLJListModel extends BaseModel {
         if (Object.keys(mixRatioData).length > 0 && Object.keys(totalComposition).length > 0) {
             for(let index in mixRatioData) {
                 for(let tmp of mixRatioData[index]) {
-                    compositionConsumption[tmp.glj_id] = compositionConsumption[tmp.glj_id] === undefined ? tmp.consumption :
-                        compositionConsumption[tmp.glj_id] + tmp.consumption;
+                    let t_index = this.getIndex(tmp,['code','name','specs','unit','type']);//取做为组成物的工料机的总消耗量
+                    compositionConsumption[t_index] = compositionConsumption[t_index] === undefined ? tmp.consumption :
+                        compositionConsumption[t_index] + tmp.consumption;
                 }
 
             }
@@ -197,44 +200,47 @@ class GLJListModel extends BaseModel {
             if (glj.code === undefined) {
                 continue;
             }
-            glj.unit_price = unitPriceList !== null && unitPriceList[glj.code + glj.name] !== undefined ? unitPriceList[glj.code + glj.name] : null;
+            let g_index = this.getIndex(glj,['code','name','specs','unit','type']);
+            glj.unit_price = unitPriceList !== null && unitPriceList[g_index] !== undefined ? unitPriceList[g_index] : null;
 
             if (glj.unit_price === null) {
                 continue;
             }
-
             let gljId = glj.glj_id + '';
             let projectGljId = glj.id + '';
-
             // 消耗量赋值
             glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
-            glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
-            glj.quantity = compositionConsumption[gljId] !== undefined ?  glj.quantity + compositionConsumption[gljId] : glj.quantity;
+            glj.quantity = totalComposition[g_index] !== undefined ? totalComposition[g_index] : glj.quantity;
+            glj.quantity = compositionConsumption[g_index] !== undefined ?  glj.quantity + compositionConsumption[g_index] : glj.quantity;
             glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);
 
             // 组成物数据
-            gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
-
-            glj.unit_price.base_price = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
-            glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
-            // 计算调整基价
-            switch (glj.unit_price.type + '') {
-                // 人工: 调整基价=基价单价*调整系数
-                case GLJTypeConst.LABOUR:
-                    glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
-                    break;
-                // 机械类型的算法
-                case GLJTypeConst.MACHINE:
-                    console.log('机械');
-                    break;
-                // 材料、主材、设备
-                default:
-                    glj.adjust_price = glj.unit_price.base_price;
-            }
+            gljList[index].ratio_data = mixRatioData[g_index] !== undefined ? mixRatioData[g_index] : [];
+            //因为schema中设置base_price 为string 类型,所以要通过中间变量转换为数字再做计算,不然会自动变成字符串类型
+            this.getGLJPrice(glj);
             result.push(glj);
         }
         return result;
     }
+    getGLJPrice(glj){
+        let glj_basePrice = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
+        glj.unit_price.base_price = glj_basePrice;
+        glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
+        // 计算调整基价
+        switch (glj.unit_price.type + '') {
+            // 人工: 调整基价=基价单价*调整系数
+            case GLJTypeConst.LABOUR:
+                glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj_basePrice), -2);
+                break;
+            // 机械类型的算法
+            case GLJTypeConst.MACHINE:
+                console.log('机械');
+                break;
+            // 材料、主材、设备
+            default:
+                glj.adjust_price = glj.unit_price.base_price;
+        }
+    }
 
     /**
      * 新增项目工料机数据(包括新增单价文件) 定额工料机新增时调用
@@ -248,8 +254,15 @@ class GLJListModel extends BaseModel {
             if (Object.keys(data).length <= 0) {
                 throw '新增数据为空';
             }
-            // 首先查找是否有同编码同名称的工料机数据
-            let projectGljData = await this.findDataByCondition({code: data.code, project_id: data.project_id});
+            let condition={
+                code: data.code,
+                project_id: data.project_id,
+                name:data.name,
+                specs:data.specs,
+                type:data.type,
+                unit:data.unit
+            };
+            let projectGljData = await this.findDataByCondition(condition);
             let isAddProjectGLJ = false;
             // 如果找不到数据则新增
             if (!projectGljData) {
@@ -267,12 +280,17 @@ class GLJListModel extends BaseModel {
             if (unitPriceFileId <= 0) {
                 throw '没有对应的单价文件';
             }
-
+            let CompositionGLJ=[];
             // 判断类型,如果是混凝土、砂浆或者配合比则查找对应的组成物(前提是没有对应的项目工料机数据)
-            if (isAddProjectGLJ && (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
-                data.type === GLJTypeConst.MIX_RATIO || data.type === GLJTypeConst.GENERAL_MACHINE)) {
-                this.compositionInit(data, unitPriceFileId);
+            if (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
+                data.type === GLJTypeConst.MIX_RATIO || data.type === GLJTypeConst.GENERAL_MACHINE) {
+                //如果是新增
+                if(isAddProjectGLJ ){
+                    await this.compositionInit(data, unitPriceFileId);
+                }
+                CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
             }
+            projectGljData.subList=CompositionGLJ;
 
             // 新增单价文件
             let unitPriceModel = new UnitPriceModel();
@@ -319,6 +337,87 @@ class GLJListModel extends BaseModel {
     }
 
     /**
+     * 修改名称、规格型号、单位、市场单价等
+     * @param data
+     * @returns {Promise.<void>}
+     */
+    async modifyGLJ(data,ration_glj){
+        let unitPriceFileModel = new UnitPriceFileModel();
+        let unitPriceFile = await unitPriceFileModel.getDataByProject(data.project_id);
+        if (!unitPriceFile) {
+            throw '没有对应的单价文件';
+        }
+        //查找单价信息,有则返回,没有则新增并返回
+        let unitPriceFileId = unitPriceFile.id;
+        let unitPriceModel = new UnitPriceModel();
+        let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId);
+        let gljData={};
+        if(isAdd){ //如果是新增,则新增一条新的项目工料机
+            data.code = unitPriceData.code;
+            gljData  = await this.insertGLJWhenIsAdd(data,ration_glj,unitPriceFileId);
+        }else { //如果不是新增,则查找是否有对应的项目工料机,有则返回,没有则新增
+            let condition = {
+                project_id:data.project_id,
+                original_code: data.original_code,
+                name:data.name,
+                specs:data.specs,
+                type:data.type,
+                unit:data.unit
+            }
+            gljData = await this.findDataByCondition(condition,{_id: 0});
+            if(!gljData){
+                data.code = unitPriceData.code;
+                gljData  = await this.insertGLJWhenIsAdd(data,ration_glj,unitPriceFileId);
+            }
+        }
+        gljData.unit_price = unitPriceData;
+        return gljData
+    }
+
+    //修改属性后插入项目工料机
+    async insertGLJWhenIsAdd(glj,ration_glj,unitPriceFileId){
+        //新增项目工料机
+        let gljData = await this.add(glj);
+        //查看是否是有配合比的工料机类型
+        if (glj.type === GLJTypeConst.CONCRETE || glj.type === GLJTypeConst.MORTAR ||
+            glj.type === GLJTypeConst.MIX_RATIO || glj.type === GLJTypeConst.GENERAL_MACHINE){
+            // 配合比数据插入
+            let connect_key =this.getIndex(ration_glj,['code','name','specs','unit','type']);
+            let connect_key_n =this.getIndex(glj,['code','name','specs','unit','type']);
+            //先查找配合比数据是否已经存在
+            let mixRatioModel = new MixRatioModel();
+            let mixRatios_o = await mixRatioModel.findDataByCondition({connect_key: connect_key_n, unit_price_file_id: unitPriceFileId}, {_id: 0}, false);
+            if(mixRatios_o&&mixRatios_o.length>0){//已经存在,不用再插入配合比数据,直接返回
+                return gljData;
+            }
+            //不存在,则查找原始的配合比数据,并为新工料机增加配合比数据
+            let mixRatios = await mixRatioModel.findDataByCondition({connect_key: connect_key, unit_price_file_id: unitPriceFileId}, {_id: 0}, false);
+            let mixInsertResult ={};
+            if(mixRatios&&mixRatios.length>0){
+                let newMixRatioData = [];
+                for(let m of mixRatios){
+                    let tem ={
+                        consumption: m.consumption,
+                        glj_id: m.glj_id,
+                        unit_price_file_id: m.unit_price_file_id,
+                        connect_key: connect_key_n,
+                        type: m.type,
+                        code: m.code,
+                        specs:m.specs,
+                        name:m.name,
+                        unit:m.unit
+                    };
+                    newMixRatioData.push(tem);
+                }
+                mixInsertResult= mixRatioModel.add(newMixRatioData);
+            }
+        }
+        return gljData;
+
+    }
+
+
+    /**
      * 根据工料机id修改市场单价
      *
      * @param {Object} updateData
@@ -432,21 +531,25 @@ class GLJListModel extends BaseModel {
             throw '参数错误';
         }
         let fromTable = data.from === undefined ? 'std' : data.from;
-
         // 查找对应组成物的项目工料机数据
-        let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, 'name', fromTable);
+        let indexs=['code','name','specs','unit','type'];
+        let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, indexs, fromTable);
 
         // 整理配合比待插入数据
         let mixRatioInsertData = [];
         for (let tmp of compositionGljList) {
             // 配合比数据插入
+            var connect_key =this.getIndex(data,['code','name','specs','unit','type']);
             let mixRatioData = {
                 consumption: tmp.consumption,
                 glj_id: tmp.ID,
                 unit_price_file_id: unitPriceFileId,
-                connect_code: tmp.connectCode,
-                glj_type: tmp.gljType,
+                connect_key: connect_key,
+                type: tmp.gljType,
                 code: tmp.code,
+                specs:tmp.specs,
+                name:tmp.name,
+                unit:tmp.unit
             };
             mixRatioInsertData.push(mixRatioData);
         }
@@ -459,15 +562,16 @@ class GLJListModel extends BaseModel {
             throw '组成物插入单价数据失败!';
         }
         // 如果已经存在则后续操作停止
-        if(projectGljList.length === compositionGljList.length) {
-            return;
+        if(Object.getOwnPropertyNames(projectGljList).length === compositionGljList.length) {
+            return
         }
 
         // 整理插入的数据
         let gljInsertData = [];
         let unitPriceInsertData = [];
         for(let tmp of compositionGljList) {
-            if (projectGljList[tmp.name] !== undefined) {
+            let key = this.getIndex(tmp,['code','name','specs','unit','gljType']);
+            if (projectGljList[key] !== undefined) {
                 continue;
             }
             // 项目工料机插入的数据
@@ -478,24 +582,29 @@ class GLJListModel extends BaseModel {
                 name: tmp.name,
                 specs: tmp.specs,
                 unit: tmp.unit === undefined ? '' : tmp.unit,
+                type: tmp.gljType,
+                original_code:tmp.code
             };
             gljInsertData.push(gljData);
 
+            let basePrice = scMathUtil.roundTo(tmp.basePrice,-6);
             // 单价文件插入的数据
             let unitPriceData = {
-                base_price: tmp.basePrice,
+                base_price: basePrice,
                 // 初始市场价=基价
-                market_price: tmp.basePrice,
+                market_price: basePrice,
                 code: tmp.code,
                 name: tmp.name,
                 unit_price_file_id: unitPriceFileId,
                 type: tmp.gljType,
                 short_name: tmp.shortName === undefined ? '' : tmp.shortName,
                 glj_id: tmp.ID,
+                specs: tmp.specs,
+                unit: tmp.unit === undefined ? '' : tmp.unit,
+                original_code:tmp.code
             };
             unitPriceInsertData.push(unitPriceData);
         }
-
         // 整理完后开始插入数据
         let addResult = await this.add(gljInsertData);
         if (!addResult) {
@@ -508,6 +617,7 @@ class GLJListModel extends BaseModel {
             throw '组成物插入单价数据失败!';
         }
 
+        return
     }
 
     /**
@@ -521,7 +631,7 @@ class GLJListModel extends BaseModel {
         let result = [];
         try {
             // 查找对应的项目工料机数据
-            let projectGLJData = await this.getDataById(projectGLJId);
+            let projectGLJData = await this.getDataById(projectGLJId,unitPriceFileId);
 
             let allowType = [GLJTypeConst.MIX_RATIO, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR,
                 GLJTypeConst.GENERAL_MACHINE];
@@ -530,39 +640,13 @@ class GLJListModel extends BaseModel {
                 throw '找不到相关项目工料机';
             }
 
-            // 查找对应的项目工料机数据
-            let [gljData, compositionList] = await this.getCompositionGLJList(projectGLJData.glj_id, projectGLJData.project_id);
+            // 查找对应的项目工料机数据配合比,单价数据
+            let [gljData, mixRatioData,unitPriceData] = await this.getCompositionListByGLJ(projectGLJData, unitPriceFileId);
 
             if (gljData.length <= 0) {
                 throw '没有对应的组成物项目工料机';
             }
 
-            // 整理出code和name查找相关单价数据
-            let codeList = [];
-            let nameList = [];
-            let gljIdList = [];
-            for(let tmp of gljData) {
-                codeList.push(tmp.code);
-                nameList.push(tmp.name);
-                gljIdList.push(tmp.glj_id);
-            }
-
-            // 查找对应的单价数据
-            let unitPriceModel = new UnitPriceModel();
-            let condition = {code: {"$in": codeList}, name: {"$in": nameList}, unit_price_file_id: unitPriceFileId};
-            let unitPriceList = await unitPriceModel.findDataByCondition(condition, {_id: 0}, false);
-
-            // 查找对应的配合比数据
-            let mixRatioModel = new MixRatioModel();
-            condition = {glj_id: {"$in": gljIdList}, connect_code: projectGLJData.code, unit_price_file_id: unitPriceFileId};
-            let mixRatioData = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false, 'glj_id');
-
-            // 整理数据
-            let unitPriceData = {};
-            for(let tmp of unitPriceList) {
-                unitPriceData[tmp.code + tmp.name] = tmp;
-            }
-
             gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
 
             // 排序
@@ -598,25 +682,91 @@ class GLJListModel extends BaseModel {
 
         let codeList = [];
         let nameList = [];
+        let specsList= [];
+        let typeList = [];
+        let unitList = [];
         for(let tmp of componentGljList) {
             codeList.push(tmp.code);
             nameList.push(tmp.name);
+            specsList.push(tmp.specs);
+            typeList.push(tmp.gljType);
+            unitList.push(tmp.unit);
         }
 
         // 查找对应的项目工料机数据
-        let condition = {code: {"$in": codeList}, name: {"$in": nameList}, project_id: projectId};
+        let condition = {project_id: projectId,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList} };
         let gljData = await this.findDataByCondition(condition, {_id: 0}, false, indexBy);
 
         return [gljData, componentGljList];
     }
 
+    async getCompositionGLJByData(glj,unitPriceFileId){
+        let [gljData,mixRatioData,unitPriceData] = await this.getCompositionListByGLJ(glj,unitPriceFileId);
+        gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
+        return gljData;
+    }
+
+
+
+    /**
+     * 反回组成物工料机和配合比数据
+     * @param glj
+     * @param unitPriceFileId
+     * @returns {Promise.<void>}
+     */
+    async getCompositionListByGLJ(glj,unitPriceFileId){
+        let t_index = this.getIndex(glj,['code','name','specs','unit','type']);
+        // 查找对应的配合比数据
+        let mixRatioModel = new MixRatioModel();
+        let condition = {connect_key: t_index, unit_price_file_id: unitPriceFileId};
+        let mixRatios = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false);
+        let codeList = [];
+        let nameList = [];
+        let specsList= [];
+        let typeList = [];
+        let unitList = [];
+        if(mixRatios.length<=0){
+            throw  '不存在对应的组成物';
+        }
+        let mixRatioData={};
+        for(let tmp of mixRatios) {
+            codeList.push(tmp.code);
+            nameList.push(tmp.name);
+            specsList.push(tmp.specs);
+            typeList.push(tmp.type);
+            unitList.push(tmp.unit);
+            let m_index = this.getIndex(tmp,['code','name','specs','unit','type']);
+            mixRatioData[m_index]=tmp;
+        }
+        // 查找对应的项目工料机数据
+        let gcondition = {project_id: glj.project_id,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList} };
+        let gljData = await this.findDataByCondition(gcondition, {_id: 0}, false);
+
+        // 查找对应的单价数据
+        let unitPriceModel = new UnitPriceModel();
+        let ucondition = { unit_price_file_id: unitPriceFileId,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList}};
+        let unitPriceList = await unitPriceModel.findDataByCondition(ucondition, {_id: 0}, false);
+
+
+        // 整理数据
+        let unitPriceData = {};
+        for(let tmp of unitPriceList) {
+            let u_index = this.getIndex(tmp,['code','name','specs','unit','type'])
+            unitPriceData[u_index] = tmp;
+        }
+
+
+        return [gljData,mixRatioData,unitPriceData];
+
+    }
+
     /**
      * 根据条件获取对应项目工料机数据
      *
      * @param {Number} id
      * @return {Promise}
      */
-    async getDataById(id) {
+    async getDataById(id,unitPriceFileId) {
 
         // 查找对应的项目工料机数据
         let projectGLJData = await this.findDataByCondition({id: id});
@@ -626,7 +776,15 @@ class GLJListModel extends BaseModel {
 
         // 查找对应的单价数据
         let unitPriceModel = new UnitPriceModel();
-        let unitPrice = await unitPriceModel.findDataByCondition({code: projectGLJData.code, name: projectGLJData.name});
+        let condition={
+            unit_price_file_id:unitPriceFileId,
+            code: projectGLJData.code,
+            name:projectGLJData.name,
+            specs:projectGLJData.specs,
+            type:projectGLJData.type,
+            unit:projectGLJData.unit
+        }
+        let unitPrice = await unitPriceModel.findDataByCondition(condition);
 
         projectGLJData.unit_price = unitPrice;
 

+ 1 - 1
modules/glj/models/mix_ratio_model.js

@@ -35,7 +35,7 @@ class MixRatioModel extends BaseModel {
                 this.model.schema.path('glj_id').required(true);
                 this.model.schema.path('consumption').required(true);
                 this.model.schema.path('unit_price_file_id').required(true);
-                this.model.schema.path('connect_code').required(true);
+                this.model.schema.path('connect_key').required(true);
                 break;
         }
     }

+ 11 - 3
modules/glj/models/schemas/glj.js

@@ -21,6 +21,11 @@ let modelSchema = {
         type: String,
         index: true
     },
+    //原始的编码
+    original_code: {
+        type: String,
+        index: true
+    },
     // 名称
     name: {
         type: String,
@@ -62,21 +67,24 @@ let modelSchema = {
         type: Number,
         default: 1
     },
+
     // 规格型号
     specs: {
         type: String,
         default: ''
     },
+    // 类型
+    type: Number,
     // 单位
     unit: String,
     // 显示调整基价
-    adjust_price: Number,
+    adjust_price: String,
     // 显示关联单价文件的字段
     unit_price: Schema.Types.Mixed,
     // 显示关联的消耗量
-    quantity: Number,
+    quantity: String,
     // 显示组成物的消耗量
-    consumption: Number,
+    consumption: String,
     // 显示关联配合比的id
     mix_ratio_id: Number,
     // 显示关联父级工料机code(组合物用)

+ 17 - 4
modules/glj/models/schemas/mix_ratio.js

@@ -14,7 +14,7 @@ let modelSchema = {
     id: Number,
     // 消耗量(有别于总消耗,此字段记录配合比的消耗量)
     consumption: {
-        type: Number,
+        type: String,
         default: 0
     },
     // 工料机总库对应id (关联用)
@@ -24,15 +24,28 @@ let modelSchema = {
     },
     // 单价文件表id (因为选择单价文件后配合比数据也需要同步,所以记录单价文件id)
     unit_price_file_id: Number,
-    // 关联项目工料机的code 不能关联id,因为单价文件导入别的项目后项目工料机id不同
-    connect_code: {
+    // 关联项目工料机的key 不能关联id,因为单价文件导入别的项目后项目工料机id不同
+    connect_key: {
         type: String,
         index: true
     },
+    // 规格型号
+    specs: {
+        type: String,
+        default: ''
+    },
+    // 单位
+    unit: String,
+    // 名称
+    name: {
+        type: String,
+        index: true,
+        default: ''
+    },
     // 对应工料机code
     code: String,
     // 工料机类型
-    glj_type: Number
+    type: Number
 };
 let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
 export {model as default, collectionName as collectionName};

+ 20 - 3
modules/glj/models/schemas/unit_price.js

@@ -13,19 +13,31 @@ let modelSchema = {
     // 自增ID
     id: Number,
     // 基价单价
-    base_price: Number,
+    base_price: String,
     // 市场单价
-    market_price: Number,
+    market_price: String,
     // 编码
     code: {
         type: String,
         index: true
     },
+    //原始的编码
+    original_code: {
+        type: String,
+        index: true
+    },
     // 名称
     name: {
         type: String,
         index: true
     },
+    // 规格型号
+    specs: {
+        type: String,
+        default: ''
+    },
+    // 单位
+    unit: String,
     // 类型
     type: Number,
     // 类型简称
@@ -33,7 +45,12 @@ let modelSchema = {
     // 单价文件表id
     unit_price_file_id: Number,
     // 对应标准库工料机id
-    glj_id: Number
+    glj_id: Number,
+    //是否新增1为是,0为否
+    is_add:{
+        type: Number,
+        default: 0
+    }
 };
 let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
 export {model as default, collectionName as collectionName};

+ 111 - 22
modules/glj/models/unit_price_model.js

@@ -8,7 +8,10 @@
 import BaseModel from "../../common/base/base_model"
 import GLJTypeConst from "../../common/const/glj_type_const"
 import CounterModel from "./counter_model"
+import MixRatioModel from "./mix_ratio_model";
 import {default as UnitPriceSchema, collectionName as collectionName} from "./schemas/unit_price";
+import _ from "lodash";
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
 
 class UnitPriceModel extends BaseModel {
 
@@ -43,12 +46,12 @@ class UnitPriceModel extends BaseModel {
         // 整理数据
         let result = {};
         for(let tmp of unitPriceList) {
-            result[tmp.code + tmp.name] = tmp;
+            let index = this.getIndex(tmp,['code','name','specs','unit','type'])
+            result[index] = tmp;
         }
 
         return result;
     }
-
     /**
      * 设置场景
      *
@@ -78,19 +81,16 @@ class UnitPriceModel extends BaseModel {
      * @return {Promise} 返回数据以及是否新增
      */
     async addUnitPrice(data, unitPriceFileId, gljCount = 0) {
-        if (data.code === undefined || data.project_id === undefined || data.name === undefined
+        if (data.original_code===undefined||data.code === undefined || data.project_id === undefined || data.name === undefined
             || data.market_price === undefined) {
             return [null, false];
         }
-
-        // 先查找是否有同code的单价记录
-        let unitPriceData = await this.findDataByCondition({code: data.code, unit_price_file_id: unitPriceFileId}, null, false);
-
-        // 如果有记录,判断是否存在一样的市场单价,有则直接返回数据
-        data.market_price = parseFloat(data.market_price);
-        let unitPriceIndex = this.isPriceIncluded(unitPriceData, data.market_price);
-        if (unitPriceData && unitPriceIndex >= 0) {
-            return [unitPriceData[unitPriceIndex], false];
+        // 先查找是否有原始code相同的记录
+        let unitPriceData = await this.findDataByCondition({original_code: data.original_code, unit_price_file_id: unitPriceFileId}, null, false);
+        // 如果有记录,判断是否存在一样的名称,单位...等,有则直接返回数据
+        let unitPrice =  this.isPropertyInclude(unitPriceData,['name','specs','unit','type'],data);
+        if(unitPrice){
+            return [unitPrice, false];
         }
 
         // 如果不存在基价单价,则在数据源中获取
@@ -100,24 +100,25 @@ class UnitPriceModel extends BaseModel {
             data.type = firstUnitPrice.type !== undefined ? firstUnitPrice.type : 0;
         }
 
-        // 更改名称
-        if (gljCount > 0) {
-            let regular = /\(\d+\)/;
-            let changeString = '(' + gljCount + ')';
-            data.name = regular.test(data.name) ? data.name.replace(regular, changeString) :
-                data.name + changeString;
-        }
         let insertData = {
             code: data.code,
             base_price: data.base_price,
             market_price: data.market_price,
             unit_price_file_id: unitPriceFileId,
             name: data.name,
+            specs:data.specs,
+            original_code:data.original_code,
+            unit:data.unit,
             type: data.type,
             short_name: data.shortName !== undefined ? data.shortName : '',
             glj_id: data.glj_id
         };
 
+        // 如果原始编码能找到,但不存在一样的编号,名称,单位.更改 等,更改code和添加新增标记
+        if (unitPriceData&&unitPriceData.length>0) {
+            insertData.code = data.original_code+"-"+unitPriceData.length;
+            insertData.is_add=1;
+        }
         let addPriceResult = await this.add(insertData);
         return [addPriceResult, true];
     }
@@ -161,10 +162,25 @@ class UnitPriceModel extends BaseModel {
                 break;
             }
         }
-
         return index;
     }
 
+    isPropertyInclude(data,pops,obj){
+        let condition={};
+        if (data.length <= 0) {
+            return null;
+        }
+        if(pops instanceof  Array){
+            for(let p of pops){
+                if(obj[p]){
+                    condition[p]=obj[p]
+                }
+            }
+        }else {
+            condition[pops]=obj[pops]
+        }
+        return _.find(data,condition);
+    }
     /**
      * 更新市场单价
      *
@@ -183,14 +199,14 @@ class UnitPriceModel extends BaseModel {
             throw '找不到对应的单价数据';
         }
 
-        // 基价单价的计算
+       /* // 基价单价的计算-----先不考虑同步
         switch (unitPriceData.type) {
             // 主材、设备自动赋值基价单价=市场单价
             case GLJTypeConst.MAIN_MATERIAL:
             case GLJTypeConst.EQUIPMENT:
                 updateData.base_price = updateData.market_price;
                 break;
-        }
+        }*/
 
         // 额外更新数据
         if (extend !== '') {
@@ -214,6 +230,79 @@ class UnitPriceModel extends BaseModel {
         return result.ok !== undefined && result.ok === 1;
     }
 
+    async updateUnitPrice(data){
+        //查找并更新单价
+        let doc={};
+        doc[data.field]=data.newval;
+        let unitPrice = await this.db.findAndModify({id:data.id},doc);
+        if(!unitPrice){
+            throw "没有找到对应的单价";
+        }
+        //查找是否是属于某个项目工料机的组成物
+        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};
+        let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
+        let connectKeyMap={};
+        //找到则计算项目工料机组成物的价格并更新
+        let rList= [];
+        if(mixRatioList&&mixRatioList.length>0){
+            for(let m of mixRatioList){
+                if(!connectKeyMap.hasOwnProperty(m.connect_key)){//为了去重复,组成物会与其它项目同步,所以有可能重复。
+                    rList.push(await this.updateParentUnitPrice(m,data.field));
+                    connectKeyMap[m.connect_key]=true;
+                }
+            }
+        }
+        return rList;
+    }
+
+    async updateParentUnitPrice(mixRatio,fieid){
+        //查找该工料机所有组成物
+        let indexList = ['code','name','specs','unit','type'];
+        let mixRatioModel = new MixRatioModel();
+        let mixRatioMap = await mixRatioModel.findDataByCondition({unit_price_file_id:mixRatio.unit_price_file_id,connect_key:mixRatio.connect_key}, null, false,indexList);
+        //查找对应的价格
+        let codeList = [];
+        let nameList = [];
+        let specsList= [];
+        let typeList = [];
+        let unitList = [];
+        for(let mk in mixRatioMap){
+            codeList.push(mixRatioMap[mk].code);
+            nameList.push(mixRatioMap[mk].name);
+            specsList.push(mixRatioMap[mk].specs);
+            typeList.push(mixRatioMap[mk].type);
+            unitList.push(mixRatioMap[mk].unit);
+        }
+        let condition = {unit_price_file_id: mixRatio.unit_price_file_id,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList}};
+        let priceMap = await this.findDataByCondition(condition, {_id: 0}, false, indexList);
+        let sumPrice=0;
+        for(let pk in priceMap){
+            let price = parseFloat(priceMap[pk][fieid]);
+            let consumption = parseFloat(mixRatioMap[pk].consumption);
+            sumPrice +=scMathUtil.roundTo(price*consumption,-6);
+        }
+        sumPrice= scMathUtil.roundTo(sumPrice,-6);
+        if(sumPrice<=0){
+            return null;
+        }
+        //更新父价格
+        let keyList = mixRatio.connect_key.split("|-|");
+        let pcondition = {
+            unit_price_file_id:mixRatio.unit_price_file_id,
+            code:keyList[0]
+        };
+        for(let i = 1;i<keyList.length;i++){
+            if(keyList[i]!='null'){
+                pcondition[indexList[i]]=keyList[i];
+            }
+        }
+        let doc={};
+        doc[fieid]=sumPrice;
+        let uprice =  await this.db.findAndModify(pcondition,doc);
+        uprice[fieid]=sumPrice;
+        return uprice;
+    }
     /**
      * 复制单价文件数据
      *

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

@@ -21,6 +21,7 @@ router.post('/get-project-info', gljController.init, gljController.getProjectInf
 router.post('/change-file', gljController.init, gljController.changeUnitPriceFile);
 router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
 router.post('/get-composition', gljController.init, gljController.getComposition);
+router.post('/updatePrice', gljController.init, gljController.updateUnitPrice);
 
 router.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);

+ 20 - 2
modules/ration_glj/controllers/ration_glj_controller.js

@@ -12,7 +12,8 @@ module.exports={
     getGLJData:getGLJData,
     addGLJ:addGLJ,
     replaceGLJ:replaceGLJ,
-    mReplaceGLJ:mReplaceGLJ
+    mReplaceGLJ:mReplaceGLJ,
+    updateRationGLJByEdit:updateRationGLJByEdit
 }
 function createRationGLJ() {
     let gls = mongoose.model('ration_glj');
@@ -42,7 +43,6 @@ async function getGLJData(req, res) {
     }
     try {
         let info = await ration_glj_facade.getLibInfo(req);
-        console.log(info);
         ration_glj_facade.getGLJData(info,function (err,datas) {
             if(err){
                 result.error=1;
@@ -111,4 +111,22 @@ async function mReplaceGLJ(req, res){
         result.message = err.message;
     }
     res.json(result);
+}
+
+async  function updateRationGLJByEdit(req, res) {
+    let result={
+        error:0
+    }
+    try {
+        let data = req.body.data;
+        data = JSON.parse(data);
+        let uresult= await ration_glj_facade.updateRationGLJByEdit(data);
+        result.data=uresult;
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+    }
+    res.json(result);
+    
 }

+ 5 - 5
modules/ration_glj/facade/glj_calculate_facade.js

@@ -10,7 +10,7 @@ let ration = mongoose.model('ration');
 let ration_coe = mongoose.model('ration_coe');
 let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
 let glj_type_util = require('../../../public/cache/std_glj_type_util');
-
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
 
 module.exports={
     calculateQuantity:calculateQuantity,
@@ -131,7 +131,7 @@ function calculateAss(quantity,assList,glj) {
             }
         }
     }
-    return quantity;
+    return scMathUtil.roundTo(quantity,-6);
 }
 
 function generateAdjustState(glj,coeList,adjustState,index) {
@@ -187,7 +187,7 @@ function calculateTimes(ass){
     if(r){
         times=times*-1;
     }
-    return times;
+    return scMathUtil.roundTo(times,-6);
 }
 
 function calculateQuantityByCoes(quantity,coeList,glj){
@@ -197,7 +197,7 @@ function calculateQuantityByCoes(quantity,coeList,glj){
             coeQuantity = everyCoe(coeQuantity,coeList[i],glj);
         }
     }
-    return coeQuantity;
+    return scMathUtil.roundTo(coeQuantity,-6);
 }
 
 function everyCoe(quantity,coe,glj) {
@@ -213,7 +213,7 @@ function everyCoe(quantity,coe,glj) {
             }
         }
     }
-    return coeQuantity;
+    return scMathUtil.roundTo(coeQuantity,-6);
 }
 
 

+ 88 - 114
modules/ration_glj/facade/ration_glj_facade.js

@@ -32,7 +32,8 @@ module.exports={
     getGLJData:getGLJData,
     addGLJ:addGLJ,
     replaceGLJ:replaceGLJ,
-    mReplaceGLJ:mReplaceGLJ
+    mReplaceGLJ:mReplaceGLJ,
+    updateRationGLJByEdit:updateRationGLJByEdit
 }
 
 let operationMap={
@@ -41,9 +42,7 @@ let operationMap={
     'ut_delete':delete_ration_glj
 };
 let updateFunctionMap = {
-    'normalUpdate':normalUpdate,
-    'marketPriceAdjustUpdate':marketPriceAdjustUpdate,
-    'customQuantityUpdate':customQuantityUpdate
+    'normalUpdate':normalUpdate
 };
 
 
@@ -82,7 +81,7 @@ function combineQuantity(results,rations) {
     _.forEach(results,function (data) {
         let tmp = {
             projectGLJID:data.projectGLJID,
-            quantity: data.quantity
+            quantity: Number(data.quantity)
         }
         let ration=_.find(rations,{ID:data.rationID});
         if(ration){
@@ -117,6 +116,7 @@ function get_lib_glj_info(ration_glj) {
             }else if(glj){
                 ration_glj.name = glj.name;
                 ration_glj.code = glj.code;
+                ration_glj.original_code=glj.code;
                 ration_glj.unit = glj.unit;
                 ration_glj.specs = glj.specs;
                 ration_glj.basePrice = glj.basePrice;
@@ -152,6 +152,7 @@ function createNewRecord(ration_glj) {
     newRecoed.quantity=ration_glj.quantity;
     newRecoed.name = ration_glj.name;
     newRecoed.code = ration_glj.code;
+    newRecoed.original_code=ration_glj.original_code;
     newRecoed.unit = ration_glj.unit;
     newRecoed.specs = ration_glj.specs;
     newRecoed.from=ration_glj.from?ration_glj.from:undefined;
@@ -174,6 +175,9 @@ async function getInfoFromProjectGLJ(ration_glj) {
          ration_glj.basePrice=result.unit_price.base_price;
          ration_glj.projectGLJID=result.id;
          ration_glj.isEstimate=result.is_evaluate;
+         if(result.hasOwnProperty('subList')&&result.subList.length>0){
+             ration_glj.subList=getMixRatioShowDatas(result.subList);
+         }
          return ration_glj;
      } catch (err) {
          logger.err(err);
@@ -182,6 +186,28 @@ async function getInfoFromProjectGLJ(ration_glj) {
 
  }
 
+ function getMixRatioShowDatas(subList) {
+     var temRationGLJs = [];
+     for(let pg of subList){
+         var tem = {
+             code:pg.code,
+             name:pg.name,
+             specs:pg.specs,
+             unit:pg.unit,
+             shortName:pg.unit_price.short_name,
+             rationItemQuantity:pg.ratio_data.consumption,
+             basePrice:pg.unit_price.base_price,
+             marketPrice:pg.unit_price.market_price,
+             adjustPrice:pg.adjust_price,
+             isEstimate:pg.is_evaluate,
+             isMixRatio:true
+         }
+         temRationGLJs.push(tem);
+     }
+     temRationGLJs=_.sortBy(temRationGLJs,'code');
+     return temRationGLJs;
+ }
+
 function create_ration_glj(user_id,datas) {
     return function (callback) {
         let ration_glj_list=datas.ration_glj_list;
@@ -258,122 +284,15 @@ function normalUpdate(user_id,datas){
     }
 }
 
-function customQuantityUpdate(user_id,datas){
-    return function(callback) {
-        doCustomQuantityUpdate(datas).then((result)=>{
-            if(result.err){
-                callback(result.err,'');
-            }else {
-                let ration_glj_data ={
-                    moduleName:'ration_glj',
-                    data:{
-                        updateTpye:commonConsts.UT_UPDATE,
-                        quantityRefresh:true,
-                        glj_result:result.cal_result.glj_result
-                    }
-                };
-                let ration_data ={
-                    moduleName:'ration',
-                    data:{
-                        updateTpye:commonConsts.UT_UPDATE,
-                        stateRefresh:true,
-                        rationID:result.cal_result.rationID,
-                        adjustState:result.cal_result.adjustState
-                    }
-                };
-                callback(null,[ration_glj_data,ration_data]);
-            }
-        })
-    }
-}
-
 async function doCustomQuantityUpdate(datas){
-    let result = {
-        err:null
-    }
-    try{
-        await ration_glj.update(datas.query,datas.doc);
+        let result =  await ration_glj.findOneAndUpdate(datas.query,datas.doc);
         let cal_result = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.query.rationID});
-
         cal_result.glj_result.forEach(function (item) {
            if(!item.doc.hasOwnProperty('customQuantity')){
                item.doc.customQuantity=null;
            }
         });
-        result.cal_result =cal_result;
-        console.log(result);
-        return result;
-    }catch (err){
-        result.err = err;
-        console.log(err);
-        return result;
-    }
-}
-
-
-function marketPriceAdjustUpdate(user_id,datas) {
-    return function (callback) {
-        updateprojectGljAndRationGLJ(datas.query,datas.doc).then((result)=>{
-            if(result.err){
-                callback(result.err,'');
-            }else {
-                let returndata ={
-                    moduleName:'ration_glj',
-                    data:{
-                        updateTpye:commonConsts.UT_UPDATE,
-                        query:datas.query,
-                        doc:result.doc
-                    }
-                };
-                let ration_data ={
-                    moduleName:'ration',
-                    data:{
-                        updateTpye:commonConsts.UT_UPDATE,
-                        stateRefresh:true,
-                        rationID:datas.query.rationID,
-                        adjustState:result.adjustState
-                    }
-                }
-                callback(null,[returndata,ration_data]);
-            }
-        })
-
-    }
-}
-
-async function updateprojectGljAndRationGLJ(query,doc) {
-    let returnresult={};
-    try {
-        let gljListModel = new GLJListModel();
-        let temp = doc.market_price;
-        if(doc.market_price==null){
-            doc.market_price = doc.base_price;
-        }
-        delete doc.base_price;
-        let result = await gljListModel.modifyMarketPrice(doc);
-        let updateDoc ={
-            marketPrice:result.unit_price.market_price,
-            marketPriceAdjust:temp,
-            projectGLJID:result.id,
-            isEstimate:result.is_evaluate,
-            name : result.name,
-            code:result.code
-        };
-        let updateresult = await ration_glj.findOneAndUpdate(query, updateDoc);
-        let stateResult =  await glj_calculate_facade.calculateQuantity({projectID:query.projectID,rationID:query.rationID},true);
-
-         returnresult ={
-            err:null,
-            doc :updateDoc,
-            adjustState:stateResult.adjustState
-        }
-        return returnresult;
-
-        } catch (error) {
-           returnresult.err = error;
-            console.log(error);
-            return returnresult
-         }
+        return cal_result;
 }
 
 
@@ -622,6 +541,7 @@ function getGLJSearchInfo(ration_glj) {
         glj_id: ration_glj.GLJID,
         project_id: ration_glj.projectID,
         code: ration_glj.code,
+        original_code:ration_glj.original_code,
         name: ration_glj.name,
         shortName:ration_glj.shortName,
         specs: ration_glj.specs,
@@ -633,6 +553,9 @@ function getGLJSearchInfo(ration_glj) {
         repositoryId:ration_glj.repositoryId,
         from:ration_glj.from?ration_glj.from:'std'//std:标准工料机库, cpt:补充工料机库
     };
+     if(data.from=='cpt'){//从补充工料机来的数据即为新增数据
+         data.is_add = 1;
+     }
     return data;
 }
 
@@ -648,6 +571,9 @@ async function addGLJ(rgList) {
        g.projectGLJID=result.id;
        g.isEstimate=result.is_evaluate;
        g.ID=uuidV1();
+       if(result.hasOwnProperty('subList')&&result.subList.length>0){
+           g.subList=getMixRatioShowDatas(result.subList);
+       }
        newRecodes.push(createNewRecord(g));
    }
     await ration_glj.insertMany(newRecodes);
@@ -693,6 +619,54 @@ async function mReplaceGLJ(data) {
     return mresult
 }
 
+async function updateRationGLJByEdit(data) {
+    var doc = data.doc;
+    var result;
+    if(doc.hasOwnProperty('customQuantity')){
+      result = await doCustomQuantityUpdate(data)
+    }else {
+       result = await doRationGLJUpdate(data);
+    }
+    return result;
+}
+
+async function doRationGLJUpdate(data){
+    let resutl = {};
+    let doc = data.doc;
+    let priceInfo = data.priceInfo;
+    let rg =  await ration_glj.findOne(data.query);
+    let gljListModel = new GLJListModel();
+    let projectGLJ= getGLJSearchInfo(rg);
+    for(let key in doc){
+        projectGLJ[key]=doc[key]
+    }
+    projectGLJ.base_price = priceInfo.base_price;
+    projectGLJ.market_price = priceInfo.market_price;
+    let projcetGLJ_n = await gljListModel.modifyGLJ(projectGLJ,rg);
+    doc.code = projcetGLJ_n.code;
+    doc.projectGLJID=projcetGLJ_n.id;
+    if(projcetGLJ_n.unit_price.is_add==1){
+        doc.createType='replace';
+        doc.rcode=projcetGLJ_n.original_code;
+    }else {
+        doc.createType='normal';
+        doc.rcode='';
+    }
+    await ration_glj.findOneAndUpdate(data.query,doc);
+    //取价格
+    gljListModel.getGLJPrice(projcetGLJ_n);
+    doc.basePrice=projcetGLJ_n.unit_price.base_price;
+    doc.marketPrice=projcetGLJ_n.unit_price.market_price;
+    doc.adjustPrice=projcetGLJ_n.adjust_price;
+    doc.isAdd = projcetGLJ_n.unit_price.is_add;
+    resutl.doc = doc;
+    let stateResult = await glj_calculate_facade.calculateQuantity({projectID:data.query.projectID,rationID:data.query.rationID});
+    resutl.adjustState= stateResult.adjustState;
+    return resutl;
+}
+
+
+
 async function changAdjustState(data,rationList) {
     let stateList=[];
     for(let r of rationList){

+ 8 - 4
modules/ration_glj/models/ration_glj.js

@@ -13,16 +13,20 @@ var ration_glj = new Schema({
     projectGLJID:Number,
     name:String,
     code:String,
+    //原始的编码
+    original_code: {
+        type: String,
+        index: true
+    },
     rcode:String,
     specs:String,
     unit:String,
     shortName:String,
     billsItemID: Number,
     type:Number,
-    quantity:Number,
-    customQuantity:Number,
-    rationItemQuantity:Number,
-    marketPriceAdjust:Number,
+    quantity:String,
+    customQuantity:String,
+    rationItemQuantity:String,
     createType: {type: String,default:'normal'},//normal、add、replace  正常、添加工料机、替换工料机
     from:{type: String,default:'std'}//std, cpt  来自标准工料机库、补充工料机库
 },{versionKey:false});

+ 1 - 0
modules/ration_glj/routes/ration_glj_route.js

@@ -12,6 +12,7 @@ module.exports = function (app) {
     rgRouter.post('/addGLJ',rgController.addGLJ);
     rgRouter.post('/replaceGLJ',rgController.replaceGLJ);
     rgRouter.post('/mReplaceGLJ',rgController.mReplaceGLJ);
+    rgRouter.post('/updateRationGLJByEdit',rgController.updateRationGLJByEdit);
     app.use('/rationGlj',rgRouter);
 }
 

+ 1 - 0
web/building_saas/glj/js/composition.js

@@ -26,6 +26,7 @@ $(document).ready(function() {
 
             // 筛选数据显示(显示混凝土、砂浆、配合比)
             projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO]);
+
             projectGLJSheet.selectRow(projectGLJSpread.firstMixRatioRow);
             projectGLJId = projectGLJSheet.getActiveDataByField('id');
 

+ 10 - 2
web/building_saas/glj/js/composition_spread.js

@@ -46,12 +46,20 @@ CompositionSpread.prototype.init = function(target) {
     let codeColumn = this.sheetObj.getFieldColumn('code');
     let unitColumn = this.sheetObj.getFieldColumn('unit');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
-
+    let basePriceCol = this.sheetObj.getFieldColumn('unit_price.base_price');
+    let adjustPriceCol = this.sheetObj.getFieldColumn('adjust_price');
+    let marketPriceCol = this.sheetObj.getFieldColumn('unit_price.market_price');
     // 居中样式
     let centerStyleSetting = {hAlign: 1};
     this.sheetObj.setStyle(-1, codeColumn, centerStyleSetting);
     this.sheetObj.setStyle(-1, unitColumn, centerStyleSetting);
 
+    //靠右设置
+    let rightStyleSetting={hAlign: 2};
+    this.sheetObj.setStyle(-1, basePriceCol, rightStyleSetting);
+    this.sheetObj.setStyle(-1, adjustPriceCol, rightStyleSetting);
+    this.sheetObj.setStyle(-1, marketPriceCol, rightStyleSetting);
+    this.sheetObj.setStyle(-1, consumptionColumn, rightStyleSetting);
 
     // 设置可编辑列
     this.sheetObj.setColumnEditable(consumptionColumn);
@@ -125,7 +133,7 @@ CompositionSpread.prototype.getRatioData = function(projectGLJid) {
         success: function(response) {
             if (response.err === 0) {
                 response.data = JSON.parse(response.data);
-
+                console.log(response.data);
                 // 设置数据
                 self.sheetObj.setData(response.data);
                 self.specialColumn(response.data);

+ 16 - 10
web/building_saas/glj/js/project_glj.js

@@ -205,16 +205,7 @@ function init() {
         if (jsonData.length <= 0) {
             // 赋值
             jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
-            if (jsonData.length > 0) {
-                // 不显示消耗量为0的数据
-                let tmpData = [];
-                for(let data of jsonData) {
-                    if (data.quantity !== 0) {
-                        tmpData.push(data);
-                    }
-                }
-                jsonData = tmpData;
-            }
+            jsonData= filterProjectGLJ(jsonData);
             mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
             mixRatioMap = data.mixRatioMap !== undefined ? data.mixRatioMap : mixRatioMap;
             host = data.constData.hostname !== undefined ? data.constData.hostname : '';
@@ -355,3 +346,18 @@ function socketInit() {
         $("#notify").slideDown('fast');
     });
 }
+
+//过滤消耗量为0的项目工料机
+function filterProjectGLJ(jsonData) {
+    if (jsonData.length > 0) {
+        // 不显示消耗量为0的数据
+        let tmpData = [];
+        for(let data of jsonData) {
+            if (data.quantity !== 0&&data.quantity !=='0') {
+                tmpData.push(data);
+            }
+        }
+        jsonData = tmpData;
+    }
+    return jsonData;
+}

+ 7 - 2
web/building_saas/glj/js/project_glj_spread.js

@@ -261,6 +261,11 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             // 锁定该单元格
             activeSheet.getCell(rowCounter, isEvaluateColumn, GC.Spread.Sheets.SheetArea.viewport).locked(true);
             activeSheet.setValue(rowCounter, isEvaluateColumn, '');
+        }else {
+            let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
+            activeSheet.setCellType(rowCounter, isEvaluateColumn, checkBox, GC.Spread.Sheets.SheetArea.viewport);
+            activeSheet.getCell(rowCounter, isEvaluateColumn, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+            activeSheet.setValue(rowCounter, isEvaluateColumn, data.is_evaluate);
         }
         // 设置供货方式列是否可选
         if (this.supplyReadonlyType.indexOf(data.unit_price.type) >= 0) {
@@ -393,14 +398,14 @@ ProjectGLJSpread.prototype.priceCalculate = function(info) {
     // 获取类型
     let type = activeSheet.getValue(row, typeColumn);
 
-    // 基价单价计算
+  /*  // 基价单价计算
     switch (type) {
         // 主材、设备自动赋值基价单价=市场单价
         case GLJTypeConst.MAIN_MATERIAL:
         case GLJTypeConst.EQUIPMENT:
             activeSheet.setValue(info.row, basePriceColumn, info.newValue);
             break;
-    }
+    }*/
 
     // 调整基价计算
     switch (type) {

+ 88 - 1
web/building_saas/main/js/models/project_glj.js

@@ -133,6 +133,93 @@ ProjectGLJ.prototype.loadCacheData = function() {
         return;
     }
     jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
+    jsonData=filterProjectGLJ(jsonData);
     projectGLJSheet.setData(jsonData);
     projectGLJSpread.specialColumn(jsonData);
-};
+};
+
+ProjectGLJ.prototype.updatePriceFromRG=function(recode,updateField,newval){
+    if(updateField=='marketPrice'){
+        this.updateBasePriceFromRG(recode,"market_price",newval);
+    }
+    if(updateField=='basePrice'){
+        this.updateBasePriceFromRG(recode,"base_price",newval);
+    }
+};
+
+ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
+    let me = this;
+    let projectGljs = this.datas.gljList;
+    let glj = _.find(projectGljs,{'id':recode.projectGLJID});
+    if(glj){
+        let data = {id:glj.unit_price.id,field:updateField,newval:newval};
+        let callback =function (data) {
+            if(updateField=='base_price'){
+                glj.unit_price.base_price=newval;
+                me.setAdjustPrice(glj);
+                me.refreshRationGLJPrice(glj);
+            }else {
+                glj.unit_price.market_price=newval;
+            }
+            //更新项目工料机价格
+            me.refreshProjectGLJPrice(data);
+            gljOprObj.showRationGLJSheetData();
+            $.bootstrapLoading.end();
+        }
+        $.bootstrapLoading.start();
+        CommonAjax.post("/glj/updatePrice",data,callback,function (err) {
+            $.bootstrapLoading.end();
+        });
+    }else {
+        gljOprObj.showRationGLJSheetData();
+    }
+}
+
+ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
+    for(let ration_glj of gljOprObj.sheetData){
+        if(ration_glj.projectGLJID ==glj.id){
+            ration_glj.basePrice=glj.unit_price.base_price;
+            ration_glj.marketPrice=glj.unit_price.market_price;
+            ration_glj.adjustPrice=glj.adjust_price;
+        }
+    }
+
+
+}
+ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
+    let projectGljs = this.datas.gljList;
+    let indexList = ['code','name','specs','unit','type'];
+    for(let d of data){
+        if(d){
+            let condition = {};
+            for(let index of indexList){
+                if(d[index]!=null&&d[index]!=undefined&&d[index]!=''){
+                    condition[index]=d[index]
+                }
+            }
+            let glj = _.find(projectGljs,condition);
+            if(glj){
+                glj.unit_price.base_price = d.base_price;
+                glj.unit_price.market_price = d.market_price;
+                this.setAdjustPrice(glj);
+                this.refreshRationGLJPrice(glj);
+            }
+        }
+    }
+}
+
+ProjectGLJ.prototype.setAdjustPrice=function(glj){
+    switch (glj.unit_price.type + '') {
+        // 人工: 调整基价=基价单价*调整系数
+        case GLJTypeConst.LABOUR:
+            glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
+            break;
+        // 机械类型的算法
+        case GLJTypeConst.MACHINE:
+            console.log('机械');
+            break;
+        // 材料、主材、设备
+        default:
+            glj.adjust_price = glj.unit_price.base_price;
+    }
+}

+ 41 - 39
web/building_saas/main/js/models/ration_glj.js

@@ -106,7 +106,7 @@ var ration_glj = {
             }else {
                 projectObj.project.ration_glj.datas = neRecodes;
             }
-            gljOprObj.showRationGLJSheetData();
+            gljOprObj.showRationGLJSheetData(true);
         };
         ration_glj.prototype.refreshAfterUpdate=function(data){
             var me = this;
@@ -117,7 +117,7 @@ var ration_glj = {
             }else {
                 me.refreshEachItme(data.doc,data.query);
             }
-            gljOprObj.showRationGLJSheetData();
+            gljOprObj.showRationGLJSheetData(true);
         };
         ration_glj.prototype.refreshEachItme = function (doc,query) {
             var glj_list = projectObj.project.ration_glj.datas;
@@ -268,50 +268,52 @@ var ration_glj = {
             updateData.push(newobj);
             return updateData;
         };
-        ration_glj.prototype.customQuantityUpdate = function(recode,newVal,text){
-            newVal = _.round(newVal,3);
+        ration_glj.prototype.updateRationGLJByEdit=function (recode,updateField,newval) {
+            var me=this;
+            $.bootstrapLoading.start();
+            var callback=function (data) {
+                if(updateField=='customQuantity'){
+                    me.refreshAfterQuantityUpdate(data);
+                }else {
+                    var doc = data.doc;
+                    for(var key in doc){
+                        recode[key] = doc[key];
+                    }
+                    if(data.hasOwnProperty('adjustState')){//更新定额调整状态
+                        me.updateRationAdjustState(data.adjustState);
+                    }
+                }
+                gljOprObj.showRationGLJSheetData();
+                projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
+                    $.bootstrapLoading.end();
+                });
+            }
             var query = {
                 'ID':recode.ID,
                 'projectID': recode.projectID,
                 'rationID':recode.rationID
             };
-            var doc;
-            if(text===null){
-                doc ={
-                    customQuantity:null
-                };
-            }else {
-                doc ={
-                    customQuantity:newVal,
-                    quantity:newVal
-                };
+            var priceInfo={
+                base_price: recode.basePrice,
+                market_price: recode.marketPrice
             }
-
-
-            var updateData = this.getUpdateData('ut_update',query,doc,'customQuantityUpdate');
-            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
-
+            var doc = {};
+            doc[updateField]=newval;
+            CommonAjax.post("/rationGlj/updateRationGLJByEdit",{query:query,doc:doc,priceInfo:priceInfo},callback,function (err) {
+                $.bootstrapLoading.end();
+            });
+        }
+        ration_glj.prototype.refreshAfterQuantityUpdate=function (data) {
+            var me=this;
+            data.glj_result.forEach(function (item) {
+                me.refreshEachItme(item.doc,item.query);
+            })
+            me.updateRationAdjustState(data.adjustState);
         };
-        ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal,text) {
-            newVal = _.round(newVal,2);
-            if(text===null){
-                newVal=null;
-            }
-            var query = {
-                'ID':recode.ID,
-                'projectID': recode.projectID,
-                'rationID':recode.rationID
-            };
-            var doc ={
-                base_price:Number(recode.basePrice),
-                market_price:newVal,
-                code:recode.code,
-                name:recode.name,
-                project_id:recode.projectID,
-                repositoryId:recode.repositoryId
-            };
-            var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
-            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
+        ration_glj.prototype.updateRationAdjustState=function(adjustState){
+            var selected = projectObj.project.mainTree.selected;
+            selected.data.adjustState=adjustState;
+            projectObj.mainController.refreshTreeNode([selected]);
         };
         ration_glj.prototype.getGLJData = function(cb){
             CommonAjax.get('/rationGlj/getGLJData', function (data) {

+ 1 - 1
web/building_saas/main/js/views/calc_program_manage.js

@@ -33,7 +33,7 @@ let rationPM = {
         ],
         view:{
             comboBox:[],
-            lockColumns:[0,1,2,3,5,6],
+            lockColumns:[0,1,2,4,5,6],
             colHeaderHeight: CP_Col_Width.colHeader,
             rowHeaderWidth: CP_Col_Width.rowHeader
         }

+ 74 - 42
web/building_saas/main/js/views/glj_view.js

@@ -17,6 +17,10 @@ var gljOprObj = {
     GLJSelection:[],
     parentNodeIds:{},
     activeTab:'#linkGLJ',
+    decimalSetting:{
+        marketPrice:2,
+        customQuantity:3
+    },
     setting: {
         header: [
             {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
@@ -30,13 +34,12 @@ var gljOprObj = {
             {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
             {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
             {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
-            {headerName: "市场单价调整", headerWidth: 80, dataCode: "marketPriceAdjust", dataType: "Number", hAlign: "right",formatter:"0.00"},
             {headerName: "是否暂估", headerWidth: 80, dataCode: "isEstimate", dataType: "String", hAlign: "center",vAlign:"center",cellType:"checkBox"}
         ],
         view: {
             comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
             lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
-            lockColumns:[0,1,2,3,4,5,7,8,9,10,12]
+            lockColumns:[0,4,5,7,8,9,11]
         },
         notEditedType: ['砼','桨','配比','机']
     },
@@ -231,15 +234,7 @@ var gljOprObj = {
             me.sheet.getCell(args.row, args.col).value(null);
             return;
         }
-        var ration_glj = projectObj.project.ration_glj;
-        var updateFunction =null;
-        if(me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
-            updateFunction = ration_glj.marketPriceAdjustUpdate;
-        }
-        if(me.setting.header[args.col].dataCode=='customQuantity'){//自定义消耗量
-            updateFunction = ration_glj.customQuantityUpdate;
-        }
-        me.updateRationGLJ(args,updateFunction);
+        me.updateRationGLJ(args);
     },
     onEditAssSheet:function(args){
         var me = gljOprObj;
@@ -302,15 +297,7 @@ var gljOprObj = {
         if(args.row>=me.sheetData.length){
             return;
         }
-        if(me.setting.header[args.col]&&me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
-            var type = me.sheetData[args.row].shortName;
-            var index= _.indexOf(me.setting.notEditedType,type);
-            if(index!=-1){
-                me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(true);
-            }else {
-                me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-            }
-        }
+        me.editChecking(args);
     },
     onCoeCellClick:function (sender,args) {
         var me = gljOprObj;
@@ -427,6 +414,25 @@ var gljOprObj = {
         return result;
 
     },
+    editChecking:function (args) {
+        var me = gljOprObj;
+        var header = me.setting.header;
+        var disable = null;
+        if(header[args.col]&&header[args.col].dataCode=='marketPrice'){
+            var type = me.sheetData[args.row].shortName;
+            var index= _.indexOf(me.setting.notEditedType,type);
+            disable=index==-1?false:true;
+        }
+        if(header[args.col]&&header[args.col].dataCode=='basePrice'){
+            var isAdd= me.sheetData[args.row].isAdd;
+            var type_b = me.sheetData[args.row].shortName;
+            var index_b= _.indexOf(me.setting.notEditedType,type);
+            disable=isAdd==1&&index_b==-1?false:true
+        }
+        if(disable!=null){
+            me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
+        }
+    },
     addDropDownList:function () {
         var sheet = this.coeSheet;
         sheet.suspendPaint();
@@ -528,8 +534,8 @@ var gljOprObj = {
         }
     },
     showRationGLJSheetData:function (init) {
-        this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true);
         if(init){
+            this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true);
             this.sheetData=_.sortBy(this.sheetData,'type');
             this.addMixRatioToShow();
             this.initRationTree();
@@ -560,12 +566,13 @@ var gljOprObj = {
     },
     addMixRatioToShow:function () {
         var newList=[];
-      for(var i =0;i<this.sheetData.length;i++){
-          newList.push(this.sheetData[i]);
-          if(this.sheetData[i].hasOwnProperty('subList')){
+        _.remove(this.sheetData,{'isMixRatio':true});
+        for(var i =0;i<this.sheetData.length;i++){
+            newList.push(this.sheetData[i]);
+            if(this.sheetData[i].hasOwnProperty('subList')){
                 newList = newList.concat(this.sheetData[i].subList);
-          }
-      }
+            }
+        }
         this.sheetData= newList;
     },
     combineWithProjectGlj:function (ration_gljs) {
@@ -580,8 +587,10 @@ var gljOprObj = {
                     ration_gljs[i].marketPrice=glj.unit_price.market_price;
                     ration_gljs[i].adjustPrice=glj.adjust_price;
                     ration_gljs[i].isEstimate=glj.is_evaluate;
-                    if(mixRatioMap.hasOwnProperty(glj.code)){
-                        var mixRatios = this.getMixRationShowDatas(mixRatioMap[glj.code],projectGljs);
+                    ration_gljs[i].isAdd=glj.unit_price.is_add;
+                    var connect_index = this.getIndex(glj,['code','name','specs','unit','type'])
+                    if(mixRatioMap.hasOwnProperty(connect_index)){
+                        var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index],projectGljs);
                         ration_gljs[i].subList = mixRatios;
                     }
                 }
@@ -589,11 +598,22 @@ var gljOprObj = {
         }
         return ration_gljs;
     },
+    getIndex(obj,pops){
+        let t_index = '';
+        let k_arr=[];
+        for(let p of pops){
+            let tmpK = (obj[p]==undefined||obj[p]==null||obj[p]=='')?'null':obj[p];
+            k_arr.push(tmpK);
+        }
+        t_index=k_arr.join("|-|");
+        return t_index;
+    },
     getMixRationShowDatas:function (mixRatioList,projectGljs) {
         var temRationGLJs = [];
         for(var i =0;i<mixRatioList.length;i++){
-            var pg =  _.find(projectGljs,{'code':mixRatioList[i].code});
+            var pg =  _.find(projectGljs,{'code':mixRatioList[i].code,'name':mixRatioList[i].name,'specs':mixRatioList[i].specs,'type':mixRatioList[i].type,'unit':mixRatioList[i].unit});//改关联关系
             var tem = {
+                projectGLJID:pg.id,
                 code:pg.code,
                 name:pg.name,
                 specs:pg.specs,
@@ -605,7 +625,8 @@ var gljOprObj = {
                 marketPrice:pg.unit_price.market_price,
                 adjustPrice:pg.adjust_price,
                 isEstimate:pg.is_evaluate,
-                isMixRatio:true
+                isMixRatio:true,
+                isAdd:pg.unit_price.is_add
             }
             temRationGLJs.push(tem);
         }
@@ -669,20 +690,31 @@ var gljOprObj = {
     lockRationGLJCell:function(){
         sheetCommonObj.lockCells(this.sheet,this.setting);
     },*/
-    updateRationGLJ:function (args,updateFunction) {
-        if(!updateFunction){
-            return
-        }
-        var me = gljOprObj;
-        var newval = this.numberValueChecking(args.editingText);
+    updateRationGLJ:function (args) {
+        var me=this;
+        var updateField = me.setting.header[args.col].dataCode;
         var recode = me.sheetData[args.row];
-        if(args.editingText===null){
-            updateFunction.apply(projectObj.project.ration_glj,[recode,null,args.editingText]);
-        }else if(newval!=null){
-            updateFunction.apply(projectObj.project.ration_glj,[recode,newval,args.editingText]);
+        var newval;
+        if(updateField=='marketPrice'||updateField=='customQuantity'||updateField=='basePrice'){
+            newval = number_util.checkNumberValue(args.editingText,this.decimalSetting[updateField]);
+            if(!newval){
+                me.sheet.getCell(args.row, args.col).value(recode[updateField]);
+                return;
+            }
         }else {
-            newval = recode[me.setting.header[args.col].dataCode];
-            me.sheet.getCell(args.row, args.col).value(newval);
+             if(updateField=='name'||updateField=='unit'){
+                 if(args.editingText===null){
+                     alert(me.setting.header[args.col].headerName +'不能为空!');
+                     me.sheet.getCell(args.row, args.col).value(recode[updateField]);
+                     return;
+                 }
+             }
+            newval=args.editingText==null?"":args.editingText;
+        }
+        if(updateField=='marketPrice'||updateField=='basePrice'){
+            projectObj.project.projectGLJ.updatePriceFromRG(recode,updateField,newval);
+        } else {
+            projectObj.project.ration_glj.updateRationGLJByEdit(recode,updateField,newval);
         }
     },
     updateRationAss:function (args) {