|
|
@@ -165,11 +165,29 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
"WHERE UTS.unit_id = $1")
|
|
|
.execute(Tuple.of(unitId))
|
|
|
.map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
- .map(ROW_TO_SENSOR)
|
|
|
- .collect(Collectors.toList())
|
|
|
+ .map(ROW_TO_SENSOR).collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ private static final Function<Row, Campaign> ROW_TO_BASIC_CAMPAIGN = (row) -> Campaign.of(
|
|
|
+ row.getLong("campaign_id"),
|
|
|
+ row.getString("description"),
|
|
|
+ row.getOffsetDateTime("from_time"),
|
|
|
+ row.getOffsetDateTime("to_time")
|
|
|
+ );
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Future<List<Campaign>> findCampaignsByUnitId(long unitId, ZoneId zone) {
|
|
|
+ return client.preparedQuery("SELECT c.campaign_id, c.description, utc.from_time, utc.to_time " +
|
|
|
+ "FROM maplog.unit_to_campaign AS utc " +
|
|
|
+ "JOIN maplog.campaign AS c on c.campaign_id = utc.camp_id " +
|
|
|
+ "WHERE utc.unit_id = $1")
|
|
|
+ .execute(Tuple.of(unitId))
|
|
|
+ .map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
+ .map(ROW_TO_BASIC_CAMPAIGN).collect(Collectors.toList()))
|
|
|
+ .onFailure(logger::catching);
|
|
|
+ }
|
|
|
+
|
|
|
private static final Function<Row, CampaignUnit> ROW_TO_CAMPAIGN_UNIT = (row) -> CampaignUnit.of(
|
|
|
row.getLong("unit_id"),
|
|
|
row.getString("description"),
|