Add hub round robin to requestJobOrder. #543
This commit is contained in:
parent
6bc24c4756
commit
f7983e4c1d
1 changed files with 55 additions and 36 deletions
|
|
@ -848,7 +848,8 @@ class APIController extends Controller implements LoggedController
|
||||||
|
|
||||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||||
RiderAssignmentHandlerInterface $rah)
|
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
|
||||||
|
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -1013,30 +1014,37 @@ class APIController extends Controller implements LoggedController
|
||||||
$invoice = $ic->generateInvoice($icrit);
|
$invoice = $ic->generateInvoice($icrit);
|
||||||
$jo->setInvoice($invoice);
|
$jo->setInvoice($invoice);
|
||||||
|
|
||||||
// assign hub and rider
|
|
||||||
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
|
||||||
($jo->getServicetype() == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
|
||||||
{
|
|
||||||
// TODO: call HubSelector service here
|
|
||||||
// get nearest hub
|
|
||||||
// $nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
|
||||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO: call HubSelector service here
|
|
||||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($nearest_hub))
|
// TODO: set this properly, since the other flags
|
||||||
|
// are on default values
|
||||||
|
$hub_criteria = new HubCriteria();
|
||||||
|
$hub_criteria->setPoint($jo->getCoordinates())
|
||||||
|
->setJoType($jo->getServiceType());
|
||||||
|
|
||||||
|
// add battery to items
|
||||||
|
$sku = $batt->getSAPCode();
|
||||||
|
if (!empty($sku))
|
||||||
|
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||||
|
|
||||||
|
// find nearest hubs
|
||||||
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
|
|
||||||
|
if (!empty($nearest_hubs))
|
||||||
{
|
{
|
||||||
|
// go through the hub list, find the nearest hub
|
||||||
|
// with an available rider
|
||||||
//error_log('found nearest hub ' . $nearest_hub->getID());
|
//error_log('found nearest hub ' . $nearest_hub->getID());
|
||||||
// assign rider
|
foreach ($nearest_hubs as $nearest_hub)
|
||||||
$available_riders = $nearest_hub->getAvailableRiders();
|
{
|
||||||
if (count($available_riders) > 0)
|
$available_riders = $nearest_hub['hub']->getAvailableRiders();
|
||||||
|
if (count($available_riders) >= 1)
|
||||||
{
|
{
|
||||||
$assigned_rider = null;
|
$assigned_rider = null;
|
||||||
if (count($available_riders) > 1)
|
if (count($available_riders) == 1)
|
||||||
|
{
|
||||||
|
$assigned_rider = $available_riders[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// TODO: the setting of riders into an array
|
// TODO: the setting of riders into an array
|
||||||
// will no longer be necessary when the contents
|
// will no longer be necessary when the contents
|
||||||
|
|
@ -1049,15 +1057,26 @@ class APIController extends Controller implements LoggedController
|
||||||
|
|
||||||
$assigned_rider = $this->randomizeRider($riders);
|
$assigned_rider = $this->randomizeRider($riders);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$assigned_rider = $available_riders[0];
|
|
||||||
|
|
||||||
//error_log('found rider ' . $assigned_rider->getID());
|
$jo->setHub($nearest_hub['hub']);
|
||||||
$jo->setHub($nearest_hub);
|
|
||||||
$jo->setRider($assigned_rider);
|
$jo->setRider($assigned_rider);
|
||||||
$jo->setStatus(JOStatus::ASSIGNED);
|
$jo->setStatus(JOStatus::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_hub['hub']);
|
||||||
|
|
||||||
|
// break out of loop
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// log hub into hub_filter_log
|
||||||
|
$hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider');
|
||||||
|
// continue to go through list to find hub with an available rider
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue