Update hub_jo_count when hub is assigned or reassigned via admin panel. #543
This commit is contained in:
parent
0115328801
commit
50e15cd770
3 changed files with 59 additions and 13 deletions
|
|
@ -2333,7 +2333,8 @@ class APIController extends Controller implements LoggedController
|
||||||
|
|
||||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||||
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select)
|
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
|
||||||
|
HubDistributor $hub_dist)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -2579,6 +2580,9 @@ class APIController extends Controller implements LoggedController
|
||||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
||||||
|
|
||||||
$assigned_rider->setAvailable(false);
|
$assigned_rider->setAvailable(false);
|
||||||
|
|
||||||
|
// update redis hub_jo_count for hub
|
||||||
|
$hub_dist->incrementJoCountForHub($nearest_hubs[0]['hub']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2602,6 +2606,9 @@ class APIController extends Controller implements LoggedController
|
||||||
|
|
||||||
if ($date_schedule != null)
|
if ($date_schedule != null)
|
||||||
$jo->setDateSchedule($date_schedule);
|
$jo->setDateSchedule($date_schedule);
|
||||||
|
|
||||||
|
// update redis hub_jo_count for hub
|
||||||
|
$hub_dist->incrementJoCountForHub($hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->persist($jo);
|
$em->persist($jo);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class HubDistributor
|
||||||
$this->hub_jo_key = $hub_jo_key;
|
$this->hub_jo_key = $hub_jo_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addJoCountForHub(Hub $hub)
|
public function incrementJoCountForHub(Hub $hub)
|
||||||
{
|
{
|
||||||
$key = $hub->getID();
|
$key = $hub->getID();
|
||||||
|
|
||||||
|
|
@ -38,6 +38,20 @@ class HubDistributor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function decrementJoCountForHub(Hub $hub)
|
||||||
|
{
|
||||||
|
$key = $hub->getID();
|
||||||
|
|
||||||
|
// get current count
|
||||||
|
$jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||||
|
if ($jo_count)
|
||||||
|
{
|
||||||
|
// hub exist in hash
|
||||||
|
// decrement count
|
||||||
|
$this->redis->hset($this->hub_jo_key, $key, $jo_count - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function arrangeHubs($hubs)
|
public function arrangeHubs($hubs)
|
||||||
{
|
{
|
||||||
if (count($hubs) == 1)
|
if (count($hubs) == 1)
|
||||||
|
|
@ -57,6 +71,18 @@ class HubDistributor
|
||||||
|
|
||||||
// check if hub is in hash. if not, hub has no jobs
|
// check if hub is in hash. if not, hub has no jobs
|
||||||
// but should still be added to results
|
// but should still be added to results
|
||||||
|
if ($hub_jo_count != null)
|
||||||
|
{
|
||||||
|
$arranged_hubs[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
'jo_count' => $hub_jo_count,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$arranged_hubs[] = [
|
$arranged_hubs[] = [
|
||||||
'hub' => $hub,
|
'hub' => $hub,
|
||||||
'db_distance' => $hub_data['db_distance'],
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
|
@ -64,10 +90,6 @@ class HubDistributor
|
||||||
'duration' => $hub_data['duration'],
|
'duration' => $hub_data['duration'],
|
||||||
'jo_count' => 0,
|
'jo_count' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($hub_jo_count != null)
|
|
||||||
{
|
|
||||||
$arranged_hubs['jo_count'] = $hub_jo_count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ use App\Service\MQTTClient;
|
||||||
use App\Service\APNSClient;
|
use App\Service\APNSClient;
|
||||||
use App\Service\MapTools;
|
use App\Service\MapTools;
|
||||||
use App\Service\RisingTideGateway;
|
use App\Service\RisingTideGateway;
|
||||||
|
use App\Service\HubDistributor;
|
||||||
|
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
|
|
@ -70,13 +71,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
protected $country_code;
|
protected $country_code;
|
||||||
protected $wh;
|
protected $wh;
|
||||||
protected $rt;
|
protected $rt;
|
||||||
|
protected $hub_dist;
|
||||||
|
|
||||||
protected $template_hash;
|
protected $template_hash;
|
||||||
|
|
||||||
public function __construct(Security $security, EntityManagerInterface $em,
|
public function __construct(Security $security, EntityManagerInterface $em,
|
||||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||||
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||||
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt)
|
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
|
||||||
|
HubDistributor $hub_dist)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->ic = $ic;
|
$this->ic = $ic;
|
||||||
|
|
@ -87,6 +90,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
$this->country_code = $country_code;
|
$this->country_code = $country_code;
|
||||||
$this->wh = $wh;
|
$this->wh = $wh;
|
||||||
$this->rt = $rt;
|
$this->rt = $rt;
|
||||||
|
$this->hub_dist = $hub_dist;
|
||||||
|
|
||||||
$this->loadTemplates();
|
$this->loadTemplates();
|
||||||
}
|
}
|
||||||
|
|
@ -753,6 +757,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
'event' => 'outlet_assign'
|
'event' => 'outlet_assign'
|
||||||
];
|
];
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
|
||||||
|
// update redis hub jo count
|
||||||
|
$this->hub_dist->incrementJoCountForHub($hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error_array;
|
return $error_array;
|
||||||
|
|
@ -1122,6 +1129,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
$more_reason = $req->request->get('not_wait_notes');
|
$more_reason = $req->request->get('not_wait_notes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get previously assigned hub, if any
|
||||||
|
$old_hub = $obj->getHub();
|
||||||
|
|
||||||
if (empty($error_array))
|
if (empty($error_array))
|
||||||
{
|
{
|
||||||
// rider mqtt event
|
// rider mqtt event
|
||||||
|
|
@ -1195,6 +1205,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
'event' => 'outlet_assign'
|
'event' => 'outlet_assign'
|
||||||
];
|
];
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
|
||||||
|
// update redis hub_jo_count for hub
|
||||||
|
// decrement old hub's count and increment new hub's count
|
||||||
|
if ($old_hub != null)
|
||||||
|
$this->hub_dist->decrementJoCountForHub($old_hub);
|
||||||
|
if ($hub != null)
|
||||||
|
$this->hub_dist->incrementJoCountForHub($hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error_array;
|
return $error_array;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue