Add checking of flags for JO auto assignment. #607
This commit is contained in:
parent
49fdfa9ea6
commit
f54476a173
5 changed files with 76 additions and 42 deletions
|
|
@ -2814,49 +2814,81 @@ class APIController extends Controller implements LoggedController
|
|||
{
|
||||
// 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());
|
||||
foreach ($nearest_hubs as $nearest_hub)
|
||||
{
|
||||
$available_riders = $nearest_hub['hub']->getAvailableRiders();
|
||||
if (count($available_riders) >= 1)
|
||||
// check if hub can be auto assigned
|
||||
// if not, move on to the next hub in the list
|
||||
if (($nearest_hub['hub']->isHubAutoAssign()))
|
||||
{
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) == 1)
|
||||
// check if hub has riders that can be auto assigned
|
||||
// if not, move on to the next hub
|
||||
if (($nearest_hub['hub']->isRiderAutoAssign()))
|
||||
{
|
||||
$assigned_rider = $available_riders[0];
|
||||
$available_riders = $nearest_hub['hub']->getAvailableRiders();
|
||||
if (count($available_riders) >= 1)
|
||||
{
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) == 1)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
$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
|
||||
{
|
||||
// we just create the JO and let admin panel handle the hub assignment
|
||||
// log hub into hub_filter_log
|
||||
$hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID());
|
||||
// continue to go through list to find hub with an available rider
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
// TODO: log hub as cannot be auto rider assigned somewhere
|
||||
// assign hub
|
||||
error_log('Rider cannot be auto assigned ' . $nearest_hub['hub']->getID());
|
||||
$jo->setHub($nearest_hub['hub']);
|
||||
$jo->setStatus(JOStatus::RIDER_ASSIGN);
|
||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_ASSIGNED);
|
||||
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
// update redis hub_jo_count for hub
|
||||
$hub_dist->incrementJoCountForHub($nearest_hub['hub']);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$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
|
||||
{
|
||||
// log hub into hub_filter_log
|
||||
$hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID());
|
||||
// continue to go through list to find hub with an available rider
|
||||
// TODO: log hub as cannot be auto assigned somewhere
|
||||
// move to next hub
|
||||
error_log('Hub cannot be auto-assigned ' . $nearest_hub['hub']->getID());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ class HubController extends Controller
|
|||
->setRiderSlots($req->request->get('rider_slots', 0))
|
||||
->setHubViewFlag($req->request->get('flag_hub_view', false))
|
||||
->setNotifNumber($req->request->get('notif_number'))
|
||||
->setAutoAssignHub($req->request->get('flag_hub_auto_assign', false))
|
||||
->setAutoAssignRider($req->request->get('flag_rider_auto_assign', false))
|
||||
->setHubAutoAssign($req->request->get('flag_hub_auto_assign', false))
|
||||
->setRiderAutoAssign($req->request->get('flag_rider_auto_assign', false))
|
||||
->clearPaymentMethods();
|
||||
|
||||
// set payment methods
|
||||
|
|
|
|||
|
|
@ -247,24 +247,24 @@ class Hub
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setAutoAssignHub($flag_hub_auto_assign = true)
|
||||
public function setHubAutoAssign($flag_hub_auto_assign = true)
|
||||
{
|
||||
$this->flag_hub_auto_assign = $flag_hub_auto_assign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAutoAssignHub()
|
||||
public function isHubAutoAssign()
|
||||
{
|
||||
return $this->flag_hub_auto_assign;
|
||||
}
|
||||
|
||||
public function setAutoAssignRider($flag_rider_auto_assign = true)
|
||||
public function setRiderAutoAssign($flag_rider_auto_assign = true)
|
||||
{
|
||||
$this->flag_rider_auto_assign = $flag_rider_auto_assign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAutoAssignRider()
|
||||
public function isRiderAutoAssign()
|
||||
{
|
||||
return $this->flag_rider_auto_assign;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,11 +154,13 @@ class MapTools
|
|||
*/
|
||||
}
|
||||
|
||||
// NOTE: only the API calls this
|
||||
// NOTE: only the API(findAdvanceNearestHubAndSlots) calls this
|
||||
public function getClosestOpenHubs(Point $point, $limit, $time = false)
|
||||
{
|
||||
// get closest hubs based on st_distance function from db
|
||||
$query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h WHERE h.status_open = true';
|
||||
$query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h
|
||||
WHERE h.status_open = true
|
||||
AND h.flag_hub_auto_assign = true';
|
||||
if ($time)
|
||||
$query_string .= ' AND :time BETWEEN h.time_open AND h.time_close';
|
||||
$query_string .= ' ORDER BY dist';
|
||||
|
|
@ -172,7 +174,7 @@ class MapTools
|
|||
|
||||
$query->setMaxResults($limit);
|
||||
|
||||
// error_log($query->getSql());
|
||||
//error_log($query->getSql());
|
||||
$result = $query->getResult();
|
||||
|
||||
$hubs = [];
|
||||
|
|
|
|||
|
|
@ -121,14 +121,14 @@
|
|||
<div class="col-lg-3">
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_hub_auto_assign" id="status-open" value="1"{{ obj.isAutoAssignHub ? ' checked' }}>
|
||||
<input type="checkbox" name="flag_hub_auto_assign" id="status-open" value="1"{{ obj.isHubAutoAssign ? ' checked' }}>
|
||||
<label class="switch-label">Hub Auto-Assign</label>
|
||||
<span></span>
|
||||
</label>
|
||||
</span>
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_rider_auto_assign" id="status-open" value="1"{{ obj.isAutoAssignRider ? ' checked' }}>
|
||||
<input type="checkbox" name="flag_rider_auto_assign" id="status-open" value="1"{{ obj.isRiderAutoAssign ? ' checked' }}>
|
||||
<label class="switch-label">Rider Auto-Assign</label>
|
||||
<span></span>
|
||||
</label>
|
||||
|
|
|
|||
Loading…
Reference in a new issue