|
|
@@ -561,50 +561,41 @@ class GLJListModel extends BaseModel {
|
|
|
throw '参数错误';
|
|
|
}
|
|
|
let fromTable = data.from === undefined ? 'std' : data.from;
|
|
|
+ var connect_key =this.getIndex(data,['code','name','specs','unit','type']);
|
|
|
+ let e_mList = await this.getCompositionGLJListFromMixRatio(projectId,unitPriceFileId,connect_key,fromTable);
|
|
|
+ //如果组成物数据已经存在,则以单价文件中组成物的数据为准,不用再往下做判断了(项目工料机中需要插入的已经在上一步中生成插入)
|
|
|
+ if(e_mList.length > 0) return;
|
|
|
+
|
|
|
// 查找对应组成物的项目工料机数据
|
|
|
let indexs=['code','name','specs','unit','type'];
|
|
|
let [projectGljList, compositionGljList] = await this.getCompositionGLJList(gljId, projectId, indexs, fromTable);
|
|
|
- // 整理配合比待插入数据
|
|
|
+ // 整理配合比待插入数据,单价文件中配合比没有数据,则以库中的组成物信息为准
|
|
|
let mixRatioInsertData = [];
|
|
|
- var connect_key =this.getIndex(data,['code','name','specs','unit','type']);
|
|
|
- //先查找是否已存在配合比数据,在共用单价文件的情况下,有可能配合比数据存在,项目工料机数据不存在
|
|
|
- let e_mList = await mixRatioModel.findDataByCondition({unit_price_file_id: unitPriceFileId,connect_key: connect_key},null,false);
|
|
|
- if(e_mList.length <= 0){
|
|
|
- for (let tmp of compositionGljList) {
|
|
|
- let consumpiton = tmp.consumption;
|
|
|
- //只有标准的工料机的组成物才会有多单价、多组成物消耗量的情况 fromTable
|
|
|
- if(fromTable == 'std' && ext && ext.quantityField &&( tmp.consumption[ext.quantityField]!= undefined && tmp.consumption[ext.quantityField]!=null)){
|
|
|
- consumpiton = tmp.consumption[ext.quantityField];
|
|
|
- }
|
|
|
- // 配合比数据插入
|
|
|
- let mixRatioData = {
|
|
|
- consumption: consumpiton,
|
|
|
- glj_id: tmp.ID,
|
|
|
- unit_price_file_id: unitPriceFileId,
|
|
|
- connect_key: connect_key,
|
|
|
- type: tmp.gljType,
|
|
|
- code: tmp.code,
|
|
|
- specs:tmp.specs?tmp.specs:"",
|
|
|
- name:tmp.name,
|
|
|
- unit:tmp.unit?tmp.unit:''
|
|
|
- };
|
|
|
- mixRatioInsertData.push(mixRatioData);
|
|
|
+ for (let tmp of compositionGljList) {
|
|
|
+ let consumpiton = tmp.consumption;
|
|
|
+ //只有标准的工料机的组成物才会有多单价、多组成物消耗量的情况 fromTable
|
|
|
+ if(fromTable == 'std' && ext && ext.quantityField &&( tmp.consumption[ext.quantityField]!= undefined && tmp.consumption[ext.quantityField]!=null)){
|
|
|
+ consumpiton = tmp.consumption[ext.quantityField];
|
|
|
}
|
|
|
+ // 配合比数据插入
|
|
|
+ let mixRatioData = {
|
|
|
+ consumption: consumpiton,
|
|
|
+ glj_id: tmp.ID,
|
|
|
+ unit_price_file_id: unitPriceFileId,
|
|
|
+ connect_key: connect_key,
|
|
|
+ type: tmp.gljType,
|
|
|
+ code: tmp.code,
|
|
|
+ specs:tmp.specs?tmp.specs:"",
|
|
|
+ name:tmp.name,
|
|
|
+ unit:tmp.unit?tmp.unit:''
|
|
|
+ };
|
|
|
+ mixRatioInsertData.push(mixRatioData);
|
|
|
}
|
|
|
//如果有车船税则加入到配合比表中 -- 先判断机械类型吧,所有都插入影响性能
|
|
|
if(data.type == 301){//如果是机械台班,看有没有车船税 - modifyGLJ方法里也会有添加组成物,修改这里逻辑时记得同步修改。
|
|
|
let newM = await this.getCCSData(data,unitPriceFileId);
|
|
|
if(newM) mixRatioInsertData.push(newM);
|
|
|
}
|
|
|
-
|
|
|
- // 插入配合比表
|
|
|
- // 因为有可能项目工料机与单价数据已存在,但配合比数据不存在,所以先插入配合比,后续判断如果存在项目工料机则可以省下数据库操作
|
|
|
- if(mixRatioInsertData.length>0){
|
|
|
- let addMixRatioResult = await mixRatioModel.add(mixRatioInsertData);
|
|
|
- if (!addMixRatioResult) {
|
|
|
- throw '组成物插入单价数据失败!';
|
|
|
- }
|
|
|
- }
|
|
|
let unitPriceModel = new UnitPriceModel();
|
|
|
let unitPriceList = await unitPriceModel.model.find({unit_price_file_id:unitPriceFileId});//查找按文件id查找单价文件数据,用来判断单价文件信息是否已存在
|
|
|
|
|
|
@@ -615,20 +606,7 @@ class GLJListModel extends BaseModel {
|
|
|
let key = this.getIndex(tmp,['code','name','specs','unit','gljType']);
|
|
|
if (projectGljList[key] === undefined) {
|
|
|
// 项目工料机插入的数据
|
|
|
- let gljData = {
|
|
|
- glj_id: tmp.ID,
|
|
|
- project_id: projectId,
|
|
|
- code: tmp.code,
|
|
|
- name: tmp.name,
|
|
|
- specs: tmp.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,
|
|
|
- from:tmp.from
|
|
|
- };
|
|
|
+ let gljData = this.getProjectGLJNewData(tmp,projectId);
|
|
|
gljInsertData.push(gljData);
|
|
|
}
|
|
|
let basePrice = tmp.basePrice;
|
|
|
@@ -668,11 +646,39 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
// 插入单价数据表
|
|
|
if(unitPriceInsertData.length >0) await unitPriceModel.add(unitPriceInsertData);
|
|
|
+
|
|
|
+ //插入配合比数据
|
|
|
+ if(mixRatioInsertData.length>0){
|
|
|
+ let addMixRatioResult = await mixRatioModel.add(mixRatioInsertData);
|
|
|
+ if (!addMixRatioResult) {
|
|
|
+ throw '组成物插入单价数据失败!';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//插入项目工料机
|
|
|
if(gljInsertData.length > 0) await this.add(gljInsertData);
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ getProjectGLJNewData(tmp,projectId){
|
|
|
+ let gljData = {
|
|
|
+ glj_id: tmp.ID,
|
|
|
+ project_id: projectId,
|
|
|
+ code: tmp.code,
|
|
|
+ name: tmp.name,
|
|
|
+ specs: tmp.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,
|
|
|
+ from:tmp.from?tmp.from:"std"
|
|
|
+ };
|
|
|
+ return gljData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取组成物具体数据
|
|
|
*
|
|
|
@@ -712,6 +718,62 @@ class GLJListModel extends BaseModel {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ //从配合比表中取组成物的信息以及对应的项目工料机信息,再从配合比数据中反查工料机库中的信息
|
|
|
+ async getCompositionGLJListFromMixRatio (projectId,unitPriceFileId,connect_key,fromTable = 'std'){
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
+ let e_mList = await mixRatioModel.model.find({unit_price_file_id: unitPriceFileId,connect_key: connect_key}).lean();
|
|
|
+ if (e_mList.length <= 0) return [];
|
|
|
+ let codeList = [];
|
|
|
+ let ratioMap = {};
|
|
|
+ for(let tmp of e_mList) {
|
|
|
+ codeList.push(tmp.code);
|
|
|
+ let ckey = this.getIndex(tmp);
|
|
|
+ ratioMap[ckey] = tmp
|
|
|
+ }
|
|
|
+ // 查找对应的项目工料机数据
|
|
|
+ let condition = {project_id: projectId,code: {"$in": codeList} };
|
|
|
+ let gljData = await this.model.find(condition, {_id: 0}).lean();
|
|
|
+ let matchGljs = {};
|
|
|
+ for(let g of gljData){
|
|
|
+ let gkey = this.getIndex(g);
|
|
|
+ if(ratioMap[gkey]) matchGljs[gkey] = g;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果有组成物信息存在,但项目工料机信息不全的情况,应从数据库中查存询原始信息
|
|
|
+ // (只有在父工料机是来自标准的情况下做这个操作,因为组成物表中没有存具体的工料机是来自补充的还是标准库,而父工料机是补充库的,组成物有可能来自两个库,而父来自标准,子只会来自标准)
|
|
|
+ let lessIDList = [],lessMix=[];//lessMix只有在父工料机是来自补充工料机的时候才要用到
|
|
|
+ let componentGljData = [];
|
|
|
+ let gljInsertData = [];
|
|
|
+ for(let mk in ratioMap){//找出缺少的工料机
|
|
|
+ if(!matchGljs[mk]){
|
|
|
+ lessMix.push(ratioMap[mk]);
|
|
|
+ lessIDList.push(ratioMap[mk].glj_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(lessIDList.length > 0){
|
|
|
+ if(fromTable == "std"){
|
|
|
+ let gljListModel = new STDGLJLibGLJListModel();
|
|
|
+ let condition = {ID: {$in: lessIDList}};
|
|
|
+ componentGljData = await gljListModel.model.find(condition).lean();
|
|
|
+ for(let tmp of componentGljData){
|
|
|
+ let newProjctData = this.getProjectGLJNewData(tmp,projectId);
|
|
|
+ gljInsertData.push(newProjctData)
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ for(let m of lessMix){
|
|
|
+ m.from = 'cpt';
|
|
|
+ let newProjctData = this.getProjectGLJNewData(m,projectId);
|
|
|
+ gljInsertData.push(newProjctData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //这边只插入项目工料机数据,对于组成物文件中有的数据,理论上单价文件也是应该要有的,如果没有,那只能是mongodb数据库不支持事务的情况的问题
|
|
|
+ if(gljInsertData.length > 0) await this.add(gljInsertData);
|
|
|
+ return e_mList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取混凝土等有组成物相关工料机对应的组成物项目工料机数据
|
|
|
*
|
|
|
@@ -728,25 +790,23 @@ class GLJListModel extends BaseModel {
|
|
|
if (componentGljList.length <= 0) {
|
|
|
return [{},[]];
|
|
|
}
|
|
|
-
|
|
|
+ //2019-11-15 优化,用5个属性条件去查意义不大,用编号就能过滤得差不多了,最后再用5个属性去匹配。 同时可以提高查询效率
|
|
|
let codeList = [];
|
|
|
- let nameList = [];
|
|
|
- let specsList= [];
|
|
|
- let typeList = [];
|
|
|
- let unitList = [];
|
|
|
+ let componentMap = {};
|
|
|
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 ckey = this.getIndex(tmp,['code','name','specs','unit','gljType']);
|
|
|
+ componentMap[ckey] = tmp
|
|
|
}
|
|
|
-
|
|
|
// 查找对应的项目工料机数据
|
|
|
- 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];
|
|
|
+ let condition = {project_id: projectId,code: {"$in": codeList} };
|
|
|
+ let gljData = await this.model.find(condition, {_id: 0}).lean();
|
|
|
+ let matchGljs = {};
|
|
|
+ for(let g of gljData){
|
|
|
+ let gkey = this.getIndex(g);
|
|
|
+ if(componentMap[gkey]) matchGljs[gkey] = g;
|
|
|
+ }
|
|
|
+ return [matchGljs, componentGljList];
|
|
|
}
|
|
|
|
|
|
async getCompositionGLJByData(glj,unitPriceFileId){
|
|
|
@@ -774,45 +834,34 @@ class GLJListModel extends BaseModel {
|
|
|
// 查找对应的配合比数据
|
|
|
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 mixRatios = await mixRatioModel.model.find(condition, {_id: 0}).lean();
|
|
|
+ //2019-11-15 优化,用5个属性条件去查意义不大,用编号就能过滤得差不多了,最后再用5个属性去匹配。 同时可以提高查询效率
|
|
|
let codeList = [];
|
|
|
- let nameList = [];
|
|
|
- let specsList= [];
|
|
|
- let typeList = [];
|
|
|
- let unitList = [];
|
|
|
if(mixRatios.length<=0){
|
|
|
return [[],[],[]];
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
//数组去重
|
|
|
codeList = _.uniq(codeList);
|
|
|
- nameList = _.uniq(nameList);
|
|
|
- specsList = _.uniq(specsList);
|
|
|
- typeList=_.uniq(typeList);
|
|
|
- unitList = _.uniq(unitList);
|
|
|
// 查找对应的项目工料机数据
|
|
|
- let gcondition = {project_id: glj.project_id?glj.project_id:glj.projectID,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 gcondition = {project_id: glj.project_id?glj.project_id:glj.projectID,code: {"$in": codeList}};
|
|
|
+ let gljData = await this.model.find(gcondition, {_id: 0}).lean();
|
|
|
// 查找对应的单价数据
|
|
|
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 ucondition = { unit_price_file_id: unitPriceFileId,code: {"$in": codeList}};
|
|
|
+ let unitPriceList = await unitPriceModel.model.find(ucondition, {_id: 0}).lean();
|
|
|
|
|
|
|
|
|
// 整理数据
|
|
|
let unitPriceData = {};
|
|
|
for(let tmp of unitPriceList) {
|
|
|
let u_index = this.getIndex(tmp,['code','name','specs','unit','type']);
|
|
|
- unitPriceData[u_index] = tmp;
|
|
|
+ if(mixRatioData[u_index]) unitPriceData[u_index] = tmp;//过滤掉不完全匹配的工料机单价
|
|
|
}
|
|
|
let c_gljData = [];
|
|
|
for(let g of gljData){//过滤掉不是组成物的工料机
|