Keep confirmed route actions in driver status projection
This commit is contained in:
@@ -18,7 +18,7 @@ interface RouteActionDao {
|
|||||||
"""
|
"""
|
||||||
SELECT * FROM route_actions
|
SELECT * FROM route_actions
|
||||||
WHERE routeId = :routeId
|
WHERE routeId = :routeId
|
||||||
AND status IN ('PENDING', 'WAITING_FOR_PHOTOS', 'SYNCING', 'FAILED_RETRYABLE', 'FAILED_CONFLICT', 'FAILED_PERMANENT')
|
AND status IN ('PENDING', 'WAITING_FOR_PHOTOS', 'SYNCING', 'CONFIRMED', 'FAILED_RETRYABLE', 'FAILED_CONFLICT', 'FAILED_PERMANENT')
|
||||||
ORDER BY createdAtEpochMillis DESC
|
ORDER BY createdAtEpochMillis DESC
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
@@ -27,7 +27,7 @@ interface RouteActionDao {
|
|||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
SELECT * FROM route_actions
|
SELECT * FROM route_actions
|
||||||
WHERE status IN ('PENDING', 'WAITING_FOR_PHOTOS', 'SYNCING', 'FAILED_RETRYABLE', 'FAILED_CONFLICT', 'FAILED_PERMANENT')
|
WHERE status IN ('PENDING', 'WAITING_FOR_PHOTOS', 'SYNCING', 'CONFIRMED', 'FAILED_RETRYABLE', 'FAILED_CONFLICT', 'FAILED_PERMANENT')
|
||||||
ORDER BY createdAtEpochMillis DESC
|
ORDER BY createdAtEpochMillis DESC
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,14 +21,18 @@ internal val routeActionVisibleStatuses = setOf(
|
|||||||
RouteActionStatus.FailedPermanent,
|
RouteActionStatus.FailedPermanent,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val routeActionProjectionStatuses = routeActionVisibleStatuses + RouteActionStatus.Confirmed
|
||||||
|
|
||||||
fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>): ProjectedDriverRoute {
|
fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>): ProjectedDriverRoute {
|
||||||
val visible = actions
|
val visible = actions
|
||||||
.filter { it.routeId == route.id && it.status in routeActionVisibleStatuses }
|
.filter { it.routeId == route.id && it.status in routeActionVisibleStatuses }
|
||||||
|
val projectable = actions
|
||||||
|
.filter { it.routeId == route.id && it.status in routeActionProjectionStatuses }
|
||||||
var projectedRoute = route
|
var projectedRoute = route
|
||||||
var loadingWeightPending = false
|
var loadingWeightPending = false
|
||||||
var unloadingWeightPending = false
|
var unloadingWeightPending = false
|
||||||
|
|
||||||
visible
|
projectable
|
||||||
.sortedWith(compareBy<RouteActionEntity> { it.createdAtEpochMillis }.thenBy { it.clientActionId })
|
.sortedWith(compareBy<RouteActionEntity> { it.createdAtEpochMillis }.thenBy { it.clientActionId })
|
||||||
.forEach { action ->
|
.forEach { action ->
|
||||||
when (action.action) {
|
when (action.action) {
|
||||||
@@ -38,7 +42,7 @@ fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>):
|
|||||||
loadingWeight = action.weight,
|
loadingWeight = action.weight,
|
||||||
trackingStatus = "active",
|
trackingStatus = "active",
|
||||||
)
|
)
|
||||||
loadingWeightPending = true
|
loadingWeightPending = action.status != RouteActionStatus.Confirmed
|
||||||
}
|
}
|
||||||
RouteActionType.Finish -> {
|
RouteActionType.Finish -> {
|
||||||
projectedRoute = projectedRoute.copy(
|
projectedRoute = projectedRoute.copy(
|
||||||
@@ -47,7 +51,7 @@ fun projectDriverRoute(route: DriverRouteDto, actions: List<RouteActionEntity>):
|
|||||||
trackingStatus = "finished",
|
trackingStatus = "finished",
|
||||||
completedAt = action.occurredAt,
|
completedAt = action.occurredAt,
|
||||||
)
|
)
|
||||||
unloadingWeightPending = true
|
unloadingWeightPending = action.status != RouteActionStatus.Confirmed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,22 @@ class DriverRouteProjectionTest {
|
|||||||
assertEquals("finished", projection.route.trackingStatus)
|
assertEquals("finished", projection.route.trackingStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun confirmedFinishStillProjectsPlannedRouteAsFinishedWithoutSyncCallout() {
|
||||||
|
val projection = projectDriverRoute(
|
||||||
|
route = route(status = "ZAPLANOWANA"),
|
||||||
|
actions = listOf(
|
||||||
|
action(RouteActionType.Finish, RouteActionStatus.Confirmed, weight = 11.8, createdAt = 2000),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals("ZAKOŃCZONA", projection.route.status)
|
||||||
|
assertEquals(11.8, projection.route.unloadingWeight)
|
||||||
|
assertEquals("finished", projection.route.trackingStatus)
|
||||||
|
assertFalse(projection.unloadingWeightPending)
|
||||||
|
assertEquals(emptyList<RouteActionEntity>(), projection.visibleActions)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun conflictKeepsLocalRouteValuesAndMarksStageAsAttention() {
|
fun conflictKeepsLocalRouteValuesAndMarksStageAsAttention() {
|
||||||
val projection = projectDriverRoute(
|
val projection = projectDriverRoute(
|
||||||
|
|||||||
Reference in New Issue
Block a user