У меня есть длина, ширина, высота и вес для каждой отправки. Я хотел рассчитать общий объем каждой перевозки и общий вес продукта. Таким образом, у меня также есть объем и вместимость транспортного средства. Теперь я добавил отгрузку в грузовик и затем показал объем транспортного средства Емкость и вес транспортного средства для добавления груза, пока грузовик не заполнен Node.js и mongodb
Я пишу некоторый код, но он предназначен только для добавления одной отправки не более одной, поэтому, пожалуйста, можете Вы помогаете мне, как добавить целую партию с конкретным идентификатором
{
"success": "Fetched Linehaul",
"linehaul": {
"idLineHaul": {
"_id": "5ea1e7e657aa5a2916826ff1",
"idVehicleRegistered": {
"_id": "5e98afc849d3ae12859ac9ab",
"vehicleNumber": "MH04CC9000",
"registrationNumber": "MH04YYH",
"volumeCapacityInCubicFeet": 3696,
"vehicleWeightCapacityInKgs": 3700,
"name": "Rajesh",
"phone": 999997896,
"vehicleType": "TATA Signa"
},
"ETA": 12,
"weightCapacityUtilized": 89,
"volumeCapacityUtilized": 45,
"expectedStartDate": "Fri Apr 24 2020 01:07:48 GMT+0530 (India Standard Time)",
"expectedEndDate": "Fri Apr 24 2020 01:07:48 GMT+0530 (India Standard Time)"
},
"packageList": [
{
"_id": "5ea1ea0157aa5a2916826ff4",
"idShipment": {
"_id": "5e9df7551faf495b0eb18c68",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e98505b2ce39e16d27d7e90"
},
"idMaterialType": "dangerous",
"length": 2,
"width": 4,
"height": 2,
"weight": 6,
"quantity": 3,
"code": "RQ123ZR",
"status": "Onboarded"
},
"damage": "No",
"createdAt": "2020-04-23T19:18:25.451Z",
"updatedAt": "2020-04-23T19:18:25.451Z"
},
{
"_id": "5ea5f8033a55270fe86744ec",
"idShipment": {
"_id": "5ea5f74f3a55270fe86744ea",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e9827962ce39e16d27d7e8a"
},
"idMaterialType": "fragile",
"length": 4,
"width": 3,
"height": 3,
"weight": 6,
"quantity": 3,
"code": "RQ123PB",
"status": "Onboarded"
},
"damage": "No",
"createdAt": "2020-04-26T21:07:15.287Z",
"updatedAt": "2020-04-26T21:07:15.287Z"
},
{
"_id": "5ea5f8033a55270fe86744ed",
"idShipment": {
"_id": "5ea5f74f3a55270fe86744eb",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e98344c2ce39e16d27d7e8d"
},
"idMaterialType": "fragile",
"length": 2,
"width": 2,
"height": 5,
"weight": 3,
"quantity": 3,
"code": "RQ123LQ",
"status": "Onboarded"
},
"damage": "No",
"createdAt": "2020-04-26T21:07:15.287Z",
"updatedAt": "2020-04-26T21:07:15.287Z"
},
{
"_id": "5ea5f8033a55270fe86744ee",
"idShipment": {
"_id": "5ea5f74f3a55270fe86744e8",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e9833cc2ce39e16d27d7e8c"
},
"idMaterialType": "fragile",
"length": 3,
"width": 4,
"height": 5,
"weight": 3,
"quantity": 23,
"code": "RQ123IT",
"status": "Onboarded"
},
"damage": "No",
"createdAt": "2020-04-26T21:07:15.287Z",
"updatedAt": "2020-04-26T21:07:15.287Z"
},
{
"_id": "5ea5f8033a55270fe86744ef",
"idShipment": {
"_id": "5ea5f74f3a55270fe86744e7",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e9833cc2ce39e16d27d7e8c"
},
"idMaterialType": "fragile",
"length": 3,
"width": 4,
"height": 5,
"weight": 2,
"quantity": 6,
"code": "RQ123NT",
"status": "Onboarded"
},
"damage": "No",
"createdAt": "2020-04-26T21:07:15.287Z",
"updatedAt": "2020-04-26T21:07:15.287Z"
}
],
"totalOnboard": 5
},
"ConsignmentOnboard": {
"consignementOnboard": [
{
"_id": "5ea1e92257aa5a2916826ff3",
"idShipment": {
"_id": "5e9def4be399e80dbbd09775",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e98505b2ce39e16d27d7e90"
},
"idMaterialType": "dangerous",
"length": 2,
"width": 4,
"height": 2,
"weight": 6,
"quantity": 3,
"code": "RQ123ZR",
"status": "In Linehaul Tansist"
},
"damage": "No",
"createdAt": "2020-04-23T19:14:42.383Z",
"updatedAt": "2020-04-23T19:14:42.383Z"
},
{
"_id": "5ea1ea1f57aa5a2916826ff5",
"idShipment": {
"_id": "5e9def4be399e80dbbd09774",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e9850ee2ce39e16d27d7e91"
},
"idMaterialType": "fragile",
"length": 5,
"width": 3,
"height": 2,
"weight": 6,
"quantity": 2,
"code": "RQ123DS",
"status": "In Linehaul Tansist"
},
"damage": "No",
"createdAt": "2020-04-23T19:18:55.723Z",
"updatedAt": "2020-04-23T19:18:55.724Z"
},
{
"_id": "5ea5f8033a55270fe86744f0",
"idShipment": {
"_id": "5e9def4be399e80dbbd09771",
"idOrder": {
"consigneeDetails": {
"name": "Raju",
"contact": 9089089898
},
"_id": "5e9851e92ce39e16d27d7e95"
},
"idMaterialType": "fragile",
"length": 4,
"width": 3,
"height": 2,
"weight": 6,
"quantity": 3,
"code": "RQ123ZX",
"status": "In Linehaul Tansist"
},
"damage": "No",
"createdAt": "2020-04-26T21:07:15.287Z",
"updatedAt": "2020-04-26T21:07:15.287Z"
}
],
"totalConsignmentOnboard": 3
},
"totalcapacityutilization": 2,
"totalWeightUtilization": 5
}
router.get('/:idLineHaul', async (req, res) => {
try {
if (req.user && req.user.roles.includes('franchisee')) {
var linehaul3= await MhcvSoftBlock.findOne({_id:req.params.idLineHaul})
.select('weightCapacityUtilized volumeCapacityUtilized expectedStartDate expectedEndDate idVehicleRegistered ETA')
.populate({
path:'idVehicleRegistered',
select:'vehicleNumber registrationNumber volumeCapacityInCubicFeet vehicleWeightCapacityInKgs vehicleType name phone'
})
console.log(linehaul3)
if(!linehaul3){
logger.info('****** LineHaul not fount in this Id *******')
res.status(400).send(responseTemplate.errorMessage('Linehaul not found'));
}
else{
var newObj = [], vehichleVolumeCapacityOfTruck, vehicleWeightCapacity;
if(linehaul3){
newObj.push(linehaul3)
vehichleVolumeCapacityOfTruck = newObj[0].idVehicleRegistered.volumeCapacityInCubicFeet;
vehicleWeightCapacity = newObj[0].idVehicleRegistered.vehicleWeightCapacityInKgs
console.log("vehichleVolumeCapacityOfTruck: ",vehichleVolumeCapacityOfTruck)
console.log("vehicleWeightCapacity: ",vehicleWeightCapacity)
}
var linehaulShipment =await LineHaulShipment.find({idLineHaul:linehaul3.id}).select('-idLineHaul -_v')
.populate({
path:'idShipment', populate:{path:'idOrder', select:'consigneeDetails.name consigneeDetails.contact'},select:'idMaterialType length width height weight quantity code status'
})
if(linehaulShipment){
var obj=[], onboardArr =[], consignementOnboard=[];
linehaulShipment && linehaulShipment.map(abc=>{
// const checkCount = linehaulShipment.length
// console.log(abc,'================================>=================', checkCount)
obj.push(abc)
if(abc && abc.idShipment.status=="Onboarded"){
//console.log(abc.idShipment.length)
onboardArr.push(abc)
}else if(abc.idShipment.status=="In Linehaul Tansist"){
consignementOnboard.push(abc)
}
})
//total capacity utilization
var firstLength = onboardArr[0].idShipment.length
var firstwidth = onboardArr[0].idShipment.width
var firstheight = onboardArr[0].idShipment.height
var firstWeight = onboardArr[0].idShipment.weight
var firstquantity = onboardArr[0].idShipment.quantity
productCapacity = firstLength * firstwidth * firstheight * firstquantity;
console.log('Product Capacity in Cubic foot: ',productCapacity)
remainingcapacity = vehichleVolumeCapacityOfTruck - productCapacity;
console.log('remaining capacity:===========>',remainingcapacity)
// now we calculate total remaining capacity
remainingcapacityUtilization = (remainingcapacity/vehichleVolumeCapacityOfTruck) * 100;
console.log("remaining capacity utilization:========> ",remainingcapacityUtilization)
// now total utilization of truck capacity
totalcapacityutilization = Math.ceil(100-remainingcapacityUtilization);
console.log("totalcapacityutilization:===============>>>", totalcapacityutilization)
//Total weight capacity utilization
var productWeight = firstWeight * firstquantity * 10;
var totalWeightRemaining = vehicleWeightCapacity - productWeight;
console.log("Remaining Weight================>", totalWeightRemaining)
//Remaining weight utilization
var remainingWeightcapacity = (totalWeightRemaining/vehicleWeightCapacity) * 100
console.log(remainingWeightcapacity);
var storeData = 0;
//total weight utilization
var wieghtObj = [];
totalWeightUtilization = Math.ceil(100 - remainingWeightcapacity);
console.log(totalWeightUtilization);
storeData = storeData + totalWeightUtilization;
console.log(storeData);
wieghtObj.push(totalWeightUtilization);
console.log("this is weight object",wieghtObj)
var totalOnboard = onboardArr.length;
console.log(totalOnboard)
//var newdata ={'OnboardArray':onboardArr};
const totalConsignmentOnboard = consignementOnboard.length;
res.send({success:'Fetched Linehaul',
linehaul:{
idLineHaul:linehaul3
,packageList:onboardArr,
totalOnboard
},
ConsignmentOnboard:{consignementOnboard,
totalConsignmentOnboard
},
totalcapacityutilization,
totalWeightUtilization
})
}
if(!linehaulShipment){
logger.info('********No linehaul shipment in this IdLinehaul*****')
res.status(403).send(responseTemplate.errorMessage('No Linehaul exist'));
}
}
}
if(req.user && !req.user.roles.includes('franchisee')){
logger.info('********User is not a Franchisee*****')
res.status(403).send(responseTemplate.errorMessage('User must be a Franchisee'));
}
if (!req.user) {
logger.info('******* User Not Found *******')
res.status(404).send(responseTemplate.errorMessage('User not found'));
}
} catch (e) {
logger.info('***** error occured ***', e);
res.status(501).send(responseTemplate.error('some error occured'));
}
});
Примечание Если отгрузка добавляется, объем и грузоподъемность транспортного средства увеличиваются
Спасибо