|
@@ -107,47 +107,50 @@ class GLJListModel extends BaseModel {
|
|
|
// 整理数据
|
|
|
for (let tmp of quantityData) {
|
|
|
let tmpNum = parseFloat(tmp.rationQuantity);
|
|
|
- tmpNum = isNaN(tmpNum) ? 1 : tmpNum;
|
|
|
+ tmpNum = isNaN(tmpNum) ||tmpNum==0? 1 : tmpNum;
|
|
|
if (quantityList[tmp.projectGLJID] === undefined) {
|
|
|
quantityList[tmp.projectGLJID] = tmp.quantity * tmpNum;
|
|
|
} else {
|
|
|
quantityList[tmp.projectGLJID] += tmp.quantity * tmpNum;
|
|
|
}
|
|
|
}
|
|
|
- // 整理获取有组成物的项目工料机编码
|
|
|
- let projectGLJCode = [];
|
|
|
+ // 整理获取有组成物的项目工料机的数据
|
|
|
+ let connect_keys = [];
|
|
|
for(let tmp of gljData) {
|
|
|
// 有组成物的类型且消耗量大于0才查找
|
|
|
if (quantityList[tmp.id] !== undefined) {
|
|
|
- projectGLJCode.push(tmp.code);
|
|
|
+ let key = this.getIndex(tmp,['code','name','specs','unit','type']);
|
|
|
+ connect_keys.push(key);
|
|
|
}
|
|
|
}
|
|
|
// 查找组成物的消耗量
|
|
|
let totalComposition = {};
|
|
|
let mixRatioData = {};
|
|
|
- if (projectGLJCode.length > 0) {
|
|
|
+ if (connect_keys.length > 0) {
|
|
|
let mixRatioModel = new MixRatioModel();
|
|
|
- condition = {connect_code: {"$in": projectGLJCode}, unit_price_file_id: unitPriceFileId};
|
|
|
+ condition = {connect_key: {"$in": connect_keys}, unit_price_file_id: unitPriceFileId};
|
|
|
let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
|
|
|
for (let tmp of mixRatioList) {
|
|
|
- totalComposition[tmp.connect_code] = totalComposition[tmp.connect_code] === undefined ? tmp.consumption :
|
|
|
- totalComposition[tmp.connect_code] + tmp.consumption;
|
|
|
- totalComposition[tmp.connect_code] = scMathUtil.roundTo(totalComposition[tmp.connect_code], -4);
|
|
|
-
|
|
|
- if (mixRatioData[tmp.glj_id] !== undefined) {
|
|
|
- mixRatioData[tmp.glj_id].push(tmp);
|
|
|
+ let t_index = tmp.connect_key;
|
|
|
+ let consumption=parseFloat(tmp.consumption);
|
|
|
+ totalComposition[t_index] = totalComposition[t_index] === undefined ? consumption :
|
|
|
+ totalComposition[t_index] + consumption;
|
|
|
+ totalComposition[t_index] = scMathUtil.roundTo(totalComposition[t_index], -4);
|
|
|
+
|
|
|
+ if (mixRatioData[t_index] !== undefined) {
|
|
|
+ mixRatioData[t_index].push(tmp);
|
|
|
} else {
|
|
|
- mixRatioData[tmp.glj_id] = [tmp];
|
|
|
+ mixRatioData[t_index] = [tmp];
|
|
|
}
|
|
|
- if(mixRationMap[tmp.connect_code]!=undefined){
|
|
|
- mixRationMap[tmp.connect_code].push(tmp);
|
|
|
+ if(mixRationMap[t_index]!=undefined){
|
|
|
+ mixRationMap[t_index].push(tmp);
|
|
|
}else {
|
|
|
- mixRationMap[tmp.connect_code]=[tmp];
|
|
|
+ mixRationMap[t_index]=[tmp];
|
|
|
}
|
|
|
if (mixRatioConnectData[tmp.glj_id] !== undefined) {
|
|
|
- mixRatioConnectData[tmp.glj_id].push(tmp.connect_code);
|
|
|
+ mixRatioConnectData[tmp.glj_id].push(tmp.connect_key);
|
|
|
} else {
|
|
|
- mixRatioConnectData[tmp.glj_id] = [tmp.connect_code];
|
|
|
+ mixRatioConnectData[tmp.glj_id] = [tmp.connect_key];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -167,7 +170,6 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
return [gljData, mixRatioConnectData,mixRationMap];
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 组合工料机数据和单价文件数据
|
|
|
*
|
|
@@ -184,8 +186,9 @@ class GLJListModel extends BaseModel {
|
|
|
if (Object.keys(mixRatioData).length > 0 && Object.keys(totalComposition).length > 0) {
|
|
|
for(let index in mixRatioData) {
|
|
|
for(let tmp of mixRatioData[index]) {
|
|
|
- compositionConsumption[tmp.glj_id] = compositionConsumption[tmp.glj_id] === undefined ? tmp.consumption :
|
|
|
- compositionConsumption[tmp.glj_id] + tmp.consumption;
|
|
|
+ let t_index = this.getIndex(tmp,['code','name','specs','unit','type']);//取做为组成物的工料机的总消耗量
|
|
|
+ compositionConsumption[t_index] = compositionConsumption[t_index] === undefined ? tmp.consumption :
|
|
|
+ compositionConsumption[t_index] + tmp.consumption;
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -197,44 +200,47 @@ class GLJListModel extends BaseModel {
|
|
|
if (glj.code === undefined) {
|
|
|
continue;
|
|
|
}
|
|
|
- glj.unit_price = unitPriceList !== null && unitPriceList[glj.code + glj.name] !== undefined ? unitPriceList[glj.code + glj.name] : null;
|
|
|
+ let g_index = this.getIndex(glj,['code','name','specs','unit','type']);
|
|
|
+ glj.unit_price = unitPriceList !== null && unitPriceList[g_index] !== undefined ? unitPriceList[g_index] : null;
|
|
|
|
|
|
if (glj.unit_price === null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
let gljId = glj.glj_id + '';
|
|
|
let projectGljId = glj.id + '';
|
|
|
-
|
|
|
// 消耗量赋值
|
|
|
glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
|
|
|
- glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
|
|
|
- glj.quantity = compositionConsumption[gljId] !== undefined ? glj.quantity + compositionConsumption[gljId] : glj.quantity;
|
|
|
+ glj.quantity = totalComposition[g_index] !== undefined ? totalComposition[g_index] : glj.quantity;
|
|
|
+ glj.quantity = compositionConsumption[g_index] !== undefined ? glj.quantity + compositionConsumption[g_index] : glj.quantity;
|
|
|
glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);
|
|
|
|
|
|
// 组成物数据
|
|
|
- gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
|
|
|
-
|
|
|
- glj.unit_price.base_price = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
|
|
|
- glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
|
|
|
- // 计算调整基价
|
|
|
- switch (glj.unit_price.type + '') {
|
|
|
- // 人工: 调整基价=基价单价*调整系数
|
|
|
- case GLJTypeConst.LABOUR:
|
|
|
- glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
|
|
|
- break;
|
|
|
- // 机械类型的算法
|
|
|
- case GLJTypeConst.MACHINE:
|
|
|
- console.log('机械');
|
|
|
- break;
|
|
|
- // 材料、主材、设备
|
|
|
- default:
|
|
|
- glj.adjust_price = glj.unit_price.base_price;
|
|
|
- }
|
|
|
+ gljList[index].ratio_data = mixRatioData[g_index] !== undefined ? mixRatioData[g_index] : [];
|
|
|
+ //因为schema中设置base_price 为string 类型,所以要通过中间变量转换为数字再做计算,不然会自动变成字符串类型
|
|
|
+ this.getGLJPrice(glj);
|
|
|
result.push(glj);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ getGLJPrice(glj){
|
|
|
+ let glj_basePrice = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
|
|
|
+ glj.unit_price.base_price = glj_basePrice;
|
|
|
+ glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
|
|
|
+ // 计算调整基价
|
|
|
+ switch (glj.unit_price.type + '') {
|
|
|
+ // 人工: 调整基价=基价单价*调整系数
|
|
|
+ case GLJTypeConst.LABOUR:
|
|
|
+ glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj_basePrice), -2);
|
|
|
+ break;
|
|
|
+ // 机械类型的算法
|
|
|
+ case GLJTypeConst.MACHINE:
|
|
|
+ console.log('机械');
|
|
|
+ break;
|
|
|
+ // 材料、主材、设备
|
|
|
+ default:
|
|
|
+ glj.adjust_price = glj.unit_price.base_price;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 新增项目工料机数据(包括新增单价文件) 定额工料机新增时调用
|
|
@@ -248,8 +254,15 @@ class GLJListModel extends BaseModel {
|
|
|
if (Object.keys(data).length <= 0) {
|
|
|
throw '新增数据为空';
|
|
|
}
|
|
|
- // 首先查找是否有同编码同名称的工料机数据
|
|
|
- let projectGljData = await this.findDataByCondition({code: data.code, project_id: data.project_id});
|
|
|
+ let condition={
|
|
|
+ code: data.code,
|
|
|
+ project_id: data.project_id,
|
|
|
+ name:data.name,
|
|
|
+ specs:data.specs,
|
|
|
+ type:data.type,
|
|
|
+ unit:data.unit
|
|
|
+ };
|
|
|
+ let projectGljData = await this.findDataByCondition(condition);
|
|
|
let isAddProjectGLJ = false;
|
|
|
// 如果找不到数据则新增
|
|
|
if (!projectGljData) {
|
|
@@ -267,12 +280,17 @@ class GLJListModel extends BaseModel {
|
|
|
if (unitPriceFileId <= 0) {
|
|
|
throw '没有对应的单价文件';
|
|
|
}
|
|
|
-
|
|
|
+ let CompositionGLJ=[];
|
|
|
// 判断类型,如果是混凝土、砂浆或者配合比则查找对应的组成物(前提是没有对应的项目工料机数据)
|
|
|
- if (isAddProjectGLJ && (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
|
|
|
- data.type === GLJTypeConst.MIX_RATIO || data.type === GLJTypeConst.GENERAL_MACHINE)) {
|
|
|
- this.compositionInit(data, unitPriceFileId);
|
|
|
+ if (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
|
|
|
+ data.type === GLJTypeConst.MIX_RATIO || data.type === GLJTypeConst.GENERAL_MACHINE) {
|
|
|
+ //如果是新增
|
|
|
+ if(isAddProjectGLJ ){
|
|
|
+ await this.compositionInit(data, unitPriceFileId);
|
|
|
+ }
|
|
|
+ CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
|
|
|
}
|
|
|
+ projectGljData.subList=CompositionGLJ;
|
|
|
|
|
|
// 新增单价文件
|
|
|
let unitPriceModel = new UnitPriceModel();
|
|
@@ -319,6 +337,87 @@ class GLJListModel extends BaseModel {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 修改名称、规格型号、单位、市场单价等
|
|
|
+ * @param data
|
|
|
+ * @returns {Promise.<void>}
|
|
|
+ */
|
|
|
+ async modifyGLJ(data,ration_glj){
|
|
|
+ let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
+ let unitPriceFile = await unitPriceFileModel.getDataByProject(data.project_id);
|
|
|
+ if (!unitPriceFile) {
|
|
|
+ throw '没有对应的单价文件';
|
|
|
+ }
|
|
|
+ //查找单价信息,有则返回,没有则新增并返回
|
|
|
+ let unitPriceFileId = unitPriceFile.id;
|
|
|
+ let unitPriceModel = new UnitPriceModel();
|
|
|
+ let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId);
|
|
|
+ let gljData={};
|
|
|
+ if(isAdd){ //如果是新增,则新增一条新的项目工料机
|
|
|
+ data.code = unitPriceData.code;
|
|
|
+ gljData = await this.insertGLJWhenIsAdd(data,ration_glj,unitPriceFileId);
|
|
|
+ }else { //如果不是新增,则查找是否有对应的项目工料机,有则返回,没有则新增
|
|
|
+ let condition = {
|
|
|
+ project_id:data.project_id,
|
|
|
+ original_code: data.original_code,
|
|
|
+ name:data.name,
|
|
|
+ specs:data.specs,
|
|
|
+ type:data.type,
|
|
|
+ unit:data.unit
|
|
|
+ }
|
|
|
+ gljData = await this.findDataByCondition(condition,{_id: 0});
|
|
|
+ if(!gljData){
|
|
|
+ data.code = unitPriceData.code;
|
|
|
+ gljData = await this.insertGLJWhenIsAdd(data,ration_glj,unitPriceFileId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ gljData.unit_price = unitPriceData;
|
|
|
+ return gljData
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改属性后插入项目工料机
|
|
|
+ async insertGLJWhenIsAdd(glj,ration_glj,unitPriceFileId){
|
|
|
+ //新增项目工料机
|
|
|
+ let gljData = await this.add(glj);
|
|
|
+ //查看是否是有配合比的工料机类型
|
|
|
+ if (glj.type === GLJTypeConst.CONCRETE || glj.type === GLJTypeConst.MORTAR ||
|
|
|
+ glj.type === GLJTypeConst.MIX_RATIO || glj.type === GLJTypeConst.GENERAL_MACHINE){
|
|
|
+ // 配合比数据插入
|
|
|
+ let connect_key =this.getIndex(ration_glj,['code','name','specs','unit','type']);
|
|
|
+ let connect_key_n =this.getIndex(glj,['code','name','specs','unit','type']);
|
|
|
+ //先查找配合比数据是否已经存在
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
+ let mixRatios_o = await mixRatioModel.findDataByCondition({connect_key: connect_key_n, unit_price_file_id: unitPriceFileId}, {_id: 0}, false);
|
|
|
+ if(mixRatios_o&&mixRatios_o.length>0){//已经存在,不用再插入配合比数据,直接返回
|
|
|
+ return gljData;
|
|
|
+ }
|
|
|
+ //不存在,则查找原始的配合比数据,并为新工料机增加配合比数据
|
|
|
+ let mixRatios = await mixRatioModel.findDataByCondition({connect_key: connect_key, unit_price_file_id: unitPriceFileId}, {_id: 0}, false);
|
|
|
+ let mixInsertResult ={};
|
|
|
+ if(mixRatios&&mixRatios.length>0){
|
|
|
+ let newMixRatioData = [];
|
|
|
+ for(let m of mixRatios){
|
|
|
+ let tem ={
|
|
|
+ consumption: m.consumption,
|
|
|
+ glj_id: m.glj_id,
|
|
|
+ unit_price_file_id: m.unit_price_file_id,
|
|
|
+ connect_key: connect_key_n,
|
|
|
+ type: m.type,
|
|
|
+ code: m.code,
|
|
|
+ specs:m.specs,
|
|
|
+ name:m.name,
|
|
|
+ unit:m.unit
|
|
|
+ };
|
|
|
+ newMixRatioData.push(tem);
|
|
|
+ }
|
|
|
+ mixInsertResult= mixRatioModel.add(newMixRatioData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return gljData;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据工料机id修改市场单价
|
|
|
*
|
|
|
* @param {Object} updateData
|
|
@@ -432,21 +531,25 @@ class GLJListModel extends BaseModel {
|
|
|
throw '参数错误';
|
|
|
}
|
|
|
let fromTable = data.from === undefined ? 'std' : data.from;
|
|
|
-
|
|
|
// 查找对应组成物的项目工料机数据
|
|
|
- let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, 'name', fromTable);
|
|
|
+ let indexs=['code','name','specs','unit','type'];
|
|
|
+ let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, indexs, fromTable);
|
|
|
|
|
|
// 整理配合比待插入数据
|
|
|
let mixRatioInsertData = [];
|
|
|
for (let tmp of compositionGljList) {
|
|
|
// 配合比数据插入
|
|
|
+ var connect_key =this.getIndex(data,['code','name','specs','unit','type']);
|
|
|
let mixRatioData = {
|
|
|
consumption: tmp.consumption,
|
|
|
glj_id: tmp.ID,
|
|
|
unit_price_file_id: unitPriceFileId,
|
|
|
- connect_code: tmp.connectCode,
|
|
|
- glj_type: tmp.gljType,
|
|
|
+ connect_key: connect_key,
|
|
|
+ type: tmp.gljType,
|
|
|
code: tmp.code,
|
|
|
+ specs:tmp.specs,
|
|
|
+ name:tmp.name,
|
|
|
+ unit:tmp.unit
|
|
|
};
|
|
|
mixRatioInsertData.push(mixRatioData);
|
|
|
}
|
|
@@ -459,15 +562,16 @@ class GLJListModel extends BaseModel {
|
|
|
throw '组成物插入单价数据失败!';
|
|
|
}
|
|
|
// 如果已经存在则后续操作停止
|
|
|
- if(projectGljList.length === compositionGljList.length) {
|
|
|
- return;
|
|
|
+ if(Object.getOwnPropertyNames(projectGljList).length === compositionGljList.length) {
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// 整理插入的数据
|
|
|
let gljInsertData = [];
|
|
|
let unitPriceInsertData = [];
|
|
|
for(let tmp of compositionGljList) {
|
|
|
- if (projectGljList[tmp.name] !== undefined) {
|
|
|
+ let key = this.getIndex(tmp,['code','name','specs','unit','gljType']);
|
|
|
+ if (projectGljList[key] !== undefined) {
|
|
|
continue;
|
|
|
}
|
|
|
// 项目工料机插入的数据
|
|
@@ -478,24 +582,29 @@ class GLJListModel extends BaseModel {
|
|
|
name: tmp.name,
|
|
|
specs: tmp.specs,
|
|
|
unit: tmp.unit === undefined ? '' : tmp.unit,
|
|
|
+ type: tmp.gljType,
|
|
|
+ original_code:tmp.code
|
|
|
};
|
|
|
gljInsertData.push(gljData);
|
|
|
|
|
|
+ let basePrice = scMathUtil.roundTo(tmp.basePrice,-6);
|
|
|
// 单价文件插入的数据
|
|
|
let unitPriceData = {
|
|
|
- base_price: tmp.basePrice,
|
|
|
+ base_price: basePrice,
|
|
|
// 初始市场价=基价
|
|
|
- market_price: tmp.basePrice,
|
|
|
+ market_price: basePrice,
|
|
|
code: tmp.code,
|
|
|
name: tmp.name,
|
|
|
unit_price_file_id: unitPriceFileId,
|
|
|
type: tmp.gljType,
|
|
|
short_name: tmp.shortName === undefined ? '' : tmp.shortName,
|
|
|
glj_id: tmp.ID,
|
|
|
+ specs: tmp.specs,
|
|
|
+ unit: tmp.unit === undefined ? '' : tmp.unit,
|
|
|
+ original_code:tmp.code
|
|
|
};
|
|
|
unitPriceInsertData.push(unitPriceData);
|
|
|
}
|
|
|
-
|
|
|
// 整理完后开始插入数据
|
|
|
let addResult = await this.add(gljInsertData);
|
|
|
if (!addResult) {
|
|
@@ -508,6 +617,7 @@ class GLJListModel extends BaseModel {
|
|
|
throw '组成物插入单价数据失败!';
|
|
|
}
|
|
|
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -521,7 +631,7 @@ class GLJListModel extends BaseModel {
|
|
|
let result = [];
|
|
|
try {
|
|
|
// 查找对应的项目工料机数据
|
|
|
- let projectGLJData = await this.getDataById(projectGLJId);
|
|
|
+ let projectGLJData = await this.getDataById(projectGLJId,unitPriceFileId);
|
|
|
|
|
|
let allowType = [GLJTypeConst.MIX_RATIO, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR,
|
|
|
GLJTypeConst.GENERAL_MACHINE];
|
|
@@ -530,39 +640,13 @@ class GLJListModel extends BaseModel {
|
|
|
throw '找不到相关项目工料机';
|
|
|
}
|
|
|
|
|
|
- // 查找对应的项目工料机数据
|
|
|
- let [gljData, compositionList] = await this.getCompositionGLJList(projectGLJData.glj_id, projectGLJData.project_id);
|
|
|
+ // 查找对应的项目工料机数据配合比,单价数据
|
|
|
+ let [gljData, mixRatioData,unitPriceData] = await this.getCompositionListByGLJ(projectGLJData, unitPriceFileId);
|
|
|
|
|
|
if (gljData.length <= 0) {
|
|
|
throw '没有对应的组成物项目工料机';
|
|
|
}
|
|
|
|
|
|
- // 整理出code和name查找相关单价数据
|
|
|
- let codeList = [];
|
|
|
- let nameList = [];
|
|
|
- let gljIdList = [];
|
|
|
- for(let tmp of gljData) {
|
|
|
- codeList.push(tmp.code);
|
|
|
- nameList.push(tmp.name);
|
|
|
- gljIdList.push(tmp.glj_id);
|
|
|
- }
|
|
|
-
|
|
|
- // 查找对应的单价数据
|
|
|
- let unitPriceModel = new UnitPriceModel();
|
|
|
- let condition = {code: {"$in": codeList}, name: {"$in": nameList}, unit_price_file_id: unitPriceFileId};
|
|
|
- let unitPriceList = await unitPriceModel.findDataByCondition(condition, {_id: 0}, false);
|
|
|
-
|
|
|
- // 查找对应的配合比数据
|
|
|
- let mixRatioModel = new MixRatioModel();
|
|
|
- condition = {glj_id: {"$in": gljIdList}, connect_code: projectGLJData.code, unit_price_file_id: unitPriceFileId};
|
|
|
- let mixRatioData = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false, 'glj_id');
|
|
|
-
|
|
|
- // 整理数据
|
|
|
- let unitPriceData = {};
|
|
|
- for(let tmp of unitPriceList) {
|
|
|
- unitPriceData[tmp.code + tmp.name] = tmp;
|
|
|
- }
|
|
|
-
|
|
|
gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
|
|
|
|
|
|
// 排序
|
|
@@ -598,25 +682,91 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
let codeList = [];
|
|
|
let nameList = [];
|
|
|
+ let specsList= [];
|
|
|
+ let typeList = [];
|
|
|
+ let unitList = [];
|
|
|
for(let tmp of componentGljList) {
|
|
|
codeList.push(tmp.code);
|
|
|
nameList.push(tmp.name);
|
|
|
+ specsList.push(tmp.specs);
|
|
|
+ typeList.push(tmp.gljType);
|
|
|
+ unitList.push(tmp.unit);
|
|
|
}
|
|
|
|
|
|
// 查找对应的项目工料机数据
|
|
|
- let condition = {code: {"$in": codeList}, name: {"$in": nameList}, project_id: projectId};
|
|
|
+ let condition = {project_id: projectId,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList} };
|
|
|
let gljData = await this.findDataByCondition(condition, {_id: 0}, false, indexBy);
|
|
|
|
|
|
return [gljData, componentGljList];
|
|
|
}
|
|
|
|
|
|
+ async getCompositionGLJByData(glj,unitPriceFileId){
|
|
|
+ let [gljData,mixRatioData,unitPriceData] = await this.getCompositionListByGLJ(glj,unitPriceFileId);
|
|
|
+ gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
|
|
|
+ return gljData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 反回组成物工料机和配合比数据
|
|
|
+ * @param glj
|
|
|
+ * @param unitPriceFileId
|
|
|
+ * @returns {Promise.<void>}
|
|
|
+ */
|
|
|
+ async getCompositionListByGLJ(glj,unitPriceFileId){
|
|
|
+ let t_index = this.getIndex(glj,['code','name','specs','unit','type']);
|
|
|
+ // 查找对应的配合比数据
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
+ let condition = {connect_key: t_index, unit_price_file_id: unitPriceFileId};
|
|
|
+ let mixRatios = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false);
|
|
|
+ let codeList = [];
|
|
|
+ let nameList = [];
|
|
|
+ let specsList= [];
|
|
|
+ let typeList = [];
|
|
|
+ let unitList = [];
|
|
|
+ if(mixRatios.length<=0){
|
|
|
+ throw '不存在对应的组成物';
|
|
|
+ }
|
|
|
+ let mixRatioData={};
|
|
|
+ for(let tmp of mixRatios) {
|
|
|
+ codeList.push(tmp.code);
|
|
|
+ nameList.push(tmp.name);
|
|
|
+ specsList.push(tmp.specs);
|
|
|
+ typeList.push(tmp.type);
|
|
|
+ unitList.push(tmp.unit);
|
|
|
+ let m_index = this.getIndex(tmp,['code','name','specs','unit','type']);
|
|
|
+ mixRatioData[m_index]=tmp;
|
|
|
+ }
|
|
|
+ // 查找对应的项目工料机数据
|
|
|
+ let gcondition = {project_id: glj.project_id,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList} };
|
|
|
+ let gljData = await this.findDataByCondition(gcondition, {_id: 0}, false);
|
|
|
+
|
|
|
+ // 查找对应的单价数据
|
|
|
+ let unitPriceModel = new UnitPriceModel();
|
|
|
+ let ucondition = { unit_price_file_id: unitPriceFileId,code: {"$in": codeList}, name: {"$in": nameList},specs:{"$in": specsList},type:{"$in": typeList},unit:{"$in": unitList}};
|
|
|
+ let unitPriceList = await unitPriceModel.findDataByCondition(ucondition, {_id: 0}, false);
|
|
|
+
|
|
|
+
|
|
|
+ // 整理数据
|
|
|
+ let unitPriceData = {};
|
|
|
+ for(let tmp of unitPriceList) {
|
|
|
+ let u_index = this.getIndex(tmp,['code','name','specs','unit','type'])
|
|
|
+ unitPriceData[u_index] = tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return [gljData,mixRatioData,unitPriceData];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据条件获取对应项目工料机数据
|
|
|
*
|
|
|
* @param {Number} id
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
- async getDataById(id) {
|
|
|
+ async getDataById(id,unitPriceFileId) {
|
|
|
|
|
|
// 查找对应的项目工料机数据
|
|
|
let projectGLJData = await this.findDataByCondition({id: id});
|
|
@@ -626,7 +776,15 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
// 查找对应的单价数据
|
|
|
let unitPriceModel = new UnitPriceModel();
|
|
|
- let unitPrice = await unitPriceModel.findDataByCondition({code: projectGLJData.code, name: projectGLJData.name});
|
|
|
+ let condition={
|
|
|
+ unit_price_file_id:unitPriceFileId,
|
|
|
+ code: projectGLJData.code,
|
|
|
+ name:projectGLJData.name,
|
|
|
+ specs:projectGLJData.specs,
|
|
|
+ type:projectGLJData.type,
|
|
|
+ unit:projectGLJData.unit
|
|
|
+ }
|
|
|
+ let unitPrice = await unitPriceModel.findDataByCondition(condition);
|
|
|
|
|
|
projectGLJData.unit_price = unitPrice;
|
|
|
|