From f40f6974e2989839c425cb1b5280479c3296e7e3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Jun 2021 06:09:48 +0000 Subject: [PATCH] Add geofence hub filtering to mobile API and to dispatch form. #575 --- src/Controller/APIController.php | 44 +++++++++++------ .../JobOrderHandler/ResqJobOrderHandler.php | 47 +++++++++++++++---- 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4b8e9cf1..dc5f431a 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -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(); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 6888afe4..3637e4a1 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -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;