|
@@ -50,14 +50,15 @@ class MixRatioModel extends BaseModel {
|
|
|
async add(data) {
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
- return this.db.model.create(data);
|
|
|
+ return await this.db.model.create(data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -79,23 +80,20 @@ class MixRatioModel extends BaseModel {
|
|
|
}
|
|
|
|
|
|
//复制组成物到切换后的组成物映射表
|
|
|
- async copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap){
|
|
|
+ async copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap,newFile = false){
|
|
|
let currentMap = {},targetMap = {}, insertData = [];
|
|
|
//取原单价文件所有的的组成物
|
|
|
- let currentList = await this.db.find({'unit_price_file_id':currentUnitPriceId});
|
|
|
- // 过滤mongoose格式
|
|
|
- currentList = JSON.stringify(currentList);
|
|
|
- currentList = JSON.parse(currentList);
|
|
|
+ let currentList = await this.model.find({'unit_price_file_id':currentUnitPriceId}).lean();;
|
|
|
this.getConnectionMap(currentMap,currentList);
|
|
|
|
|
|
//切换后的单价文件所有的的组成物
|
|
|
- let targetList = await this.db.find({'unit_price_file_id':changeUnitPriceId});
|
|
|
+ let targetList = await this.model.find({'unit_price_file_id':changeUnitPriceId}).lean();
|
|
|
this.getConnectionMap(targetMap,targetList);
|
|
|
for(let ckey in currentMap){
|
|
|
if(targetMap[ckey]){//如果切换后的单价文件已经存在,则不用复
|
|
|
continue;
|
|
|
}
|
|
|
- if(gljMap[ckey]){//在本项目中有用到
|
|
|
+ if(gljMap[ckey] || newFile == true){//在本项目中有用到
|
|
|
for(let ratio of currentMap[ckey]){
|
|
|
delete ratio._id; // 删除原有id信息
|
|
|
delete ratio.id;
|
|
@@ -104,7 +102,7 @@ class MixRatioModel extends BaseModel {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return insertData.length > 0 ? this.add(insertData) : true;
|
|
|
+ return insertData.length > 0 ? await this.add(insertData) : true;
|
|
|
}
|
|
|
getConnectionMap(map,list){
|
|
|
for(let l of list){
|