Add sendRiderEvent call for MQTTClient service #151
This commit is contained in:
parent
128dd352d9
commit
cbdc2fd24e
4 changed files with 39 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ use App\Ramcar\TradeInType;
|
||||||
|
|
||||||
use App\Service\InvoiceCreator;
|
use App\Service\InvoiceCreator;
|
||||||
use App\Service\RisingTideGateway;
|
use App\Service\RisingTideGateway;
|
||||||
|
use App\Service\MQTTClient;
|
||||||
|
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
|
|
||||||
|
|
@ -1168,6 +1168,7 @@ class JobOrderController extends BaseController
|
||||||
'event' => 'driver_assigned'
|
'event' => 'driver_assigned'
|
||||||
];
|
];
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
$mclient->sendRiderEvent($obj, $payload);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
|
|
@ -1361,6 +1362,7 @@ class JobOrderController extends BaseController
|
||||||
'driver_id' => $rider->getID(),
|
'driver_id' => $rider->getID(),
|
||||||
];
|
];
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
$mclient->sendRiderEvent($obj, $payload);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
|
|
@ -2135,6 +2137,7 @@ class JobOrderController extends BaseController
|
||||||
'jo_id' => $obj->getID(),
|
'jo_id' => $obj->getID(),
|
||||||
];
|
];
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
$mclient->sendRiderEvent($obj, $payload);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,17 @@ class Rider
|
||||||
*/
|
*/
|
||||||
protected $password;
|
protected $password;
|
||||||
|
|
||||||
|
// rider sessions
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="RiderSession", mappedBy="rider")
|
||||||
|
*/
|
||||||
|
protected $sessions;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->job_orders = new ArrayCollection();
|
$this->job_orders = new ArrayCollection();
|
||||||
$this->schedules = new ArrayCollection();
|
$this->schedules = new ArrayCollection();
|
||||||
|
$this->sessions = new ArrayCollection();
|
||||||
$this->curr_rating = 0;
|
$this->curr_rating = 0;
|
||||||
$this->flag_available = true;
|
$this->flag_available = true;
|
||||||
$this->flag_active = true;
|
$this->flag_active = true;
|
||||||
|
|
@ -307,4 +314,9 @@ class Rider
|
||||||
|
|
||||||
return $this->job_orders->matching($criteria)[0];
|
return $this->job_orders->matching($criteria)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSessions()
|
||||||
|
{
|
||||||
|
return $this->sessions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use App\Entity\JobOrder;
|
||||||
class MQTTClient
|
class MQTTClient
|
||||||
{
|
{
|
||||||
const PREFIX = 'motolite.control.';
|
const PREFIX = 'motolite.control.';
|
||||||
|
const RIDER_PREFIX = 'motorider.';
|
||||||
|
|
||||||
protected $mclient;
|
protected $mclient;
|
||||||
|
|
||||||
|
|
@ -36,6 +37,7 @@ class MQTTClient
|
||||||
if (count($sessions) == 0)
|
if (count($sessions) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// send to every customer session
|
||||||
foreach ($sessions as $sess)
|
foreach ($sessions as $sess)
|
||||||
{
|
{
|
||||||
$phone_num = $sess->getPhoneNumber();
|
$phone_num = $sess->getPhoneNumber();
|
||||||
|
|
@ -43,4 +45,25 @@ class MQTTClient
|
||||||
$this->publish($channel, json_encode($payload));
|
$this->publish($channel, json_encode($payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sendRiderEvent(JobOrder $job_order, $payload)
|
||||||
|
{
|
||||||
|
// check if a rider is available
|
||||||
|
$rider = $job_order->getRider();
|
||||||
|
if ($rider == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// check if rider has sessions
|
||||||
|
$sessions = $rider->getSessions();
|
||||||
|
if (count($sessions) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// send to every rider session
|
||||||
|
foreach ($sessions as $sess)
|
||||||
|
{
|
||||||
|
$sess_id = $sess->getID();
|
||||||
|
$channel = self::RIDER_PREFIX . $sess_id;
|
||||||
|
$this->publish($channel, json_encode($payload));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue