|
@@ -250,9 +250,19 @@ class GLJListModel extends BaseModel {
|
|
|
};
|
|
|
let projectGljData = await this.findDataByCondition(condition);
|
|
|
let isAddProjectGLJ = false;
|
|
|
+
|
|
|
+ // 获取标段对应的单价文件id
|
|
|
+ let unitPriceFileId = unitFileId?unitFileId:await ProjectModel.getUnitPriceFileId(data.project_id);
|
|
|
+ if (unitPriceFileId <= 0) {
|
|
|
+ throw '没有对应的单价文件';
|
|
|
+ }
|
|
|
+
|
|
|
+ let unitPriceModel = new UnitPriceModel();
|
|
|
+
|
|
|
+ // 新增单条记录 (两个操作本来应该是事务操作,然而mongodb事务支持比较弱,就当作是都可以顺利执行)
|
|
|
+
|
|
|
// 如果找不到数据则新增
|
|
|
if (!projectGljData) {
|
|
|
- // 新增单条记录 (两个操作本来应该是事务操作,然而mongodb事务支持比较弱,就当作是都可以顺利执行)
|
|
|
let gljInsertData = await this.add(data);
|
|
|
if (!gljInsertData) {
|
|
|
throw '新增项目工料机失败!';
|
|
@@ -261,14 +271,7 @@ class GLJListModel extends BaseModel {
|
|
|
projectGljData = gljInsertData;
|
|
|
}
|
|
|
|
|
|
- // 获取标段对应的单价文件id
|
|
|
-
|
|
|
- let unitPriceFileId = unitFileId?unitFileId:await ProjectModel.getUnitPriceFileId(data.project_id);
|
|
|
- if (unitPriceFileId <= 0) {
|
|
|
- throw '没有对应的单价文件';
|
|
|
- }
|
|
|
let CompositionGLJ=[];
|
|
|
- let unitPriceModel = new UnitPriceModel();
|
|
|
// 判断类型,如果是混凝土、砂浆、配合比或者主材则查找对应的组成物(前提是没有对应的项目工料机数据)
|
|
|
if(this.ownCompositionTypes.indexOf(data.type)!=-1) {
|
|
|
//如果是新增
|
|
@@ -288,7 +291,6 @@ class GLJListModel extends BaseModel {
|
|
|
}
|
|
|
}
|
|
|
projectGljData.subList=CompositionGLJ;
|
|
|
-
|
|
|
// 新增单价文件
|
|
|
let [unitPriceInsertData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId);
|
|
|
|
|
@@ -573,36 +575,31 @@ class GLJListModel extends BaseModel {
|
|
|
throw '组成物插入单价数据失败!';
|
|
|
}
|
|
|
}
|
|
|
- let pglj_length = projectGljList instanceof Array ? projectGljList.length:Object.getOwnPropertyNames(projectGljList).length;
|
|
|
- // 如果已经存在则后续操作停止
|
|
|
- if(pglj_length === compositionGljList.length) {
|
|
|
- return
|
|
|
- }
|
|
|
+ let unitPriceModel = new UnitPriceModel();
|
|
|
+ let unitPriceList = await unitPriceModel.model.find({unit_price_file_id:unitPriceFileId});//查找按文件id查找单价文件数据,用来判断单价文件信息是否已存在
|
|
|
|
|
|
// 整理插入的数据
|
|
|
let gljInsertData = [];
|
|
|
let unitPriceInsertData = [];
|
|
|
for(let tmp of compositionGljList) {
|
|
|
let key = this.getIndex(tmp,['code','name','specs','unit','gljType']);
|
|
|
- if (projectGljList[key] !== undefined) {
|
|
|
- continue;
|
|
|
+ if (projectGljList[key] === undefined) {
|
|
|
+ // 项目工料机插入的数据
|
|
|
+ let gljData = {
|
|
|
+ glj_id: tmp.ID,
|
|
|
+ project_id: projectId,
|
|
|
+ code: tmp.code,
|
|
|
+ name: tmp.name,
|
|
|
+ specs: tmp.specs,
|
|
|
+ unit: tmp.unit === undefined ? '' : tmp.unit,
|
|
|
+ type: tmp.gljType,
|
|
|
+ adjCoe:tmp.adjCoe,
|
|
|
+ original_code:tmp.code,
|
|
|
+ materialType: tmp.materialType, //三材类别
|
|
|
+ materialCoe: tmp.materialCoe
|
|
|
+ };
|
|
|
+ gljInsertData.push(gljData);
|
|
|
}
|
|
|
- // 项目工料机插入的数据
|
|
|
- let gljData = {
|
|
|
- glj_id: tmp.ID,
|
|
|
- project_id: projectId,
|
|
|
- code: tmp.code,
|
|
|
- name: tmp.name,
|
|
|
- specs: tmp.specs,
|
|
|
- unit: tmp.unit === undefined ? '' : tmp.unit,
|
|
|
- type: tmp.gljType,
|
|
|
- adjCoe:tmp.adjCoe,
|
|
|
- original_code:tmp.code,
|
|
|
- materialType: tmp.materialType, //三材类别
|
|
|
- materialCoe: tmp.materialCoe
|
|
|
- };
|
|
|
- gljInsertData.push(gljData);
|
|
|
-
|
|
|
let basePrice = scMathUtil.roundTo(tmp.basePrice,-6);
|
|
|
// 单价文件插入的数据
|
|
|
let unitPriceData = {
|
|
@@ -622,19 +619,17 @@ class GLJListModel extends BaseModel {
|
|
|
if(tmp.from=='cpt'){
|
|
|
unitPriceData.is_add = 1;
|
|
|
}
|
|
|
- unitPriceInsertData.push(unitPriceData);
|
|
|
+ if(!unitPriceModel.isPropertyInclude(unitPriceList,['code','name','specs','unit','type'],unitPriceData)){
|
|
|
+ unitPriceInsertData.push(unitPriceData);
|
|
|
+ }
|
|
|
}
|
|
|
// 整理完后开始插入数据
|
|
|
- let addResult = await this.add(gljInsertData);
|
|
|
- if (!addResult) {
|
|
|
- throw '组成物插入项目工料机失败!';
|
|
|
- }
|
|
|
+
|
|
|
// 插入单价数据表
|
|
|
- let unitPriceModel = new UnitPriceModel();
|
|
|
- let addUnitPriceResult = await unitPriceModel.add(unitPriceInsertData);
|
|
|
- if (!addUnitPriceResult) {
|
|
|
- throw '组成物插入单价数据失败!';
|
|
|
- }
|
|
|
+ if(unitPriceInsertData.length >0) await unitPriceModel.add(unitPriceInsertData);
|
|
|
+ //插入项目工料机
|
|
|
+ if(gljInsertData.length > 0) await this.add(gljInsertData);
|
|
|
+
|
|
|
|
|
|
return
|
|
|
}
|
|
@@ -719,6 +714,12 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
async getCompositionGLJByData(glj,unitPriceFileId){
|
|
|
let [gljData,mixRatioData,unitPriceData] = await this.getCompositionListByGLJ(glj,unitPriceFileId);
|
|
|
+ let priceNum = unitPriceData?Object.getOwnPropertyNames(unitPriceData).length:0;
|
|
|
+ let mixNum = mixRatioData?Object.getOwnPropertyNames(mixRatioData).length:0;
|
|
|
+ if(priceNum !==mixNum){//检查组成物数据是否一致
|
|
|
+ console.log("组成物数据有误,组成物单价文件个数:"+priceNum+", 组成物个数:"+mixNum);
|
|
|
+ return []
|
|
|
+ }
|
|
|
gljData = this.combineData(gljData, unitPriceData, [], mixRatioData);
|
|
|
return gljData;
|
|
|
}
|