Skip to content

Commit

Permalink
River som lytter på distribuert brev og lagrer i omregningskjøring (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjodn authored Nov 18, 2024
1 parent 67be3d2 commit 0014e23
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package no.nav.etterlatte.behandling.omregning

import no.nav.etterlatte.common.ConnectionAutoclosing
import no.nav.etterlatte.libs.common.feilhaandtering.checkInternFeil
import no.nav.etterlatte.libs.common.sak.DisttribuertEllerIverksatt
import no.nav.etterlatte.libs.common.sak.KjoeringDistEllerIverksattRequest
import no.nav.etterlatte.libs.common.sak.KjoeringRequest
import no.nav.etterlatte.libs.common.sak.KjoeringStatus
import no.nav.etterlatte.libs.common.sak.LagreKjoeringRequest
import no.nav.etterlatte.libs.common.sak.SakId
import no.nav.etterlatte.libs.database.setSakId
import no.nav.etterlatte.libs.database.single
import no.nav.etterlatte.libs.database.toList

class OmregningDao(
Expand Down Expand Up @@ -110,4 +113,63 @@ class OmregningDao(
}
}
}

fun lagreDistribuertBrevEllerIverksattBehandlinga(
request: KjoeringDistEllerIverksattRequest,
status: KjoeringStatus,
) {
connection.hentConnection { connection ->
with(connection) {
val statement =
prepareStatement(
"""
INSERT INTO omregningskjoering (
kjoering, sak_id, status
${
when (request.distEllerIverksatt) {
DisttribuertEllerIverksatt.IVERKSATT -> "iverkksatt_behandling"
DisttribuertEllerIverksatt.DISTRIBUERT -> "distribuert_brev"
}
}
)
VALUES (?, ?, ?, ?)
""".trimIndent(),
)
statement.setString(1, request.kjoering)
statement.setSakId(2, request.sakId)
statement.setString(3, status.name)
statement.setBoolean(4, true)
statement.executeUpdate().also {
checkInternFeil(it > 0) {
"Kunne ikke lagreKjoering for id sakid ${request.sakId}"
}
}
}
}
}

