Skip to content

Commit b5d7a70

Browse files
committed
Legg til metoder for å hente summert og detaljert feilstatus i DashboardService, samt oppdater DashboardOversiktDTO for oversiktsdata
1 parent a45b22b commit b5d7a70

1 file changed

Lines changed: 70 additions & 70 deletions

File tree

apps/dolly-backend/src/main/java/no/nav/dolly/service/DashboardService.java

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,76 @@ public Flux<DashboardDollyTeamsDTO> getDollyTeamsStatus() {
166166
.sort(Comparator.comparing(DashboardDollyTeamsDTO::getInterval).reversed());
167167
}
168168

169+
public Flux<JsonNode> getFeilstatusSummert(int year, Month month) {
170+
171+
var filter = "%4d-%02d".formatted(year, month.getValue());
172+
return buildFeilWhereFragment()
173+
.map(feilFilter -> "select b.sist_oppdatert::date bestilling_dato, bp.* " +
174+
"from bestilling b " +
175+
"join bestilling_progress bp on bp.bestilling_id = b.id " +
176+
"where to_char(b.sist_oppdatert, 'YYYY-MM') = :range " +
177+
"and (" + feilFilter + ") order by bestilling_dato")
178+
.flatMapMany(query -> entityTemplate.getDatabaseClient()
179+
.sql(query)
180+
.bind("range", filter)
181+
.map((row, metadata) -> entityTemplate.getConverter()
182+
.read(BestillingProgressDTO.class, row, metadata))
183+
.all())
184+
.groupBy(BestillingProgressDTO::getBestillingDato)
185+
.flatMap(Flux::collectList)
186+
.flatMap(this::tilFeilstatusSummert);
187+
}
188+
189+
public Flux<JsonNode> getFeilstatusDetaljert(int year, Month month, int day) {
190+
191+
var filter = "%4d-%02d-%02d".formatted(year, month.getValue(), day);
192+
return buildFeilWhereFragment()
193+
.map(feilFilter -> "select b.sist_oppdatert, bp.* " +
194+
"from bestilling b " +
195+
"join bestilling_progress bp on bp.bestilling_id = b.id " +
196+
"where to_char(b.sist_oppdatert, 'YYYY-MM-DD') = :range " +
197+
"and (" + feilFilter + ") order by b.sist_oppdatert")
198+
.flatMapMany(query -> entityTemplate.getDatabaseClient()
199+
.sql(query)
200+
.bind("range", filter)
201+
.map((row, metadata) -> entityTemplate.getConverter()
202+
.read(BestillingProgressDTO.class, row, metadata))
203+
.all())
204+
.sort(Comparator.comparing(BestillingProgressDTO::getSistOppdatert))
205+
.flatMap(this::tilFeilJson);
206+
}
207+
208+
public Flux<DashboardOversiktDTO> getPerioderOversikt() {
209+
210+
return bestillingRepository.findByAvailIntervals()
211+
.groupBy(OversiktFragment::getMaaned)
212+
.flatMap(Flux::collectList)
213+
.map(fragmenter -> {
214+
var aarManed = fragmenter.getFirst().getMaaned();
215+
var yearMonth = YearMonth.parse(aarManed);
216+
return DashboardOversiktDTO.builder()
217+
.aarManed(aarManed)
218+
.aar(yearMonth.getYear())
219+
.maaned(yearMonth.getMonth())
220+
.totaltAntallPersoner(fragmenter.stream()
221+
.map(OversiktFragment::getAntall)
222+
.mapToInt(Long::intValue)
223+
.sum())
224+
.nye(fragmenter.stream()
225+
.filter(fragment -> "NYBESTILLING".equals(fragment.getGjenopprettstatus()))
226+
.map(OversiktFragment::getAntall)
227+
.mapToInt(Long::intValue)
228+
.sum())
229+
.gjenopprettede(fragmenter.stream()
230+
.filter(fragment -> "GJENOPPRETTING".equals(fragment.getGjenopprettstatus()))
231+
.map(OversiktFragment::getAntall)
232+
.mapToInt(Long::intValue)
233+
.sum())
234+
.build();
235+
})
236+
.sort(Comparator.comparing(DashboardOversiktDTO::getAarManed).reversed());
237+
}
238+
169239
private static long sumByStatus(List<BestillingerFragment> fragments,
170240
Function<BestillingerFragment, String> statusGetter,
171241
String value) {
@@ -219,45 +289,6 @@ private static DashboardDollyTeamsDTO.Entry toDollyTeamEntry(DollyTeamFragment f
219289
return new DashboardDollyTeamsDTO.Entry(info[0], info[1], toIntExact(oppslag.get(info[2])));
220290
}
221291

222-
public Flux<JsonNode> getFeilstatusSummert(int year, Month month) {
223-
224-
var filter = "%4d-%02d".formatted(year, month.getValue());
225-
return buildFeilWhereFragment()
226-
.map(feilFilter -> "select b.sist_oppdatert::date bestilling_dato, bp.* " +
227-
"from bestilling b " +
228-
"join bestilling_progress bp on bp.bestilling_id = b.id " +
229-
"where to_char(b.sist_oppdatert, 'YYYY-MM') = :range " +
230-
"and (" + feilFilter + ") order by bestilling_dato")
231-
.flatMapMany(query -> entityTemplate.getDatabaseClient()
232-
.sql(query)
233-
.bind("range", filter)
234-
.map((row, metadata) -> entityTemplate.getConverter()
235-
.read(BestillingProgressDTO.class, row, metadata))
236-
.all())
237-
.groupBy(BestillingProgressDTO::getBestillingDato)
238-
.flatMap(Flux::collectList)
239-
.flatMap(this::tilFeilstatusSummert);
240-
}
241-
242-
public Flux<JsonNode> getFeilstatusDetaljert(int year, Month month, int day) {
243-
244-
var filter = "%4d-%02d-%02d".formatted(year, month.getValue(), day);
245-
return buildFeilWhereFragment()
246-
.map(feilFilter -> "select b.sist_oppdatert, bp.* " +
247-
"from bestilling b " +
248-
"join bestilling_progress bp on bp.bestilling_id = b.id " +
249-
"where to_char(b.sist_oppdatert, 'YYYY-MM-DD') = :range " +
250-
"and (" + feilFilter + ") order by b.sist_oppdatert")
251-
.flatMapMany(query -> entityTemplate.getDatabaseClient()
252-
.sql(query)
253-
.bind("range", filter)
254-
.map((row, metadata) -> entityTemplate.getConverter()
255-
.read(BestillingProgressDTO.class, row, metadata))
256-
.all())
257-
.sort(Comparator.comparing(BestillingProgressDTO::getSistOppdatert))
258-
.flatMap(this::tilFeilJson);
259-
}
260-
261292
private Mono<String> buildFeilWhereFragment() {
262293
return bestillingProgressRepository.findStatusColumns()
263294
.reduce(new StringJoiner(" or "), (joiner, column) ->
@@ -365,35 +396,4 @@ private static OrdreResponseDTO.PersonHendelserDTO getError(OrdreResponseDTO.Per
365396
.toList())
366397
.build();
367398
}
368-
369-
public Flux<DashboardOversiktDTO> getPerioderOversikt() {
370-
371-
return bestillingRepository.findByAvailIntervals()
372-
.groupBy(OversiktFragment::getMaaned)
373-
.flatMap(Flux::collectList)
374-
.map(fragmenter -> {
375-
var aarManed = fragmenter.getFirst().getMaaned();
376-
var yearMonth = YearMonth.parse(aarManed);
377-
return DashboardOversiktDTO.builder()
378-
.aarManed(aarManed)
379-
.aar(yearMonth.getYear())
380-
.maaned(yearMonth.getMonth())
381-
.totaltAntallPersoner(fragmenter.stream()
382-
.map(OversiktFragment::getAntall)
383-
.mapToInt(Long::intValue)
384-
.sum())
385-
.nye(fragmenter.stream()
386-
.filter(fragment -> "NYBESTILLING".equals(fragment.getGjenopprettstatus()))
387-
.map(OversiktFragment::getAntall)
388-
.mapToInt(Long::intValue)
389-
.sum())
390-
.gjenopprettede(fragmenter.stream()
391-
.filter(fragment -> "GJENOPPRETTING".equals(fragment.getGjenopprettstatus()))
392-
.map(OversiktFragment::getAntall)
393-
.mapToInt(Long::intValue)
394-
.sum())
395-
.build();
396-
})
397-
.sort(Comparator.comparing(DashboardOversiktDTO::getAarManed).reversed());
398-
}
399399
}

0 commit comments

Comments
 (0)