|
@@ -28,6 +28,9 @@ const stdGljModel = mongoose.model('std_glj_lib_gljList');
|
|
|
const gljClassModel = mongoose.model('std_glj_lib_gljClass');
|
|
const gljClassModel = mongoose.model('std_glj_lib_gljClass');
|
|
|
const projectDao = require('../../pm/models/project_model').project;
|
|
const projectDao = require('../../pm/models/project_model').project;
|
|
|
const compleClassModel = mongoose.model('complementary_glj_section');
|
|
const compleClassModel = mongoose.model('complementary_glj_section');
|
|
|
|
|
+let gljUtil = require('../../../public/gljUtil');
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
save: save,
|
|
save: save,
|
|
@@ -38,6 +41,7 @@ module.exports = {
|
|
|
getGLJData: getGLJData,
|
|
getGLJData: getGLJData,
|
|
|
getGLJDataByCodes:getGLJDataByCodes,
|
|
getGLJDataByCodes:getGLJDataByCodes,
|
|
|
addGLJ: addGLJ,
|
|
addGLJ: addGLJ,
|
|
|
|
|
+ deleteRationGLJ:deleteRationGLJ,
|
|
|
deleteGLJ:deleteGLJ,
|
|
deleteGLJ:deleteGLJ,
|
|
|
insertAddTypeGLJ:insertAddTypeGLJ,
|
|
insertAddTypeGLJ:insertAddTypeGLJ,
|
|
|
replaceGLJ: replaceGLJ,
|
|
replaceGLJ: replaceGLJ,
|
|
@@ -636,8 +640,9 @@ async function addGLJ(rgList,compilation) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function insertAddTypeGLJ(rgList,compilation) {
|
|
async function insertAddTypeGLJ(rgList,compilation) {
|
|
|
- let newRecodes = [];
|
|
|
|
|
|
|
+ let newRecodes = [],GLJMap=null;
|
|
|
let [unitFileId,ext] = await prepareExtData(rgList[0].projectID,compilation);
|
|
let [unitFileId,ext] = await prepareExtData(rgList[0].projectID,compilation);
|
|
|
|
|
+
|
|
|
for (let g of rgList) {
|
|
for (let g of rgList) {
|
|
|
let projectGljModel = new GLJListModel();
|
|
let projectGljModel = new GLJListModel();
|
|
|
let result = await projectGljModel.addList(getGLJSearchInfo(g),unitFileId,ext);
|
|
let result = await projectGljModel.addList(getGLJSearchInfo(g),unitFileId,ext);
|
|
@@ -653,6 +658,14 @@ async function insertAddTypeGLJ(rgList,compilation) {
|
|
|
g.ID = uuidV1();
|
|
g.ID = uuidV1();
|
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
|
g.subList = getMixRatioShowDatas(result.subList);
|
|
g.subList = getMixRatioShowDatas(result.subList);
|
|
|
|
|
+ //对于混凝土,砂浆,配合比,组成物还要插入定额工料机
|
|
|
|
|
+ if(gljUtil.isConcreteType(g.type)){
|
|
|
|
|
+ if(GLJMap == null){
|
|
|
|
|
+ let oldGLJList = await ration_glj.find({'rationID':g.rationID});
|
|
|
|
|
+ GLJMap = _.indexBy(oldGLJList,"projectGLJID");
|
|
|
|
|
+ }
|
|
|
|
|
+ addMixRatioToRationGLJ(g,result.subList,newRecodes,GLJMap);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
newRecodes.push(createNewRecord(g));
|
|
newRecodes.push(createNewRecord(g));
|
|
|
}
|
|
}
|
|
@@ -660,6 +673,80 @@ async function insertAddTypeGLJ(rgList,compilation) {
|
|
|
return newRecodes;
|
|
return newRecodes;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function deleteRationGLJ(data){
|
|
|
|
|
+ let deleteIDs = [data.ID];
|
|
|
|
|
+ if(gljUtil.isConcreteType(data.type)){//如果是混凝土、砂浆、配合比,还要删除没有被引用的组成物工料机
|
|
|
|
|
+ let projectGljModel = new GLJListModel();
|
|
|
|
|
+ let rationGLJList = await ration_glj.find({'rationID':data.rationID});
|
|
|
|
|
+ let unitFileId = await projectDao.getUnitPriceFileId(data.projectID);
|
|
|
|
|
+ let projectGLJMap = {},referenceMap={};
|
|
|
|
|
+ let deleteMix = [];
|
|
|
|
|
+ for(let r of rationGLJList){
|
|
|
|
|
+ projectGLJMap[r.projectGLJID] = r;
|
|
|
|
|
+ if(gljUtil.isConcreteType(r.type)){
|
|
|
|
|
+ if(r.ID == data.ID){//是要删除的工料机
|
|
|
|
|
+ deleteMix = await projectGljModel.getCompositionGLJByData(r,unitFileId);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ let comList = await projectGljModel.getCompositionGLJByData(r,unitFileId);
|
|
|
|
|
+ for(let c of comList){
|
|
|
|
|
+ referenceMap[c.id] = c;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for(let d of deleteMix){
|
|
|
|
|
+ //删除不属于其它的组成物并且定额消耗为0
|
|
|
|
|
+ if(referenceMap[d.id]) continue;
|
|
|
|
|
+ if(projectGLJMap[d.id]&&(projectGLJMap[d.id].rationItemQuantity == '0'||projectGLJMap[d.id].rationItemQuantity == 0)){
|
|
|
|
|
+ deleteIDs.push(projectGLJMap[d.id].ID);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ await ration_glj.deleteMany({'ID': {"$in": deleteIDs}});
|
|
|
|
|
+ } else{
|
|
|
|
|
+ await ration_glj.deleteOne({ID:data.ID});
|
|
|
|
|
+ }
|
|
|
|
|
+ let calcResult = await glj_calculate_facade.calculateQuantity({
|
|
|
|
|
+ projectID: data.projectID,
|
|
|
|
|
+ rationID: data.rationID
|
|
|
|
|
+ });
|
|
|
|
|
+ calcResult.deleteList = deleteIDs;
|
|
|
|
|
+ return calcResult;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+function addMixRatioToRationGLJ(g,subList,newRecodes,GLJMap){
|
|
|
|
|
+ let newMap = {};
|
|
|
|
|
+ for(let mr of subList ){
|
|
|
|
|
+ //先查找该定额下是否已经有了工料机了,有就不用再插入了
|
|
|
|
|
+ newMap[mr.id] = mr;//新增的定额工料机映射表
|
|
|
|
|
+ if(GLJMap[mr.id]||_.find(newRecodes,{'projectGLJID':mr.id})) continue;
|
|
|
|
|
+ //没有的情况下,生成一条定额工料机计录
|
|
|
|
|
+ let newMr = {
|
|
|
|
|
+ projectID:g.projectID,
|
|
|
|
|
+ GLJID:mr.glj_id,
|
|
|
|
|
+ rationID:g.rationID,
|
|
|
|
|
+ rationItemQuantity:0,
|
|
|
|
|
+ quantity:0,
|
|
|
|
|
+ name:mr.name,
|
|
|
|
|
+ code:mr.code,
|
|
|
|
|
+ original_code:mr.original_code,
|
|
|
|
|
+ unit:mr.unit,
|
|
|
|
|
+ specs:mr.specs,
|
|
|
|
|
+ from:mr.from,
|
|
|
|
|
+ createType:g.createType,
|
|
|
|
|
+ shortName:mr.unit_price.short_name,
|
|
|
|
|
+ billsItemID:g.billsItemID,
|
|
|
|
|
+ type:mr.type,
|
|
|
|
|
+ model:mr.model,
|
|
|
|
|
+ repositoryId:g.repositoryId,
|
|
|
|
|
+ projectGLJID:mr.id,
|
|
|
|
|
+ adjCoe:mr.adjCoe
|
|
|
|
|
+ };
|
|
|
|
|
+ newMr.ID = uuidV1();
|
|
|
|
|
+ newRecodes.push(newMr);
|
|
|
|
|
+ }
|
|
|
|
|
+ return newMap;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
async function replaceGLJByData(data,compilation) {
|
|
async function replaceGLJByData(data,compilation) {
|
|
|
let projectGljModel = new GLJListModel();
|
|
let projectGljModel = new GLJListModel();
|
|
@@ -667,7 +754,8 @@ async function replaceGLJByData(data,compilation) {
|
|
|
let result = await projectGljModel.addList(getGLJSearchInfo(data),unitFileId,ext);
|
|
let result = await projectGljModel.addList(getGLJSearchInfo(data),unitFileId,ext);
|
|
|
let typeString = result.type+'';
|
|
let typeString = result.type+'';
|
|
|
data.projectGLJID = result.id;
|
|
data.projectGLJID = result.id;
|
|
|
-
|
|
|
|
|
|
|
+ // CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
|
|
|
|
|
+ let [newRecodes,deleteList] = await replaceMixRatio(data,result,unitFileId);
|
|
|
let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
|
|
let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
|
|
|
//组装回传数据
|
|
//组装回传数据
|
|
|
data.marketPrice = result.unit_price.market_price;
|
|
data.marketPrice = result.unit_price.market_price;
|
|
@@ -680,24 +768,75 @@ async function replaceGLJByData(data,compilation) {
|
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
|
data.subList = getMixRatioShowDatas(result.subList);
|
|
data.subList = getMixRatioShowDatas(result.subList);
|
|
|
}
|
|
}
|
|
|
- return data;
|
|
|
|
|
|
|
+ return {data:data,newRecodes:newRecodes,deleteList:deleteList};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function replaceMixRatio(g,result,unitFileId){
|
|
|
|
|
+ let newRecodes=[],deleteList = [];
|
|
|
|
|
+ if(gljUtil.isConcreteType(g.type)){//相同类型的才能替换,所以判断一个就好了
|
|
|
|
|
+ let IDMap = {}, projectGLJMap = {},referenceMap={},concreteList=[],newMap={};
|
|
|
|
|
+ let projectGljModel = new GLJListModel();
|
|
|
|
|
+ let rationGLJList = await ration_glj.find({'rationID':g.rationID});
|
|
|
|
|
+ for(let r of rationGLJList){
|
|
|
|
|
+ IDMap[r.ID] = r;
|
|
|
|
|
+ projectGLJMap[r.projectGLJID] = r;
|
|
|
|
|
+ if(gljUtil.isConcreteType(r.type)&&r.ID!=g.ID) concreteList.push(r) //除了本身,记录一下其它混凝土类型
|
|
|
|
|
+ }
|
|
|
|
|
+ if (result.hasOwnProperty('subList') && result.subList.length > 0){
|
|
|
|
|
+ newMap = addMixRatioToRationGLJ(g,result.subList,newRecodes,projectGLJMap);//先生成要添加的工料机
|
|
|
|
|
+ }
|
|
|
|
|
+ let oldMixList = await projectGljModel.getCompositionGLJByData(IDMap[g.ID],unitFileId);
|
|
|
|
|
+ for(let c of concreteList){//找出要删除的子定额工料机(没人引用,并且定额消耗量为0)
|
|
|
|
|
+ let temList = await projectGljModel.getCompositionGLJByData(c,unitFileId);
|
|
|
|
|
+ for(let t of temList){
|
|
|
|
|
+ referenceMap[t.id] = t;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for(let o of oldMixList){
|
|
|
|
|
+ if(newMap[o.id]||referenceMap[o.id]) continue;//如果两个地方有一个存在,那么就不用删除
|
|
|
|
|
+ //没有被其它地方引用并且定额消耗量为0,就删除对应的定额工料机
|
|
|
|
|
+ if(projectGLJMap[o.id] && (projectGLJMap[o.id].rationItemQuantity == '0'||projectGLJMap[o.id].rationItemQuantity == 0)) deleteList.push(projectGLJMap[o.id].ID)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(deleteList.length > 0) await ration_glj.deleteMany({'ID': {"$in": deleteList}});//删除定额工料机
|
|
|
|
|
+ if(newRecodes.length > 0) await ration_glj.insertMany(newRecodes);
|
|
|
|
|
+ return [newRecodes,deleteList]
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
async function replaceGLJ(data,compilation) {
|
|
async function replaceGLJ(data,compilation) {
|
|
|
let rdata = {};
|
|
let rdata = {};
|
|
|
- data = await replaceGLJByData(data,compilation);
|
|
|
|
|
|
|
+ let r_result =await replaceGLJByData(data,compilation);
|
|
|
|
|
+ data = r_result.data;
|
|
|
let stateResult = await glj_calculate_facade.calculateQuantity({
|
|
let stateResult = await glj_calculate_facade.calculateQuantity({
|
|
|
projectID: data.projectID,
|
|
projectID: data.projectID,
|
|
|
rationID: data.rationID
|
|
rationID: data.rationID
|
|
|
- }, true,true);
|
|
|
|
|
|
|
+ }, null,true);
|
|
|
rdata.data = data;
|
|
rdata.data = data;
|
|
|
rdata.adjustState = stateResult.adjustState;
|
|
rdata.adjustState = stateResult.adjustState;
|
|
|
rdata.name = stateResult.rationName;
|
|
rdata.name = stateResult.rationName;
|
|
|
|
|
+ rdata.newRecodes = r_result.newRecodes;
|
|
|
|
|
+ rdata.deleteList = r_result.deleteList;
|
|
|
|
|
+ rdata.glj_result = stateResult.glj_result;
|
|
|
return rdata;
|
|
return rdata;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+async function replaceMixRatioForMReplace(tasks,result,unitFileId) {
|
|
|
|
|
+ let allNewRecodes = [],allDeleteList=[];
|
|
|
|
|
+ for(let t of tasks){
|
|
|
|
|
+ let tem = _.cloneDeep(t.updateOne.update);
|
|
|
|
|
+ tem.ID = t.updateOne.filter.ID;
|
|
|
|
|
+ tem.rationID = t.updateOne.filter.rationID;
|
|
|
|
|
+ delete t.updateOne.filter.rationID;
|
|
|
|
|
+ let [newRecodes,deleteList] = await replaceMixRatio(tem,result,unitFileId);
|
|
|
|
|
+ allNewRecodes = allNewRecodes.concat(newRecodes);
|
|
|
|
|
+ allDeleteList = allDeleteList.concat(deleteList);
|
|
|
|
|
+ }
|
|
|
|
|
+ return {newRecodes:allNewRecodes,deleteList:allDeleteList}
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function mReplaceGLJ(data,compilation) {
|
|
async function mReplaceGLJ(data,compilation) {
|
|
|
- let mresult = {};
|
|
|
|
|
|
|
+ let mresult = {},mixResult = null,noNeedCal=true;
|
|
|
let projectGljModel = new GLJListModel();
|
|
let projectGljModel = new GLJListModel();
|
|
|
let [unitFileId,ext] = await prepareExtData(data.doc.projectID,compilation);
|
|
let [unitFileId,ext] = await prepareExtData(data.doc.projectID,compilation);
|
|
|
//
|
|
//
|
|
@@ -705,12 +844,16 @@ async function mReplaceGLJ(data,compilation) {
|
|
|
let typeString = result.type+'';
|
|
let typeString = result.type+'';
|
|
|
let newDoc = {};
|
|
let newDoc = {};
|
|
|
newDoc.projectGLJID = result.id;
|
|
newDoc.projectGLJID = result.id;
|
|
|
- let rationList = await ration_glj.distinct('rationID', data.query);
|
|
|
|
|
|
|
+ let rationList = [];//await ration_glj.distinct('rationID', data.query);
|
|
|
for(let t of data.tasks){
|
|
for(let t of data.tasks){
|
|
|
|
|
+ rationList.push(t.updateOne.filter.rationID);
|
|
|
t.updateOne.update.projectGLJID = result.id;//更新项目工料机ID
|
|
t.updateOne.update.projectGLJID = result.id;//更新项目工料机ID
|
|
|
}
|
|
}
|
|
|
|
|
+ if(gljUtil.isConcreteType(result.unit_price.type)) {
|
|
|
|
|
+ mixResult = await replaceMixRatioForMReplace(data.tasks,result,unitFileId);
|
|
|
|
|
+ noNeedCal = null;
|
|
|
|
|
+ }
|
|
|
await ration_glj.bulkWrite(data.tasks);
|
|
await ration_glj.bulkWrite(data.tasks);
|
|
|
- //let updateResult = await ration_glj.update(data.query, data.doc, {multi: true});
|
|
|
|
|
|
|
|
|
|
newDoc.marketPrice = result.unit_price.market_price;
|
|
newDoc.marketPrice = result.unit_price.market_price;
|
|
|
newDoc.adjustPrice = result.unit_price.base_price;
|
|
newDoc.adjustPrice = result.unit_price.base_price;
|
|
@@ -722,10 +865,13 @@ async function mReplaceGLJ(data,compilation) {
|
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
|
newDoc.subList = getMixRatioShowDatas(result.subList);
|
|
newDoc.subList = getMixRatioShowDatas(result.subList);
|
|
|
}
|
|
}
|
|
|
- let stateList = await changAdjustState(data, rationList);
|
|
|
|
|
|
|
+ let [stateList,glj_result] = await changAdjustState(data, rationList,noNeedCal);
|
|
|
data.doc = newDoc;
|
|
data.doc = newDoc;
|
|
|
mresult.data = data;
|
|
mresult.data = data;
|
|
|
mresult.stateList = stateList;
|
|
mresult.stateList = stateList;
|
|
|
|
|
+ mresult.newRecodes = mixResult?mixResult.newRecodes:[];
|
|
|
|
|
+ mresult.deleteList = mixResult?mixResult.deleteList:[];
|
|
|
|
|
+ mresult.glj_result = glj_result;
|
|
|
return mresult
|
|
return mresult
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -850,18 +996,19 @@ async function getRationTypeGLJQuantity(projectID) {
|
|
|
return rations;
|
|
return rations;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function changAdjustState(data, rationList) {
|
|
|
|
|
- let stateList = [];
|
|
|
|
|
|
|
+async function changAdjustState(data, rationList,noNeedCal) {
|
|
|
|
|
+ let stateList = [],glj_result=[];
|
|
|
for (let r of rationList) {
|
|
for (let r of rationList) {
|
|
|
let stateResult = await glj_calculate_facade.calculateQuantity({
|
|
let stateResult = await glj_calculate_facade.calculateQuantity({
|
|
|
projectID: data.query.projectID,
|
|
projectID: data.query.projectID,
|
|
|
rationID: r
|
|
rationID: r
|
|
|
- }, true,true);
|
|
|
|
|
|
|
+ }, noNeedCal,true);
|
|
|
if(stateResult){
|
|
if(stateResult){
|
|
|
stateList.push({rationID: r, adjustState: stateResult.adjustState,name:stateResult.rationName});
|
|
stateList.push({rationID: r, adjustState: stateResult.adjustState,name:stateResult.rationName});
|
|
|
|
|
+ glj_result = glj_result.concat(stateResult.glj_result)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return stateList;
|
|
|
|
|
|
|
+ return [stateList,glj_result];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getGLJDataByCodes(data,compilation) {
|
|
async function getGLJDataByCodes(data,compilation) {
|