fun hentNyligsteLinjeForKjoering(
kjoering: String,
sakId: SakId,
): Pair<Long, KjoeringStatus> =
connection.hentConnection { connection ->
with(connection) {
val statement =
prepareStatement(
"""
SELECT kjoering, status
FROM omregningskjoering
WHERE kjoering = ? AND sak_id = ?
""".trimIndent(),
)
statement.setString(1, kjoering)
statement.setLong(2, sakId.sakId)
statement.executeQuery().single {
Pair(
getLong("sak_id"),
KjoeringStatus.valueOf(getString("status")),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ktor.server.routing.post
import io.ktor.server.routing.put
import io.ktor.server.routing.route
import no.nav.etterlatte.inTransaction
import no.nav.etterlatte.libs.common.sak.KjoeringDistEllerIverksattRequest
import no.nav.etterlatte.libs.common.sak.KjoeringRequest
import no.nav.etterlatte.libs.common.sak.LagreKjoeringRequest
import no.nav.etterlatte.libs.ktor.token.brukerTokenInfo
Expand All @@ -26,6 +27,16 @@ fun Route.omregningRoutes(omregningService: OmregningService) {
}
call.respond(HttpStatusCode.OK)
}
put("dist-eller-iverksatt") {
val request = call.receive<KjoeringDistEllerIverksattRequest>()
logger.info(
"Motter oppdatering på distribuert brev eller iverksatt behandling (${request.distEllerIverksatt.name}) i sak ${request.sakId}",
)
inTransaction {
omregningService.lagreDistribuertBrevEllerIverksattBehandlinga(request)
}
call.respond(HttpStatusCode.OK)
}

post("kjoeringFullfoert") {
val request = call.receive<LagreKjoeringRequest>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.etterlatte.behandling.omregning

import no.nav.etterlatte.behandling.BehandlingService
import no.nav.etterlatte.libs.common.sak.KjoeringDistEllerIverksattRequest
import no.nav.etterlatte.libs.common.sak.KjoeringRequest
import no.nav.etterlatte.libs.common.sak.KjoeringStatus
import no.nav.etterlatte.libs.common.sak.LagreKjoeringRequest
Expand Down Expand Up @@ -40,4 +41,9 @@ class OmregningService(
}
omregningDao.lagreKjoering(request)
}

fun lagreDistribuertBrevEllerIverksattBehandlinga(request: KjoeringDistEllerIverksattRequest) {
val (_, sisteStatus) = omregningDao.hentNyligsteLinjeForKjoering(request.kjoering, request.sakId)
omregningDao.lagreDistribuertBrevEllerIverksattBehandlinga(request, sisteStatus)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE omregningskjoering
ADD COLUMN iverkksatt_behandling BOOL;

ALTER TABLE omregningskjoering
ADD COLUMN distribuert_brev BOOL;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.etterlatte

import no.nav.etterlatte.inntektsjustering.InntektsjusteringJobbRiver
import no.nav.etterlatte.inntektsjustering.OppdaterInntektsjusteringBrevDistribuert
import no.nav.etterlatte.migrering.AvbrytBehandlingHvisMigreringFeilaRiver
import no.nav.etterlatte.regulering.FinnSakerTilReguleringRiver
import no.nav.etterlatte.regulering.OmregningBrevDistribusjonRiver
import no.nav.etterlatte.regulering.OmregningFeiletRiver
import no.nav.etterlatte.regulering.OmregningsHendelserBehandlingRiver
import no.nav.etterlatte.regulering.ReguleringsforespoerselRiver
Expand All @@ -13,7 +13,12 @@ import no.nav.helse.rapids_rivers.RapidsConnection
import rapidsandrivers.initRogR

fun main() {
initRogR("oppdater-behandling") { rapidsConnection, rapidEnv -> settOppRivers(rapidsConnection, AppBuilder(rapidEnv)) }
initRogR("oppdater-behandling") { rapidsConnection, rapidEnv ->
settOppRivers(
rapidsConnection,
AppBuilder(rapidEnv),
)
}
}

private fun settOppRivers(
Expand All @@ -35,5 +40,5 @@ private fun settOppRivers(
TidshendelseRiver(rapidsConnection, tidshendelseService)
OppdaterDoedshendelseBrevDistribuert(rapidsConnection, behandlingservice)
InntektsjusteringJobbRiver(rapidsConnection, behandlingservice, featureToggleService)
OppdaterInntektsjusteringBrevDistribuert(rapidsConnection, behandlingservice)
OmregningBrevDistribusjonRiver(rapidsConnection, behandlingservice)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import no.nav.etterlatte.libs.common.pdlhendelse.UtflyttingsHendelse
import no.nav.etterlatte.libs.common.pdlhendelse.VergeMaalEllerFremtidsfullmakt
import no.nav.etterlatte.libs.common.revurdering.AutomatiskRevurderingRequest
import no.nav.etterlatte.libs.common.revurdering.AutomatiskRevurderingResponse
import no.nav.etterlatte.libs.common.sak.DisttribuertEllerIverksatt
import no.nav.etterlatte.libs.common.sak.HentSakerRequest
import no.nav.etterlatte.libs.common.sak.KjoeringDistEllerIverksattRequest
import no.nav.etterlatte.libs.common.sak.KjoeringRequest
import no.nav.etterlatte.libs.common.sak.KjoeringStatus
import no.nav.etterlatte.libs.common.sak.LagreKjoeringRequest
Expand Down Expand Up @@ -134,6 +136,12 @@ interface BehandlingService {
feilendeSteg: String? = null,
)

fun lagreKjoeringBrevDistribuertEllerIverksatt(
sakId: SakId,
kjoering: String,
distEllerIverksatt: DisttribuertEllerIverksatt,
)

fun lagreFullfoertKjoering(request: LagreKjoeringRequest)
}

Expand Down Expand Up @@ -421,6 +429,26 @@ class BehandlingServiceImpl(
}
}

override fun lagreKjoeringBrevDistribuertEllerIverksatt(
sakId: SakId,
kjoering: String,
distEllerIverksatt: DisttribuertEllerIverksatt,
) {
runBlocking {
behandlingKlient.put("$url/omregning/dist-eller-iverksatt") {
contentType(ContentType.Application.Json)
setBody(
KjoeringDistEllerIverksattRequest(
kjoering = kjoering,
sakId = sakId,
distEllerIverksatt = distEllerIverksatt,
),
)
}
logger.debug("$kjoering: har fullført distribuering av brev for sak $sakId")
}
}

override fun lagreFullfoertKjoering(request: LagreKjoeringRequest) {
runBlocking {
behandlingKlient.post("$url/omregning/kjoeringFullfoert") {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package no.nav.etterlatte.regulering

import no.nav.etterlatte.BehandlingService
import no.nav.etterlatte.brev.BrevHendelseType
import no.nav.etterlatte.brev.Brevkoder
import no.nav.etterlatte.libs.common.feilhaandtering.InternfeilException
import no.nav.etterlatte.libs.common.inntektsjustering.AarligInntektsjusteringRequest
import no.nav.etterlatte.libs.common.sak.DisttribuertEllerIverksatt
import no.nav.etterlatte.rapidsandrivers.BREV_KODE
import no.nav.etterlatte.rapidsandrivers.Kontekst
import no.nav.etterlatte.rapidsandrivers.ListenerMedLogging
import no.nav.etterlatte.rapidsandrivers.SAK_ID_KEY
import no.nav.etterlatte.rapidsandrivers.brevId
import no.nav.etterlatte.rapidsandrivers.brevKode
import no.nav.etterlatte.rapidsandrivers.sakId
import no.nav.helse.rapids_rivers.JsonMessage
import no.nav.helse.rapids_rivers.MessageContext
import no.nav.helse.rapids_rivers.RapidsConnection
import org.slf4j.LoggerFactory

internal class OmregningBrevDistribusjonRiver(
rapidsConnection: RapidsConnection,
private val behandlingService: BehandlingService,
) : ListenerMedLogging() {
private val logger = LoggerFactory.getLogger(this::class.java)

init {
initialiserRiver(rapidsConnection, BrevHendelseType.DISTRIBUERT) {
validate { it.requireKey(SAK_ID_KEY) }
validate { it.requireKey(BREV_KODE) }
validate { it.demandValue(BREV_KODE, Brevkoder.OMS_INNTEKTSJUSTERING_VEDTAK.name) } // TODO kan bli flere
}
}

override fun kontekst() = Kontekst.OMREGNING

override fun haandterPakke(
packet: JsonMessage,
context: MessageContext,
) {
logger.info("Setter status på brev til distribuert på omregning til sak=${packet.sakId}, brevid=${packet.brevId}")
try {
val brevkode = packet.brevKode
when (brevkode) {
Brevkoder.OMS_INNTEKTSJUSTERING_VEDTAK.name -> {
val kjoering = AarligInntektsjusteringRequest.utledKjoering()
behandlingService.lagreKjoeringBrevDistribuertEllerIverksatt(
packet.sakId,
kjoering,
DisttribuertEllerIverksatt.DISTRIBUERT,
)
}

else -> {}
}
} catch (e: Exception) {
logger.error(
"Kunne ikke oppdatere omregning sin status på brev distribusjon for sak ${packet.sakId} brevid: ${packet.brevId}",
e,
)
throw InternfeilException(
"Fikk ikke oppdatert kjøring med status på brev distribusjon for ${packet.sakId}",
e,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ data class KjoeringRequest(
val feilendeSteg: String? = null,
)

data class KjoeringDistEllerIverksattRequest(
val kjoering: String,
val sakId: SakId,
val distEllerIverksatt: DisttribuertEllerIverksatt,
)

data class LagreKjoeringRequest(
val kjoering: String,
val status: KjoeringStatus,
Expand All @@ -36,3 +42,8 @@ enum class KjoeringStatus {
TIL_MANUELL,
TIL_MANUELL_UTEN_OPPGAVE,
}

enum class DisttribuertEllerIverksatt {
IVERKSATT,
DISTRIBUERT,
}

0 comments on commit 0014e23

Please sign in to comment.