Add round robin flag to HubCriteria. #575

This commit is contained in:
Korina Cordero 2021-06-23 10:39:49 +00:00
parent b4c8da134c
commit e61c3f1762
5 changed files with 29 additions and 2 deletions

View file

@ -294,3 +294,5 @@ services:
App\Service\HubFilterLogger:
arguments:
$em: "@doctrine.orm.entity_manager"
# TODO: add the HubFilteringGeoChecker here

View file

@ -1023,6 +1023,8 @@ class APIController extends Controller implements LoggedController
// TODO: set this properly, since the other flags
// are on default values
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria, if any
$hub_criteria = new HubCriteria();
$hub_criteria->setPoint($jo->getCoordinates())
->setJoType($jo->getServiceType());
@ -2580,6 +2582,8 @@ class APIController extends Controller implements LoggedController
{
// TODO: set this properly, since the other flags
// are on default values
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria, if any
$hub_criteria = new HubCriteria();
$hub_criteria->setPoint($jo->getCoordinates())
->setJoType($jo->getServiceType());

View file

@ -17,6 +17,7 @@ class HubCriteria
protected $items; // array of items: items[sku] = quantity to check for
protected $payment_method; // payment method of JO
protected $flag_emergency; // flag if emergency or not
protected $flag_round_robin; // flag if we use round robin or not
public function __construct()
{
@ -29,6 +30,7 @@ class HubCriteria
$this->items = [];
$this->payment_method = '';
$flag_emergency = false;
$flag_round_robin = false;
}
public function setPoint(Point $point)
@ -131,5 +133,17 @@ class HubCriteria
{
return $this->flag_emergency;
}
public function setRoundRobin($flag_round_robin = true)
{
$this->flag_round_robin = $flag_round_robin;
return $this;
}
public function isRoundRobin()
{
return $this->flag_round_robin;
}
}

View file

@ -50,6 +50,7 @@ class HubSelector
$date_time = $criteria->getDateTime();
$payment_method = $criteria->getPaymentMethod();
$flag_emergency = $criteria->isEmergency();
$flag_round_robin = $criteria->isRoundRobin();
$results = [];
@ -86,7 +87,7 @@ class HubSelector
//error_log('inventory hubs ' . json_encode($filtered_hubs));
// round robin filter
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs, $flag_round_robin);
$filtered_hubs = $hubs_round_robin;
//error_log('round robin hubs ' . json_encode($filtered_hubs));
@ -103,10 +104,12 @@ class HubSelector
return $results;
}
protected function filterHubsByRoundRobin($hubs)
protected function filterHubsByRoundRobin($hubs, $flag_round_robin)
{
if (empty($hubs))
return $hubs;
if (!$flag_round_robin)
return $hubs;
$results = [];
// call hub distributor service

View file

@ -1974,6 +1974,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get closest hubs
// set hub criteria
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria
$hub_criteria->setPoint($obj->getCoordinates())
->setLimitResults(50)
->setPaymentMethod($obj->getModeOfPayment())
@ -2260,6 +2262,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// get closest hubs
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria
$hub_criteria->setPoint($obj->getCoordinates())
->setLimitResults(50);
$hubs = $hub_selector->find($hub_criteria);