Fix the command to update unaccepted job orders. Add more checking before updating rider's availability. #630
This commit is contained in:
parent
9f5493c125
commit
f9de11ccb5
2 changed files with 23 additions and 16 deletions
|
|
@ -75,25 +75,21 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
||||||
$requeued_jos[] = [
|
$requeued_jos[] = [
|
||||||
'jo' => $requeued_jo,
|
'jo' => $requeued_jo,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$update_sql = 'UPDATE job_order SET status = :new_status, rider_id = null WHERE id = :jo_id';
|
||||||
|
$update_stmt = $db->prepare($update_sql);
|
||||||
|
$update_stmt->execute([
|
||||||
|
'new_status' => $new_status,
|
||||||
|
'jo_id' => $jo_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the assigned job orders and have been unaccepted for at least 3 minutes
|
|
||||||
// change the jo status from assigned to rider_assign and rider id to null
|
|
||||||
$update_sql = 'UPDATE job_order SET status = :new_status, rider_id = null WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
|
|
||||||
|
|
||||||
$update_stmt = $db->prepare($update_sql);
|
|
||||||
$update_stmt->execute([
|
|
||||||
'new_status' => $new_status,
|
|
||||||
'current_status' => $current_status,
|
|
||||||
'timeout' => $timeout,
|
|
||||||
]);
|
|
||||||
|
|
||||||
foreach ($requeued_jos as $jo_info)
|
foreach ($requeued_jos as $jo_info)
|
||||||
{
|
{
|
||||||
$jo = $jo_info['jo'];
|
$jo = $jo_info['jo'];
|
||||||
if ($jo != null)
|
if ($jo != null)
|
||||||
{
|
{
|
||||||
// $output->writeln('Requeuing for rider assignment ' . $jo->getID());
|
$output->writeln('Requeuing for rider assignment ' . $jo->getID());
|
||||||
$id = $jo->getID();
|
$id = $jo->getID();
|
||||||
|
|
||||||
// send notifications to rider app, telling rider that jo has been requeued
|
// send notifications to rider app, telling rider that jo has been requeued
|
||||||
|
|
@ -104,6 +100,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
||||||
];
|
];
|
||||||
$mclient->sendRiderEvent($jo, $rider_payload);
|
$mclient->sendRiderEvent($jo, $rider_payload);
|
||||||
|
|
||||||
|
|
||||||
// send outlet assign since order should go back to hub and await reassignment to another rider
|
// send outlet assign since order should go back to hub and await reassignment to another rider
|
||||||
$payload = [
|
$payload = [
|
||||||
'event' => 'outlet_assign',
|
'event' => 'outlet_assign',
|
||||||
|
|
@ -115,11 +112,19 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
||||||
$rider = $jo->getRider();
|
$rider = $jo->getRider();
|
||||||
if ($rider != null)
|
if ($rider != null)
|
||||||
{
|
{
|
||||||
// set rider's availability to true
|
// check rider's current job order before changing rider's availability
|
||||||
$rider->setAvailable(true);
|
// since rider's current job order is set when JO is assigned to rider
|
||||||
|
if ($rider->getCurrentJobOrder() != null)
|
||||||
|
{
|
||||||
|
if ($rider->getCurrentJobOrder()->getID() == $jo->getID())
|
||||||
|
{
|
||||||
|
// reset rider's availability to true
|
||||||
|
$rider->setAvailable(true);
|
||||||
|
|
||||||
// set rider's current job order to null
|
// set rider's current job order to null
|
||||||
$rider->setCurrentJobOrder();
|
$rider->setCurrentJobOrder();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -565,6 +565,8 @@ class RiderController extends Controller
|
||||||
public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id)
|
public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id)
|
||||||
{
|
{
|
||||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||||
|
// TODO: change this to setCurrentJobOrder since this is what is being used to set rider's
|
||||||
|
// job order. It is no longer using setActiveJobOrder.
|
||||||
$rider->setActiveJobOrder($jo);
|
$rider->setActiveJobOrder($jo);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue