|
|
@@ -368,11 +368,27 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Future<List<Action>> findActionsByDriverId(int driverId) {
|
|
|
+ public Future<List<Action>> findActionsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to) {
|
|
|
+ String whereTimestampClause;
|
|
|
+ Tuple tupleParams;
|
|
|
+ if (from != null && to != null) {
|
|
|
+ whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2 AND dta.to_time < $3";
|
|
|
+ tupleParams = Tuple.of(driverId, from, to);
|
|
|
+ } else if (from != null) {
|
|
|
+ whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2";
|
|
|
+ tupleParams = Tuple.of(driverId, from);
|
|
|
+ } else if (to != null) {
|
|
|
+ whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.to_time < $2";
|
|
|
+ tupleParams = Tuple.of(driverId, to);
|
|
|
+ } else {
|
|
|
+ whereTimestampClause = "WHERE dta.driver_id = $1";
|
|
|
+ tupleParams = Tuple.of(driverId);
|
|
|
+ }
|
|
|
+
|
|
|
return client.preparedQuery("SELECT a.action_id, a.name FROM maplog.action AS a " +
|
|
|
"JOIN maplog.driver_to_action AS dta ON a.action_id = dta.action_id " +
|
|
|
- "WHERE dta.driver_id = $1 ORDER BY a.action_id")
|
|
|
- .execute(Tuple.of(driverId))
|
|
|
+ whereTimestampClause + " ORDER BY a.action_id")
|
|
|
+ .execute(tupleParams)
|
|
|
.map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
.map(row -> Action.of(
|
|
|
row.getInteger("action_id"),
|