Procházet zdrojové kódy

材料计算_id重复bug,从其它建设项目中选择单价文件bug

zhangweicheng před 6 roky
rodič
revize
a3a4812f0c

+ 2 - 2
modules/all_models/material_calc.js

@@ -104,7 +104,7 @@ let originalSchema = {
 mongoose.model("original_calc", new Schema(originalSchema, {versionKey: false, collection: "original_calc"}));
 
 
-let userfreightSchema = {
+let userfreightSchema = mongoose.Schema({
     ID:String,
     unit_price_file_id: Number,
     connect_key: String,// 关联项目工料机的key 不能关联id,因为单价文件导入别的项目后项目工料机id不同
@@ -121,7 +121,7 @@ let userfreightSchema = {
     ration_gljs:[ration_glj],
     calcType:String,//计算方式
     materialType:String//材料类型
-};
+}, { _id: false });
 
 let user_freights = {
     ID:{type:String,index: true},

+ 24 - 11
modules/glj/facade/glj_facade.js

@@ -10,7 +10,8 @@ module.exports={ //先导出后require可以解决循环引用问题
     updateMaterialCalcTasks:updateMaterialCalcTasks,
     updateUserFreight:updateUserFreight,
     getUserFreights:getUserFreights,
-    insertElectrovalence:insertElectrovalence
+    insertElectrovalence:insertElectrovalence,
+    updateElectrovalence:updateElectrovalence
 };
 
 const mongoose = require('mongoose');
@@ -26,6 +27,7 @@ let freight_calc_model = mongoose.model('freight_calc');
 let unit_price_model = mongoose.model('unit_price');
 let user_freights_model = mongoose.model('user_freights');
 let std_glj_lib_model = mongoose.model('std_glj_lib_map');
+let com_electrovalence_model = mongoose.model('com_electrovalence');
 
 let ration_glj = require('../../ration_glj/facade/ration_glj_facade');
 const uuidV1 = require('uuid/v1');
@@ -44,7 +46,7 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
 
         let insertData = null;
         if (type > 0) {
-            let currentUnitPrice = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
+            let currentUnitPrice = await unitPriceFileModel.model.findOne({id: changeUnitPriceId}).lean();
             if (currentUnitPrice === null) {
                 throw '不存在对应单价文件';
             }
@@ -52,13 +54,12 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
             let projectData = await ProjectModel.getProject(projectId);
             let rootProjectId = projectData.property.rootProjectID !== undefined ? projectData.property.rootProjectID : 0;
 
-            insertData = JSON.parse(JSON.stringify(currentUnitPrice));
+            insertData = currentUnitPrice;
             insertData.root_project_id = rootProjectId;
             newName?insertData.name = newName:'';
             insertData.user_id = userID;
             delete insertData._id;
-            delete insertData.ID;
-            currentUnitPriceId = changeUnitPriceId; //从其它建设项目复制时,这个ID要变成被选中的来源的单价文件ID
+            delete insertData.id;
 
         }
         // 获取即将更改的单价文件信息
@@ -70,12 +71,9 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
 
         // 查找对应单价文件的项目工料机数据
         let unitPriceModel = new UnitPriceModel();
-   /*     if(type ===1){//从其它项目复制,则先复制一份数据。 后面会做复制操作了,
-            let needCopyList = await unitPriceModel.findDataByCondition({unit_price_file_id: changeUnitPriceId}, null, false);
+        if(type ===1){//从其它项目复制,则先复制一份数据。
+            let needCopyList = await unitPriceModel.model.find({unit_price_file_id: changeUnitPriceId}).lean();
             if(needCopyList){
-                // 过滤mongoose格式
-                needCopyList = JSON.stringify(needCopyList);
-                needCopyList = JSON.parse(needCopyList);
                 let copyList = [];
                 for(let n of needCopyList){
                     delete n._id;  // 删除原有id信息
@@ -85,7 +83,7 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
                 }
                 copyList.length>0 ? await unitPriceModel.add(copyList):'';
             }
-        }*/
+        }
         let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id,projectId);
         // 复制成功后更改project数据
         if (!copyResult) {
@@ -229,6 +227,21 @@ async function insertElectrovalence(data,compilationID) {
     return result;
 }
 
+//更新或新建综合电价信息
+async function updateElectrovalence(data) {
+    let elec = data["electrovalence"];
+    if(elec){
+        let actionType = elec.actionType;
+        if(actionType == "add"){
+            await com_electrovalence_model.create(elec.doc);
+        }else if(actionType == "update"){
+            await com_electrovalence_model.updateOne({'ID':elec.ID},elec.doc);
+        }
+    }
+    if(data["unitPrice"]) await updateUnitPrice(data["unitPrice"]);
+
+}
+
 
 async function updateMaterialCalcTasks(data) {
     let freightTasks = [];

+ 8 - 0
public/web/sheet/sheet_common.js

@@ -1227,5 +1227,13 @@ var sheetCommonObj = {
                 break;
         }
         return result;
+    },
+    getSelectedRecode:function (sheet,datas) {
+        let sel = sheet.getSelections()[0];
+        let srow = sel.row == -1||sel.row == ""?0:sel.row;
+        if(gljUtil.isDef(srow) && datas.length>srow){
+            return datas[srow];
+        }
+        return null;
     }
 }

+ 6 - 8
web/building_saas/main/js/views/material_calc_view.js

@@ -189,12 +189,12 @@ materialCalcObj = {
         this.freightSheet.setRowCount(0);
         this.freightDatas = this.getFreightDatas();
         sheetCommonObj.showData(this.freightSheet, this.freightSetting,this.freightDatas);
-        this.freightSheet.setRowCount(this.freightDatas+20);
+        this.freightSheet.setRowCount(this.freightDatas.length+20);
         let convCol = _.findIndex(this.freightSetting.header,{'dataCode':'conveyance'});
         sheetCommonObj.setComboBox(-1,convCol,this.freightSheet,this.conveyanceOptions,false);
         let startCol = _.findIndex(this.freightSetting.header,{'dataCode':'start'});
         let startOptions = this.getUserFreightOptions();
-        sheetCommonObj.setComboBox(-1,startCol,this.freightSheet,startOptions,false,true);
+        sheetCommonObj.setComboBox(-1,startCol,this.freightSheet,startOptions,false,true,5);
         sel.row =  oldData?_.findIndex(this.freightDatas,{'ID':oldData.ID}):sel.row ;
         this.freightSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
         this.refreshRationView();
@@ -456,6 +456,7 @@ materialCalcObj = {
                 if(key == "connect_key") doc[key] = gljUtil.getIndex(material);
                 if(key == "unit_price_file_id") doc[key] = material.unit_price.unit_price_file_id;
             }
+            delete doc._id;
             return doc;
         }
     },
@@ -711,6 +712,7 @@ materialCalcObj = {
             let user_freight = {rootProjectID:projectObj.project.projectInfo.property.rootProjectID};
             let f = {};
             for(let key in record){
+                if(key == "_id") continue;
                 f[key] = record[key];
                 if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
             }
@@ -729,6 +731,7 @@ materialCalcObj = {
         t.rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
         let f = {};
         for(let key in record){
+            if(key == "_id") continue;
             f[key] = record[key];
             if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
         }
@@ -922,12 +925,7 @@ materialCalcObj = {
        return this.getSelectedRecode(this.priceSheet,this.priceDatas)
     },
     getSelectedRecode:function (sheet,datas) {
-        let sel = sheet.getSelections()[0];
-        let srow = sel.row == -1||sel.row == ""?0:sel.row;
-        if(gljUtil.isDef(srow) && datas.length>srow){
-            return datas[srow];
-        }
-        return null;
+        return sheetCommonObj.getSelectedRecode(sheet,datas);
     }
 
 };