Add hub round robin to requestJobOrder. #543

This commit is contained in:
Korina Cordero 2021-04-21 03:22:51 +00:00
parent 6bc24c4756
commit f7983e4c1d

View file

@ -848,7 +848,8 @@ class APIController extends Controller implements LoggedController
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
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
$required_params = [
@ -1013,51 +1014,69 @@ class APIController extends Controller implements LoggedController
$invoice = $ic->generateInvoice($icrit);
$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());
// assign rider
$available_riders = $nearest_hub->getAvailableRiders();
if (count($available_riders) > 0)
foreach ($nearest_hubs as $nearest_hub)
{
$assigned_rider = null;
if (count($available_riders) > 1)
$available_riders = $nearest_hub['hub']->getAvailableRiders();
if (count($available_riders) >= 1)
{
// TODO: the setting of riders into an array
// will no longer be necessary when the contents
// of randomizeRider changes
$riders = [];
foreach ($available_riders as $rider)
$assigned_rider = null;
if (count($available_riders) == 1)
{
$riders[] = $rider;
$assigned_rider = $available_riders[0];
}
else
{
// TODO: the setting of riders into an array
// will no longer be necessary when the contents
// of randomizeRider changes
$riders = [];
foreach ($available_riders as $rider)
{
$riders[] = $rider;
}
$assigned_rider = $this->randomizeRider($riders);
}
$assigned_rider = $this->randomizeRider($riders);
$jo->setHub($nearest_hub['hub']);
$jo->setRider($assigned_rider);
$jo->setStatus(JOStatus::ASSIGNED);
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
$assigned_rider->setAvailable(false);
// update redis hub_jo_count for hub
$hub_dist->incrementJoCountForHub($nearest_hub['hub']);
// break out of loop
break;
}
else
$assigned_rider = $available_riders[0];
//error_log('found rider ' . $assigned_rider->getID());
$jo->setHub($nearest_hub);
$jo->setRider($assigned_rider);
$jo->setStatus(JOStatus::ASSIGNED);
$assigned_rider->setAvailable(false);
{
// 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
}
}
}