zhangweicheng hace 5 años
padre
commit
60f52b6a22

+ 2 - 2
modules/all_models/material_calc.js

@@ -53,7 +53,7 @@ var ration_glj = new Schema({
     from:{type: String,default:'std'}//std, cpt  来自标准工料机库、补充工料机库
 },{versionKey:false,_id: false});
 
-let ration_schema = {
+let ration_schema = new Schema({
     ID: {type: String},
     projectID: Number,
     code: String,
@@ -66,7 +66,7 @@ let ration_schema = {
     stdID:Number,
     from:String,
     rationAssList: [rationAssItemSchema]
-};
+},{versionKey:false,_id: false});
 
 
 let freightSchema = {

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

@@ -93,7 +93,7 @@ class MixRatioModel extends BaseModel {
             if(targetMap[ckey]){//如果切换后的单价文件已经存在,则不用复
                 continue;
             }
-            if(gljMap[ckey] && gljMap[ckey].copy  == true){//在本项目中有用到
+            if(gljMap[ckey]){//在本项目中有用到
                 for(let ratio of  currentMap[ckey]){
                     delete ratio._id;  // 删除原有id信息
                     delete ratio.id;

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

@@ -461,7 +461,6 @@ class UnitPriceModel extends BaseModel {
         let insertData = [];
         for (let tmp of currentUnitList) {
             let t_index = this.getIndex(tmp,['code','name','specs','unit','type']);
-            if(gljMap[t_index])  gljMap[t_index].copy = true;//复制标记,用于组成物,材料计算等的复制
             if (targetUnitList !== null && targetUnitList[t_index] !== undefined) {
                 continue;
             }
@@ -489,10 +488,7 @@ class UnitPriceModel extends BaseModel {
     async  copyCalcNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,model){
         let currentMap = {},targetMap = {}, insertData = [];
         //取原单价文件所有的原价、运费计算计录
-        let currentList = await model.find({'unit_price_file_id':currentUnitPriceId});
-        // 过滤mongoose格式
-        currentList = JSON.stringify(currentList);
-        currentList = JSON.parse(currentList);
+        let currentList = await model.find({'unit_price_file_id':currentUnitPriceId}).lean();
         currentMap = _.groupBy(currentList,"connect_key");
 
         //切换后的单价文件所有的的组成物
@@ -502,11 +498,24 @@ class UnitPriceModel extends BaseModel {
             if(targetMap[ckey]){//如果切换后已经存在,则不用复制
                 continue;
             }
-            if(gljMap[ckey] && gljMap[ckey].copy  == true){//在本项目中有用到并且复制标记为true
+            if(gljMap[ckey]){//在本项目中有用到并且复制标记为true
                 for(let c of  currentMap[ckey]){
                     delete c._id;  // 删除原有id信息
                     c.ID = uuidV1();
                     c.unit_price_file_id = changeUnitPriceId;
+                    //更改下挂的定额工料机与项目工料机的关联关系
+                    if(c.ration_gljs){
+                      for(let rg of c.ration_gljs){
+                        rg.ID = uuidV1();
+                      }
+                    }
+
+                    if(c.rations){
+                      for(let r of c.rations){
+                        r.ID = uuidV1(); 
+                      }
+                    }
+
                     insertData.push(c);
                 }
             }

+ 23 - 0
modules/pm/facade/pm_facade.js

@@ -691,6 +691,18 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
           for(let m of mList){
             m.unit_price_file_id = newFID;
             m.ID = uuidV1();
+            //自采自办的情况,项目工料机要跟着改变:
+            if(m.ration_gljs){
+              for(let rg of m.ration_gljs){
+                rg.ID = uuidV1();
+              }
+            }
+            if(m.rations){
+              for(let r of m.rations){
+                r.ID = uuidV1(); 
+              }
+            }
+
             rList.push(m);
           }
         }else{
@@ -1812,6 +1824,17 @@ async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,use
             delete o._id;
             o.unit_price_file_id = fileID;
             o.ID = uuidV1();
+            if(o.ration_gljs){
+              for(let rg of o.ration_gljs){
+                rg.ID = uuidV1();
+              }
+            }
+            if(o.rations){
+              for(let r of o.rations){
+                r.ID = uuidV1();
+              }
+            }
+
             nList.push(o)
           }
         }else{