Add geofence hub filtering to mobile API and to dispatch form. #575

This commit is contained in:
Korina Cordero 2021-06-24 06:09:48 +00:00
parent 12fd768849
commit f40f6974e2
2 changed files with 67 additions and 24 deletions

View file

@ -45,6 +45,7 @@ use App\Service\PromoLogger;
use App\Service\HubSelector;
use App\Service\HubDistributor;
use App\Service\HubFilterLogger;
use App\Service\HubFilteringGeoChecker;
use App\Entity\MobileSession;
use App\Entity\Customer;
@ -856,7 +857,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, PromoLogger $promo_logger,
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
HubFilteringGeoChecker $hub_geofence)
{
// check required parameters and api key
$required_params = [
@ -1021,13 +1023,20 @@ class APIController extends Controller implements LoggedController
$invoice = $ic->generateInvoice($icrit);
$jo->setInvoice($invoice);
// 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
// set more hub criteria fields
$hub_criteria = new HubCriteria();
$hub_criteria->setPoint($jo->getCoordinates())
->setJoType($jo->getServiceType());
$hub_criteria->setPoint($jo->getCoordinates());
if ($hub_geofence->isCovered($long, $lat))
{
// TODO: set this properly, since the other flags
// are on default values.
// if true, set other values for HubCriteria
// error_log('Area is covered by hub filtering');
$hub_criteria->setJoType($jo->getServiceType())
->setPaymentMethod($jo->getModeOfPayment())
->setRoundRobin(true);
}
// add battery to items
$sku = $batt->getSAPCode();
@ -2395,7 +2404,8 @@ class APIController extends Controller implements LoggedController
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
HubFilteringGeoChecker $hub_geofence)
{
// check required parameters and api key
$required_params = [
@ -2580,13 +2590,19 @@ class APIController extends Controller implements LoggedController
// check if hub is null
if ($hub == null)
{
// 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());
$hub_criteria->setPoint($jo->getCoordinates());
if ($hub_geofence->isCovered($long, $lat))
{
// if true, set other values for HubCriteria
// TODO: set this properly, since the other flags
// are on default values
// error_log('Area is covered by hub filtering');
$hub_criteria->setJoType($jo->getServiceType())
->setPaymentMethod($jo->getModeOfPayment())
->setRoundRobin(true);
}
// add battery to items
$sku = $batt->getSAPCode();

View file

@ -55,6 +55,7 @@ use App\Service\RisingTideGateway;
use App\Service\PromoLogger;
use App\Service\HubSelector;
use App\Service\HubDistributor;
use App\Service\HubFilteringGeoChecker;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
@ -78,6 +79,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
protected $rt;
protected $promo_logger;
protected $hub_dist;
protected $hub_geofence;
protected $template_hash;
@ -85,7 +87,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
PromoLogger $promo_logger, HubDistributor $hub_dist)
PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence)
{
$this->em = $em;
$this->ic = $ic;
@ -98,6 +100,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->rt = $rt;
$this->promo_logger = $promo_logger;
$this->hub_dist = $hub_dist;
$this->hub_geofence = $hub_geofence;
$this->loadTemplates();
}
@ -498,7 +501,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
{
foreach ($customer_tags as $customer_tag)
{
// TODO: not too comfy with this being hardcoded
if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId())
{
// remove associated entity
@ -1973,13 +1975,21 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// get closest hubs
// set hub criteria
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria
// set more hub criteria fields
$long = $obj->getCoordinates()->getLongitude();
$lat = $obj->getCoordinates()->getLatitude();
$hub_criteria->setPoint($obj->getCoordinates())
->setLimitResults(50)
->setPaymentMethod($obj->getModeOfPayment())
->setJoType($obj->getServiceType());
->setLimitResults(50);
if ($this->hub_geofence->isCovered($long, $lat))
{
// if true, set other values for HubCriteria
// error_log('Area is covered by hub filtering');
$hub_criteria->setPaymentMethod($obj->getModeOfPayment())
->setJoType($obj->getServiceType())
->setRoundRobin(true);
}
// check if emergency or not
$willing_to_wait = $obj->getWillWait();
@ -2262,10 +2272,27 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// get closest hubs
// TODO: check the new service HubFilteringGeoChecker
// if true, set other values for HubCriteria
// set more hub criteria fields
$long = $obj->getCoordinates()->getLongitude();
$lat = $obj->getCoordinates()->getLatitude();
$hub_criteria->setPoint($obj->getCoordinates())
->setLimitResults(50);
if ($this->hub_geofence->isCovered($long, $lat))
{
// if true, set other values for HubCriteria
// error_log('Area is covered by hub');
$hub_criteria->setPaymentMethod($obj->getModeOfPayment())
->setJoType($obj->getServiceType())
->setRoundRobin(true);
}
// check if emergency or not
$willing_to_wait = $obj->getWillWait();
if ($willing_to_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT)
$hub_criteria->setEmergency(true);
$hubs = $hub_selector->find($hub_criteria);
$params['status_cancelled'] = JOStatus::CANCELLED;