-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nytt endepunkt for å hente antall åpne oppgaver per avklaringsbehov.
- Loading branch information
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
api-kontrakt/src/main/kotlin/no/nav/aap/oppgave/produksjonsstyring/AntallOppgaverDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package no.nav.aap.oppgave.produksjonsstyring | ||
|
||
import no.nav.aap.oppgave.verdityper.Behandlingstype | ||
|
||
data class AntallOppgaverDto(val behandlingstype: Behandlingstype?) |
22 changes: 22 additions & 0 deletions
22
app/src/main/kotlin/no/nav/aap/oppgave/produksjonsstyring/ProduksjonsstyringAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package no.nav.aap.oppgave.produksjonsstyring | ||
|
||
import com.papsign.ktor.openapigen.route.path.normal.NormalOpenAPIRoute | ||
import com.papsign.ktor.openapigen.route.path.normal.post | ||
import com.papsign.ktor.openapigen.route.response.respond | ||
import com.papsign.ktor.openapigen.route.route | ||
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry | ||
import no.nav.aap.komponenter.dbconnect.transaction | ||
import no.nav.aap.oppgave.metrikker.httpCallCounter | ||
import javax.sql.DataSource | ||
|
||
fun NormalOpenAPIRoute.hentAntallOppgaver(dataSource: DataSource, prometheus: PrometheusMeterRegistry) = | ||
|
||
route("/produksjonsstyring/antall-oppgaver").post<Unit, Map<String, Int>, AntallOppgaverDto> { _, req -> | ||
prometheus.httpCallCounter("/produksjonsstyring/antall-oppgaver").increment() | ||
val åpneOppgaverForBehandlingstype = dataSource.transaction(readOnly = true) { connection -> | ||
ProduksjonsstyringRepository(connection) | ||
.hentAntallÅpneOppgaver(req.behandlingstype) | ||
.map {it.key.kode to it.value}.toMap() | ||
} | ||
respond(åpneOppgaverForBehandlingstype) | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/kotlin/no/nav/aap/oppgave/produksjonsstyring/ProduksjonsstyringRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package no.nav.aap.oppgave.produksjonsstyring | ||
|
||
import no.nav.aap.komponenter.dbconnect.DBConnection | ||
import no.nav.aap.oppgave.AvklaringsbehovKode | ||
import no.nav.aap.oppgave.verdityper.Behandlingstype | ||
|
||
|
||
data class AvklaringbehovOgAntall( | ||
val avklaringsbehovtype: AvklaringsbehovKode, | ||
val antall: Int | ||
) | ||
|
||
class ProduksjonsstyringRepository(private val connection: DBConnection) { | ||
|
||
fun hentAntallÅpneOppgaver(behandlingstype: Behandlingstype? = null): Map<AvklaringsbehovKode, Int> { | ||
val behandlingstypeClause = if (behandlingstype != null) "AND BEHANDLINGSTYPE = ?" else "" | ||
|
||
val sql = """ | ||
SELECT | ||
AVKLARINGSBEHOV_TYPE, COUNT(*) ANTALL | ||
FROM | ||
OPPGAVE | ||
WHERE | ||
STATUS != 'AVSLUTTET' | ||
$behandlingstypeClause | ||
GROUP BY | ||
AVKLARINGSBEHOV_TYPE | ||
""".trimIndent() | ||
|
||
val antallList = connection.queryList<AvklaringbehovOgAntall>(sql) { | ||
setParams { | ||
if (behandlingstype != null) { | ||
setString(1, behandlingstype.name) | ||
} | ||
} | ||
setRowMapper { row -> | ||
AvklaringbehovOgAntall(AvklaringsbehovKode(row.getString("AVKLARINGSBEHOV_TYPE")), row.getInt("ANTALL")) | ||
} | ||
} | ||
return antallList.map {it.avklaringsbehovtype to it.antall}.toMap() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters