Add rider assignment handler for resq. #333
This commit is contained in:
parent
8bbc39ec9e
commit
0df0955cb3
5 changed files with 94 additions and 27 deletions
|
|
@ -179,6 +179,12 @@ services:
|
||||||
# customer generator interface
|
# customer generator interface
|
||||||
App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\ResqCustomerHandler"
|
App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\ResqCustomerHandler"
|
||||||
|
|
||||||
|
# rider assignment
|
||||||
|
App\Service\RiderAssignmentHandler\ResqRiderAssignmentHandler: ~
|
||||||
|
|
||||||
|
# rider assignment interface
|
||||||
|
App\Service\RiderAssignmentHandlerInterface: "@App\\Service\\RiderAssignmentHandler\\ResqRiderAssignmentHandler"
|
||||||
|
|
||||||
# map manager
|
# map manager
|
||||||
#App\Service\GISManager\Bing: ~
|
#App\Service\GISManager\Bing: ~
|
||||||
App\Service\GISManager\OpenStreet: ~
|
App\Service\GISManager\OpenStreet: ~
|
||||||
|
|
|
||||||
|
|
@ -731,7 +731,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign job order
|
// assign job order
|
||||||
public function assignJobOrder(Request $req, $id, MQTTCLient $mclient, APNSClient $aclient)
|
public function assignJobOrder(Request $req, $id)
|
||||||
{
|
{
|
||||||
// get object data
|
// get object data
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
@ -827,7 +827,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// fulfill job order
|
// fulfill job order
|
||||||
public function fulfillJobOrder(Request $req, $id, MQTTClient $mclient)
|
public function fulfillJobOrder(Request $req, $id)
|
||||||
{
|
{
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ use App\Entity\Hub;
|
||||||
use App\Entity\Promo;
|
use App\Entity\Promo;
|
||||||
use App\Entity\Rider;
|
use App\Entity\Rider;
|
||||||
use App\Entity\JORejection;
|
use App\Entity\JORejection;
|
||||||
|
use App\Entity\Warranty;
|
||||||
|
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
|
|
@ -38,6 +39,7 @@ use App\Ramcar\JORejectionReason;
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
use App\Service\JobOrderHandlerInterface;
|
use App\Service\JobOrderHandlerInterface;
|
||||||
|
use App\Service\RiderAssignmentHandlerInterface;
|
||||||
use App\Service\WarrantyHandler;
|
use App\Service\WarrantyHandler;
|
||||||
use App\Service\MQTTClient;
|
use App\Service\MQTTClient;
|
||||||
use App\Service\APNSClient;
|
use App\Service\APNSClient;
|
||||||
|
|
@ -59,6 +61,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
protected $security;
|
protected $security;
|
||||||
protected $validator;
|
protected $validator;
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
protected $rah;
|
||||||
protected $country_code;
|
protected $country_code;
|
||||||
protected $wh;
|
protected $wh;
|
||||||
|
|
||||||
|
|
@ -66,14 +69,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
|
|
||||||
public function __construct(Security $security, EntityManagerInterface $em,
|
public function __construct(Security $security, EntityManagerInterface $em,
|
||||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||||
TranslatorInterface $translator, string $country_code,
|
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||||
WarrantyHandler $wh)
|
string $country_code, WarrantyHandler $wh)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->ic = $ic;
|
$this->ic = $ic;
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
$this->rah = $rah;
|
||||||
$this->country_code = $country_code;
|
$this->country_code = $country_code;
|
||||||
$this->wh = $wh;
|
$this->wh = $wh;
|
||||||
|
|
||||||
|
|
@ -515,7 +519,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign job order
|
// assign job order
|
||||||
public function assignJobOrder(Request $req, $id, MQTTCLient $mclient, APNSClient $aclient)
|
public function assignJobOrder(Request $req, $id)
|
||||||
{
|
{
|
||||||
// get object data
|
// get object data
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
@ -606,22 +610,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
// validated! save the entity
|
// validated! save the entity
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
// send event to mobile app
|
// call rider assignment handler's assignJobOrder
|
||||||
$payload = [
|
$this->rah->assignJobOrder($obj, $rider);
|
||||||
'event' => 'driver_assigned'
|
|
||||||
];
|
|
||||||
$mclient->sendEvent($obj, $payload);
|
|
||||||
$mclient->sendRiderEvent($obj, $payload);
|
|
||||||
|
|
||||||
// sned push notification
|
|
||||||
$aclient->sendPush($obj, "A RESQ rider is on his way to you.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error_array;
|
return $error_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fulfill job order
|
// fulfill job order
|
||||||
public function fulfillJobOrder(Request $req, $id, MQTTClient $mclient)
|
public function fulfillJobOrder(Request $req, $id)
|
||||||
{
|
{
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
@ -697,16 +694,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
if ($rider->getImageFile() != null)
|
if ($rider->getImageFile() != null)
|
||||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/' . $rider->getImageFile();
|
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/' . $rider->getImageFile();
|
||||||
|
|
||||||
// send to mqtt
|
// call rider assignment handler's fulfillJobOrder
|
||||||
$payload = [
|
$this->rah->fulfillJobOrder($obj, $image_url, $rider);
|
||||||
'event' => 'fulfilled',
|
|
||||||
'jo_id' => $obj->getID(),
|
|
||||||
'driver_image' => $image_url,
|
|
||||||
'driver_name' => $rider->getFullName(),
|
|
||||||
'driver_id' => $rider->getID(),
|
|
||||||
];
|
|
||||||
$mclient->sendEvent($obj, $payload);
|
|
||||||
$mclient->sendRiderEvent($obj, $payload);
|
|
||||||
|
|
||||||
// create the warranty if new battery only
|
// create the warranty if new battery only
|
||||||
if ($obj->getServiceType () == ServiceType::BATTERY_REPLACEMENT_NEW)
|
if ($obj->getServiceType () == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ interface JobOrderHandlerInterface
|
||||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient);
|
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||||
|
|
||||||
// assign job order
|
// assign job order
|
||||||
public function assignJobOrder(Request $req, int $id, MQTTCLient $mclient, APNSClient $aclient);
|
public function assignJobOrder(Request $req, int $id);
|
||||||
|
|
||||||
// fulfill job order
|
// fulfill job order
|
||||||
public function fulfillJobOrder(Request $req, int $id, MQTTClient $mclient);
|
public function fulfillJobOrder(Request $req, int $id);
|
||||||
|
|
||||||
// cancel job order
|
// cancel job order
|
||||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient);
|
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service\RiderAssignmentHandler;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Service\RiderAssignmentHandlerInterface;
|
||||||
|
use App\Service\MQTTClient;
|
||||||
|
use App\Service\APNSClient;
|
||||||
|
|
||||||
|
use App\Entity\JobOrder;
|
||||||
|
use App\Entity\Rider;
|
||||||
|
|
||||||
|
use App\Ramcar\JOStatus;
|
||||||
|
|
||||||
|
class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
protected $aclient;
|
||||||
|
protected $mclient;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
|
||||||
|
APNSClient $aclient)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
$this->mclient = $mclient;
|
||||||
|
$this->aclient = $aclient;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign job order to rider
|
||||||
|
public function assignJobOrder(JobOrder $obj, Rider $rider)
|
||||||
|
{
|
||||||
|
// create the payload
|
||||||
|
$payload = [
|
||||||
|
'event' => 'driver_assigned'
|
||||||
|
];
|
||||||
|
|
||||||
|
// send event
|
||||||
|
$this->mclient->sendEvent($obj, $payload);
|
||||||
|
|
||||||
|
// check if rider is available
|
||||||
|
if ($rider->isAvailable())
|
||||||
|
{
|
||||||
|
error_log('set rider availability to false');
|
||||||
|
// set rider to unavailable
|
||||||
|
$rider->setAvailable(false);
|
||||||
|
|
||||||
|
// send event to rider
|
||||||
|
$this->mclient->sendRiderEvent($obj, $payload);
|
||||||
|
|
||||||
|
// send push notification
|
||||||
|
$this->aclient->sendPush($obj, "A RESQ rider is on his way to you.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// complete job order
|
||||||
|
public function fulfillJobOrder(JobOrder $obj, string $image_url, Rider $rider)
|
||||||
|
{
|
||||||
|
// send to mqtt
|
||||||
|
$payload = [
|
||||||
|
'event' => 'fulfilled',
|
||||||
|
'jo_id' => $obj->getID(),
|
||||||
|
'driver_image' => $image_url,
|
||||||
|
'driver_name' => $rider->getFullName(),
|
||||||
|
'driver_id' => $rider->getID(),
|
||||||
|
];
|
||||||
|
$this->mclient->sendEvent($obj, $payload);
|
||||||
|
|
||||||
|
// send fulfill/complete event to rider
|
||||||
|
$this->mclient->sendRiderEvent($obj, $payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue