|
|
@@ -272,51 +272,77 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
.onFailure(logger::catching);
|
|
|
}
|
|
|
|
|
|
- private static final Function<Row, CampaignUnit> ROW_TO_CAMPAIGN_UNIT = (row) -> CampaignUnit.of(
|
|
|
- row.getLong("unit_id"),
|
|
|
- row.getString("name"),
|
|
|
- row.getString("description"),
|
|
|
- row.getOffsetDateTime("from_time"),
|
|
|
- row.getOffsetDateTime("to_time")
|
|
|
- );
|
|
|
-
|
|
|
@Override
|
|
|
public Future<List<CampaignUnit>> findUnitsByCampaignId(long campaignId) {
|
|
|
- return client.preparedQuery("SELECT u.unit_id, u.name, u.description, utc.from_time, utc.to_time " +
|
|
|
+ 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 " +
|
|
|
"JOIN maplog.campaign c on c.campaign_id = utc.camp_id " +
|
|
|
"JOIN maplog.unit u on u.unit_id = utc.unit_id " +
|
|
|
"WHERE utc.camp_id = $1")
|
|
|
.execute(Tuple.of(campaignId))
|
|
|
.map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
- .map(ROW_TO_CAMPAIGN_UNIT)
|
|
|
+ .map((row) -> CampaignUnit.of(
|
|
|
+ row.getLong("unit_id"),
|
|
|
+ row.getLong("camp_id"),
|
|
|
+ row.getString("name"),
|
|
|
+ row.getString("description"),
|
|
|
+ row.getOffsetDateTime("from_time"),
|
|
|
+ row.getOffsetDateTime("to_time")
|
|
|
+ ))
|
|
|
.collect(Collectors.toList()));
|
|
|
}
|
|
|
|
|
|
+ private static final Function<Row, CampaignUnit> ROW_TO_CAMPAIGN_UNIT = (row) -> CampaignUnit.of(
|
|
|
+ row.getLong("unit_id"),
|
|
|
+ row.getLong("camp_id"),
|
|
|
+ row.getString("name"),
|
|
|
+ row.getString("unit_type_id"),
|
|
|
+ row.getString("imei"),
|
|
|
+ row.getString("description"),
|
|
|
+ row.getOffsetDateTime("from_time"),
|
|
|
+ row.getOffsetDateTime("to_time")
|
|
|
+ );
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Future<CampaignUnit> findUnitByIdAndCampaignId(long campaignId, long unitId) {
|
|
|
+ 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 AS u " +
|
|
|
+ "JOIN maplog.unit_to_campaign utc on u.unit_id = utc.unit_id " +
|
|
|
+ "WHERE utc.camp_id = $1 AND utc.unit_id = $2")
|
|
|
+ .execute(Tuple.of(campaignId, unitId))
|
|
|
+ .map(RowSet::iterator)
|
|
|
+ .map(iterator -> iterator.hasNext() ? ROW_TO_CAMPAIGN_UNIT.apply(iterator.next()) : null);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Future<Map<Long, Sensor>> findSensorsByUnitIdGroupById(long unitId) {
|
|
|
return findSensorsByUnitId(unitId).map(sensors -> sensors.stream()
|
|
|
.collect(Collectors.toMap(Sensor::getSensorId, Function.identity())));
|
|
|
}
|
|
|
|
|
|
- private static final Function<Row, Campaign> ROW_TO_CAMPAIGN = (row) -> Campaign.of(
|
|
|
- row.getLong("campaign_id"),
|
|
|
- row.getString("description"),
|
|
|
- row.getOffsetDateTime("from_time"),
|
|
|
- row.getOffsetDateTime("to_time")
|
|
|
- );
|
|
|
-
|
|
|
@Override
|
|
|
public Future<List<Campaign>> allCampaigns() {
|
|
|
return client.query("SELECT campaign_id, description, from_time, to_time FROM maplog.campaign ORDER BY campaign_id")
|
|
|
.execute()
|
|
|
.map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
- .map(ROW_TO_CAMPAIGN)
|
|
|
+ .map((row) -> Campaign.of(
|
|
|
+ row.getLong("campaign_id"),
|
|
|
+ row.getString("description"),
|
|
|
+ row.getOffsetDateTime("from_time"),
|
|
|
+ row.getOffsetDateTime("to_time")
|
|
|
+ ))
|
|
|
.collect(Collectors.toList())
|
|
|
)
|
|
|
.onFailure(logger::catching);
|
|
|
}
|
|
|
|
|
|
+ private static final Function<Row, Campaign> ROW_TO_CAMPAIGN = (row) -> Campaign.of(
|
|
|
+ row.getLong("campaign_id"),
|
|
|
+ row.getString("description"),
|
|
|
+ row.getOffsetDateTime("from_time"),
|
|
|
+ row.getOffsetDateTime("to_time")
|
|
|
+ );
|
|
|
+
|
|
|
@Override
|
|
|
public Future<Campaign> findCampaignById(long campaignId) {
|
|
|
return client.preparedQuery("SELECT campaign_id, description, from_time, to_time FROM maplog.campaign WHERE campaign_id = $1")
|