|
@@ -8,6 +8,8 @@ let _=require("lodash");
|
|
|
let ration_glj = mongoose.model('ration_glj');
|
|
let ration_glj = mongoose.model('ration_glj');
|
|
|
let ration = mongoose.model('ration');
|
|
let ration = mongoose.model('ration');
|
|
|
let ration_coe = mongoose.model('ration_coe');
|
|
let ration_coe = mongoose.model('ration_coe');
|
|
|
|
|
+const ProjectModel = require('../../pm/models/project_model').project;
|
|
|
|
|
+let mixRatioModel = mongoose.model('mix_ratio');
|
|
|
let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
|
|
let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
|
|
|
let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
|
|
let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
|
|
|
let glj_type_util = require('../../../public/cache/std_glj_type_util');
|
|
let glj_type_util = require('../../../public/cache/std_glj_type_util');
|
|
@@ -49,9 +51,7 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){
|
|
|
let impactRation = await ration.findOne({ID:query.rationID,projectID:query.projectID});
|
|
let impactRation = await ration.findOne({ID:query.rationID,projectID:query.projectID});
|
|
|
let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
|
|
let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
|
|
|
let coeList = await ration_coe.find({projectID:query.projectID,rationID:query.rationID}).sort('seq').exec();
|
|
let coeList = await ration_coe.find({projectID:query.projectID,rationID:query.rationID}).sort('seq').exec();
|
|
|
- let assList=[];
|
|
|
|
|
- let assRation = null;
|
|
|
|
|
- let adjustState=[];
|
|
|
|
|
|
|
+ let assList=[], assRation = null, adjustState=[],mixRatioMap = {};
|
|
|
if(!impactRation){//如果定额不存在或者已删除,返回空
|
|
if(!impactRation){//如果定额不存在或者已删除,返回空
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -65,12 +65,15 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- gljList = sortRationGLJ(gljList);
|
|
|
|
|
- for(let i =0;i<gljList.length;i++ ){
|
|
|
|
|
- let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,noNeedCal);
|
|
|
|
|
- result.glj_result.push(r);
|
|
|
|
|
|
|
+ for(let glj of gljList){//先把混凝土,砂浆,配合比有自定义消耗的挑出来
|
|
|
|
|
+ if(gljUtil.isConcreteType(glj.type)&& !noCustomQuantiyt(glj)) await getMixRatioMap(glj,mixRatioMap);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ gljList = sortRationGLJ(gljList);
|
|
|
|
|
+ for(let i =0;i<gljList.length;i++ ){
|
|
|
|
|
+ let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,mixRatioMap,noNeedCal);
|
|
|
|
|
+ result.glj_result.push(r);
|
|
|
|
|
+ }
|
|
|
if(noNeedCal==null){
|
|
if(noNeedCal==null){
|
|
|
await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
|
|
await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
|
|
|
}
|
|
}
|
|
@@ -137,8 +140,16 @@ function sortRationGLJ(list) {
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,noNeedCal) {
|
|
|
|
|
- let decimalObject =await decimal_facade.getProjectDecimal(glj.projectID);
|
|
|
|
|
|
|
+function sortBeforeCalc(list) {
|
|
|
|
|
+ list = _.sortByAll(list, [function (item) {
|
|
|
|
|
+ return gljUtil.isConcreteType(item.type)?1:2;
|
|
|
|
|
+ }]);
|
|
|
|
|
+ return list;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,mixRatioMap,noNeedCal) {
|
|
|
|
|
+ let decimalObject = await decimal_facade.getProjectDecimal(glj.projectID);
|
|
|
let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
|
|
let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
|
|
|
let quantity = scMathUtil.roundTo(parseFloat(glj.quantity),-decimal);
|
|
let quantity = scMathUtil.roundTo(parseFloat(glj.quantity),-decimal);
|
|
|
let result={
|
|
let result={
|
|
@@ -151,12 +162,12 @@ async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,n
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
try {
|
|
try {
|
|
|
- if(noNeedCal==null){
|
|
|
|
|
- if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""){
|
|
|
|
|
|
|
+ if(noNeedCal==null){//计算顺序:辅助定额,附注条件,自定义消耗(如果有就不用前计算两项),自定义乘系数
|
|
|
|
|
+ if(noCustomQuantiyt(glj)){
|
|
|
quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
|
|
quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
|
|
|
quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
|
|
quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
|
|
|
quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
|
|
quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
|
|
|
- }else {
|
|
|
|
|
|
|
+ }else {//对于有自定义消耗量的,并且是混凝土,浆砂,配合比 这三种类型,其组成物的消耗量要跟据自定义消耗量做相应的换算
|
|
|
quantity = glj.customQuantity;
|
|
quantity = glj.customQuantity;
|
|
|
result.doc.customQuantity = glj.customQuantity;
|
|
result.doc.customQuantity = glj.customQuantity;
|
|
|
}
|
|
}
|
|
@@ -176,6 +187,25 @@ async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,n
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function getMixRatioMap(glj,mixRatioMap) {//生成组成物对应的父工料机的映射表
|
|
|
|
|
+ let unitPriceFileId = await ProjectModel.getUnitPriceFileId(glj.projectID);
|
|
|
|
|
+ let connect_key = gljUtil.getIndex(glj);
|
|
|
|
|
+ let mixList = await mixRatioModel.find({"unit_price_file_id":unitPriceFileId,'connect_key':connect_key})
|
|
|
|
|
+ for(let m of mixList){
|
|
|
|
|
+ let mkey = gljUtil.getIndex(m);
|
|
|
|
|
+ if(mixRatioMap[mkey]){
|
|
|
|
|
+ mixRatioMap[mkey].push({customQuantity:glj.customQuantity,rationItemQuantity:glj.rationItemQuantity,consumption:m.consumption});
|
|
|
|
|
+ }else {
|
|
|
|
|
+ mixRatioMap[mkey] = [{customQuantity:glj.customQuantity,rationItemQuantity:glj.rationItemQuantity,consumption:m.consumption}];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+function noCustomQuantiyt(glj) {//是否有自定义消耗量
|
|
|
|
|
+ return !glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function calculateAss(quantity,assList,glj) {
|
|
async function calculateAss(quantity,assList,glj) {
|
|
|
for(let i=0;i<assList.length;i++){
|
|
for(let i=0;i<assList.length;i++){
|
|
|
if(assList[i].assRation){
|
|
if(assList[i].assRation){
|