|
|
@@ -326,6 +326,36 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Future<List<Unit>> findUnitsByDriverId(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 u.unit_id, u.name, u.imei, u.description FROM maplog.driver_to_action AS dta " +
|
|
|
+ "JOIN maplog.unit AS u ON u.unit_id = dta.unit_id " + whereTimestampClause)
|
|
|
+ .execute(tupleParams)
|
|
|
+ .map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
+ .map(row -> Unit.of(
|
|
|
+ row.getLong("unit_id"),
|
|
|
+ row.getString("name"),
|
|
|
+ row.getString("imei"),
|
|
|
+ row.getString("description")
|
|
|
+ )).collect(toList()))
|
|
|
+ .onFailure(logger::catching);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Future<List<CampaignUnit>> findUnitsByCampaignId(long campaignId) {
|
|
|
return client.preparedQuery("SELECT u.unit_id, utc.camp_id, u.name, u.imei, u.unit_type_id, u.description, utc.from_time, utc.to_time " +
|
|
|
"FROM maplog.unit_to_campaign AS utc " +
|