|
@@ -14,6 +14,8 @@ import _ from "lodash";
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
let collectionName = 'unit_price';
|
|
|
let decimal_facade = require('../../main/facade/decimal_facade');
|
|
|
+let gljListModel = mongoose.model("glj_list");
|
|
|
+
|
|
|
|
|
|
class UnitPriceModel extends BaseModel {
|
|
|
|
|
@@ -329,7 +331,7 @@ class UnitPriceModel extends BaseModel {
|
|
|
* @param {Number} changeUnitPriceId
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
- async copyNotExist(currentUnitPriceId, changeUnitPriceId) {
|
|
|
+ async copyNotExist(currentUnitPriceId, changeUnitPriceId,projectId) {
|
|
|
let result = false;
|
|
|
// 首先查找原单价文件id下的数据
|
|
|
let currentUnitList = await this.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false);
|
|
@@ -340,6 +342,13 @@ class UnitPriceModel extends BaseModel {
|
|
|
currentUnitList = JSON.stringify(currentUnitList);
|
|
|
currentUnitList = JSON.parse(currentUnitList);
|
|
|
|
|
|
+ let gljList = await gljListModel.find({'project_id':projectId});
|
|
|
+ let gljMap = {};//用来记录glj的映射表,本项目有使用的工料机才需要copy过去
|
|
|
+ for(let g of gljList){
|
|
|
+ let g_index = this.getIndex(g,['code','name','specs','unit','type']);
|
|
|
+ gljMap[g_index] = g;
|
|
|
+ }
|
|
|
+
|
|
|
let codeList = [];
|
|
|
let nameList =[];
|
|
|
for (let tmp of currentUnitList) {
|
|
@@ -364,13 +373,18 @@ class UnitPriceModel extends BaseModel {
|
|
|
if (targetUnitList !== null && targetUnitList[t_index] !== undefined) {
|
|
|
continue;
|
|
|
}
|
|
|
- // 删除原有id信息
|
|
|
- delete tmp._id;
|
|
|
- delete tmp.id;
|
|
|
- tmp.unit_price_file_id = changeUnitPriceId;
|
|
|
- insertData.push(tmp);
|
|
|
+ if(gljMap[t_index]){//如果本项目有用到才复制
|
|
|
+ delete tmp._id; // 删除原有id信息
|
|
|
+ delete tmp.id;
|
|
|
+ tmp.unit_price_file_id = changeUnitPriceId;
|
|
|
+ insertData.push(tmp);
|
|
|
+ }
|
|
|
}
|
|
|
- return insertData.length > 0 ? this.add(insertData) : true;
|
|
|
+ let uResult = insertData.length > 0 ? this.add(insertData) : true;
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
+ let mResult = await mixRatioModel.copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap);//复制组成物
|
|
|
+ return uResult&&mResult;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|