|
|
@@ -16,20 +16,22 @@ let glj_type_util = require('../../../public/cache/std_glj_type_util');
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
let decimal_facade = require('../../main/facade/decimal_facade');
|
|
|
let gljUtil = require('../../../public/gljUtil');
|
|
|
+const common_util = require('../../../public/common_util');
|
|
|
|
|
|
module.exports={
|
|
|
calculateQuantity:calculateQuantity,
|
|
|
getGLJTypeByID:getGLJTypeByID
|
|
|
}
|
|
|
-//辅助定额调整、替换工料机、标准附注条件调整、添加工料机、自定义消耗量(包括删除工料机)、自定义乘系数、市场单价调整
|
|
|
+//辅助定额调整、替换工料机、稳定土配合比、标准附注条件调整、添加工料机、自定义消耗量(包括删除工料机)、自定义乘系数、市场单价调整
|
|
|
let stateSeq ={
|
|
|
ass:1,
|
|
|
replace:2,
|
|
|
- coe:3,
|
|
|
- add:4,
|
|
|
- cusQuantity:5,
|
|
|
- cusCoe:6,
|
|
|
- adjMak:7
|
|
|
+ proportion: 3,
|
|
|
+ coe:4,
|
|
|
+ add:5,
|
|
|
+ cusQuantity:6,
|
|
|
+ cusCoe:7,
|
|
|
+ adjMak:8
|
|
|
};
|
|
|
//自定义乘系数与定额工料机类型映射表
|
|
|
let coeTypeMap = {
|
|
|
@@ -44,66 +46,71 @@ let coeTypeMap = {
|
|
|
|
|
|
async function calculateQuantity(query,noNeedCal=null,refreshRationName = false){
|
|
|
try {
|
|
|
- let result ={
|
|
|
- glj_result:[],
|
|
|
- rationID:query.rationID
|
|
|
- };
|
|
|
- let impactRation = await ration.findOne({ID:query.rationID});
|
|
|
- let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
|
|
|
- let coeList = await ration_coe.find({rationID:query.rationID}).sort('seq').exec();
|
|
|
- let assList=[], assRation = null, adjustState=[],mixRatioMap = {};
|
|
|
- if(!impactRation){//如果定额不存在或者已删除,返回空
|
|
|
- return null;
|
|
|
- }
|
|
|
- if(impactRation._doc.hasOwnProperty("rationAssList")&&impactRation.rationAssList.length>0){
|
|
|
- prepareAss(impactRation.rationAssList);
|
|
|
- let temTimes = [];
|
|
|
- let thirdRationCodes=[];
|
|
|
- for(let i=0;i<impactRation.rationAssList.length;i++){
|
|
|
- let times = calculateTimes(impactRation.rationAssList[i]);
|
|
|
- if(times!=0){
|
|
|
- let thirdRationCode = impactRation.rationAssList[i].thirdRationCode;
|
|
|
- if(thirdRationCode && thirdRationCode !=''){
|
|
|
- temTimes.push(times);
|
|
|
- thirdRationCodes.push(thirdRationCode)
|
|
|
- }
|
|
|
- assRation = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:impactRation.rationAssList[i].assistCode});
|
|
|
- assList.push({times:times,assRation:assRation});
|
|
|
- adjustState.push({index:stateSeq.ass,content:impactRation.rationAssList[i].name+" "+impactRation.rationAssList[i].actualValue+" : +"+impactRation.rationAssList[i].assistCode+"x"+times});
|
|
|
- }
|
|
|
- }
|
|
|
- if(temTimes.length == 2 &&thirdRationCodes[0] == thirdRationCodes[1] ){ //说明有第三定额
|
|
|
- let times_t = temTimes[0] * temTimes[1];
|
|
|
- let tration = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:thirdRationCodes[0]});
|
|
|
- if(tration){
|
|
|
- assList.push({times:times_t,assRation:tration});
|
|
|
- adjustState.push({index:stateSeq.ass,content:"+"+thirdRationCodes[0]+"x"+times_t});
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for(let glj of gljList){//先把混凝土,砂浆,配合比有自定义消耗的挑出来
|
|
|
- if(gljUtil.isConcreteType(glj.type)) await getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap);
|
|
|
- }
|
|
|
+ let result ={
|
|
|
+ glj_result:[],
|
|
|
+ rationID:query.rationID
|
|
|
+ };
|
|
|
+ let impactRation = await ration.findOne({ID:query.rationID});
|
|
|
+ let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
|
|
|
+ let coeList = await ration_coe.find({rationID:query.rationID}).sort('seq').exec();
|
|
|
+ let assList=[], assRation = null, adjustState=[],mixRatioMap = {};
|
|
|
+ if(!impactRation){//如果定额不存在或者已删除,返回空
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(impactRation._doc.hasOwnProperty("rationAssList")&&impactRation.rationAssList.length>0){
|
|
|
+ prepareAss(impactRation.rationAssList);
|
|
|
+ let temTimes = [];
|
|
|
+ let thirdRationCodes=[];
|
|
|
+ for(let i=0;i<impactRation.rationAssList.length;i++){
|
|
|
+ let times = calculateTimes(impactRation.rationAssList[i]);
|
|
|
+ if(times!=0){
|
|
|
+ let thirdRationCode = impactRation.rationAssList[i].thirdRationCode;
|
|
|
+ if(thirdRationCode && thirdRationCode !=''){
|
|
|
+ temTimes.push(times);
|
|
|
+ thirdRationCodes.push(thirdRationCode)
|
|
|
+ }
|
|
|
+ assRation = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:impactRation.rationAssList[i].assistCode});
|
|
|
+ assList.push({times:times,assRation:assRation});
|
|
|
+ adjustState.push({index:stateSeq.ass,content:impactRation.rationAssList[i].name+" "+impactRation.rationAssList[i].actualValue+" : +"+impactRation.rationAssList[i].assistCode+"x"+times});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(temTimes.length == 2 &&thirdRationCodes[0] == thirdRationCodes[1] ){ //说明有第三定额
|
|
|
+ let times_t = temTimes[0] * temTimes[1];
|
|
|
+ let tration = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:thirdRationCodes[0]});
|
|
|
+ if(tration){
|
|
|
+ assList.push({times:times_t,assRation:tration});
|
|
|
+ adjustState.push({index:stateSeq.ass,content:"+"+thirdRationCodes[0]+"x"+times_t});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let glj of gljList){//先把混凝土,砂浆,配合比有自定义消耗的挑出来
|
|
|
+ if(gljUtil.isConcreteType(glj.type)) await getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap);
|
|
|
+ }
|
|
|
gljList = gljUtil.sortRationGLJ(gljList);
|
|
|
for(let i =0;i<gljList.length;i++ ){
|
|
|
let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,mixRatioMap,noNeedCal);
|
|
|
if(quantityUpdateCheck(gljList[i],r) == true) result.glj_result.push(r);
|
|
|
}
|
|
|
- if(noNeedCal==null && result.glj_result.length > 0){
|
|
|
- await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
|
|
|
- }
|
|
|
- adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
|
|
|
- adjustState=_.map(adjustState, _.property('content'));
|
|
|
- let adjustStateString = adjustState.join(';');
|
|
|
- let setData = {adjustState:adjustStateString};
|
|
|
- if(refreshRationName == true){//需要更新定额名称
|
|
|
- let newName = generateRationName(impactRation,gljList);
|
|
|
- setData.name = newName;
|
|
|
- result.rationName = newName;
|
|
|
- }
|
|
|
- await ration.update({ID:query.rationID},setData);
|
|
|
- result.adjustState=adjustStateString;
|
|
|
- return result;
|
|
|
+ if(noNeedCal==null && result.glj_result.length > 0){
|
|
|
+ await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
|
|
|
+ }
|
|
|
+ // 稳定土调整状态
|
|
|
+ const proportionStr = gljList.filter(glj => glj.rationProportion).map(glj => glj.adjustProportion || 0).join(':');
|
|
|
+ if (proportionStr) {
|
|
|
+ adjustState.push({ index: stateSeq.proportion, content: proportionStr });
|
|
|
+ }
|
|
|
+ adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
|
|
|
+ adjustState=_.map(adjustState, _.property('content'));
|
|
|
+ let adjustStateString = adjustState.join(';');
|
|
|
+ let setData = {adjustState:adjustStateString};
|
|
|
+ if(refreshRationName == true){//需要更新定额名称
|
|
|
+ let newName = generateRationName(impactRation,gljList);
|
|
|
+ setData.name = newName;
|
|
|
+ result.rationName = newName;
|
|
|
+ }
|
|
|
+ await ration.update({ID:query.rationID},setData);
|
|
|
+ result.adjustState=adjustStateString;
|
|
|
+ return result;
|
|
|
}catch (err){
|
|
|
console.log(err);
|
|
|
throw err;
|
|
|
@@ -141,6 +148,11 @@ function generateRationName(ration,gljList) {
|
|
|
caption = caption.replace('%s',r);
|
|
|
}
|
|
|
}
|
|
|
+ // 更新定额名称中显示的稳定土配合比
|
|
|
+ const proportionStr = gljList.filter(glj => glj.rationProportion).map(glj => glj.adjustProportion || 0).join(':');
|
|
|
+ if (proportionStr) {
|
|
|
+ caption = caption.replace('%p', proportionStr);
|
|
|
+ }
|
|
|
let reNameList = [];
|
|
|
for(let g of gljList){
|
|
|
//glj._doc.createType=='replace'&&glj.rcode!=glj.code
|
|
|
@@ -175,6 +187,10 @@ function generateUpdateTasks(result) {
|
|
|
async function calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList) {
|
|
|
let quantity = glj.rationItemQuantity ? scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal):0;
|
|
|
quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
|
|
|
+ if (glj.rationProportion && common_util.isDef(glj.adjustProportion)) {
|
|
|
+ const proportionRate = glj.adjustProportion / glj.rationProportion;
|
|
|
+ quantity *= proportionRate;
|
|
|
+ }
|
|
|
quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
|
|
|
return quantity;
|
|
|
}
|