|
|
@@ -165,9 +165,10 @@ class UnitPriceModel extends BaseModel {
|
|
|
let counterModel = new CounterModel();
|
|
|
if (data instanceof Array) {
|
|
|
// 如果是批量新增
|
|
|
- for(let tmp in data) {
|
|
|
+ await this.setIDfromCounter(collectionName,data);
|
|
|
+ /* for(let tmp in data) {
|
|
|
data[tmp].id = await counterModel.getId(collectionName);
|
|
|
- }
|
|
|
+ } */
|
|
|
} else {
|
|
|
data.id = await counterModel.getId(collectionName);
|
|
|
}
|
|
|
@@ -432,7 +433,7 @@ class UnitPriceModel extends BaseModel {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- let gljList = await gljListModel.find({'project_id':projectId});
|
|
|
+ let gljList = await gljListModel.find({'project_id':projectId}).lean();
|
|
|
let gljMap = {};//用来记录glj的映射表,本项目有使用的工料机才需要copy过去
|
|
|
for(let g of gljList){
|
|
|
let g_index = this.getIndex(g,['code','name','specs','unit','type']);
|
|
|
@@ -468,10 +469,9 @@ class UnitPriceModel extends BaseModel {
|
|
|
delete tmp.id;
|
|
|
tmp.unit_price_file_id = changeUnitPriceId;
|
|
|
insertData.push(tmp);
|
|
|
- gljMap[t_index].copy = true;//复制标记,用于组成物,材料计算等的复制
|
|
|
}
|
|
|
}
|
|
|
- let uResult = insertData.length > 0 ? this.add(insertData) : true;
|
|
|
+ let uResult = insertData.length > 0 ? await this.add(insertData) : true;
|
|
|
let mixRatioModel = new MixRatioModel();
|
|
|
let mResult = await mixRatioModel.copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap);//复制组成物
|
|
|
let cResult = await this.copyMaterialNotExist(currentUnitPriceId, changeUnitPriceId,gljMap);
|
|
|
@@ -488,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");
|
|
|
|
|
|
//切换后的单价文件所有的的组成物
|
|
|
@@ -501,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);
|
|
|
}
|
|
|
}
|