-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Samle logikk for utsatt oppgave i service #374
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import no.nav.syfo.repository.InntektsmeldingRepository | |
import no.nav.syfo.service.BehandlendeEnhetConsumer | ||
import no.nav.syfo.service.SYKEPENGER_UTLAND | ||
import no.nav.syfo.util.Metrikk | ||
import org.slf4j.LoggerFactory | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
|
@@ -26,9 +25,43 @@ class UtsattOppgaveService( | |
private val om: ObjectMapper, | ||
private val metrikk: Metrikk | ||
) { | ||
|
||
private val logger = this.logger() | ||
|
||
fun opprettOppgaveIGosys( | ||
utsattOppgave: UtsattOppgaveEntitet, | ||
speil: Boolean, | ||
imEntitet: InntektsmeldingEntitet, | ||
): OppgaveResultat { | ||
val behandlendeEnhet = behandlendeEnhetConsumer.hentBehandlendeEnhet( | ||
utsattOppgave.fnr, | ||
utsattOppgave.inntektsmeldingId | ||
) | ||
val gjelderUtland = (SYKEPENGER_UTLAND == behandlendeEnhet) | ||
val inntektsmelding = om.readValue<Inntektsmelding>(imEntitet.data!!) | ||
val behandlingsTema = finnBehandlingsTema(inntektsmelding) | ||
logger.info("Fant enhet $behandlendeEnhet for ${utsattOppgave.arkivreferanse}") | ||
val resultat = runBlocking { | ||
oppgaveClient.opprettOppgave( | ||
journalpostId = utsattOppgave.journalpostId, | ||
tildeltEnhetsnr = null, | ||
aktoerId = utsattOppgave.aktørId, | ||
gjelderUtland = gjelderUtland, | ||
gjelderSpeil = speil, | ||
tema = behandlingsTema | ||
) | ||
} | ||
|
||
utsattOppgave | ||
.apply { | ||
enhet = behandlendeEnhet | ||
gosysOppgaveId = resultat.oppgaveId.toString() | ||
utbetalingBruker = resultat.utbetalingBruker | ||
} | ||
.lagre() | ||
|
||
return resultat | ||
} | ||
|
||
fun prosesser(oppdatering: OppgaveOppdatering) { | ||
val oppgave = utsattOppgaveDAO.finn(oppdatering.id.toString()) | ||
if (oppgave == null) { | ||
|
@@ -39,84 +72,69 @@ class UtsattOppgaveService( | |
logger.info("Fant oppgave for inntektsmelding: ${oppgave.arkivreferanse} med tilstand: ${Tilstand.Forkastet.name}") | ||
val gjelderSpeil = oppdatering.oppdateringstype == OppdateringstypeDTO.OpprettSpeilRelatert | ||
|
||
if (oppgave.tilstand == Tilstand.Utsatt && oppdatering.handling == no.nav.syfo.utsattoppgave.Handling.Utsett) { | ||
if (oppgave.timeout == null) { | ||
metrikk.tellUtsattOppgave_UtenDato() | ||
Comment on lines
-43
to
-44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sletter denne, da den aldri til oppstå. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Timeout ER jo nullable: class OppgaveOppdatering( |
||
return when { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Her bytter jeg bare |
||
oppgave.tilstand == Tilstand.Utsatt && oppdatering.handling == Handling.Utsett -> { | ||
oppdatering.timeout ?: error("Timeout på utsettelse mangler for inntektsmelding: ${oppgave.arkivreferanse}") | ||
|
||
oppgave | ||
.apply { | ||
timeout = oppdatering.timeout | ||
oppdatert = LocalDateTime.now() | ||
speil = gjelderSpeil | ||
} | ||
.lagre() | ||
|
||
metrikk.tellUtsattOppgave_Utsett() | ||
logger.info("Oppdaterte timeout på inntektsmelding: ${oppgave.arkivreferanse} til ${oppdatering.timeout}") | ||
} | ||
oppdatering.timeout ?: error("Timeout på utsettelse mangler for inntektsmelding: ${oppgave.arkivreferanse}") | ||
oppgave.timeout = oppdatering.timeout | ||
oppgave.oppdatert = LocalDateTime.now() | ||
oppgave.speil = gjelderSpeil | ||
lagre(oppgave) | ||
metrikk.tellUtsattOppgave_Utsett() | ||
logger.info("Oppdaterte timeout på inntektsmelding: ${oppgave.arkivreferanse} til ${oppdatering.timeout}") | ||
return | ||
} | ||
|
||
if (oppgave.tilstand == Tilstand.Utsatt && oppdatering.handling == no.nav.syfo.utsattoppgave.Handling.Forkast) { | ||
oppgave.oppdatert = LocalDateTime.now() | ||
lagre(oppgave.copy(tilstand = Tilstand.Forkastet, speil = gjelderSpeil)) | ||
metrikk.tellUtsattOppgave_Forkast() | ||
logger.info("Endret oppgave: ${oppgave.arkivreferanse} til tilstand: ${Tilstand.Forkastet.name}") | ||
return | ||
} | ||
oppgave.tilstand == Tilstand.Utsatt && oppdatering.handling == Handling.Forkast -> { | ||
oppgave | ||
.apply { | ||
oppdatert = LocalDateTime.now() | ||
} | ||
.copy( | ||
tilstand = Tilstand.Forkastet, | ||
speil = gjelderSpeil, | ||
) | ||
.lagre() | ||
Comment on lines
+92
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeg forstår ikke helt hvorfor |
||
|
||
if ((oppgave.tilstand == Tilstand.Utsatt || oppgave.tilstand == Tilstand.Forkastet) && oppdatering.handling == Handling.Opprett) { | ||
val inntektsmeldingEntitet = inntektsmeldingRepository.findByArkivReferanse(oppgave.arkivreferanse) | ||
val resultat = opprettOppgaveIGosys(oppgave, oppgaveClient, utsattOppgaveDAO, behandlendeEnhetConsumer, gjelderSpeil, inntektsmeldingEntitet, om) | ||
oppgave.oppdatert = LocalDateTime.now() | ||
lagre(oppgave.copy(tilstand = Tilstand.Opprettet, speil = gjelderSpeil)) | ||
metrikk.tellUtsattOppgave_Opprett() | ||
logger.info("Endret oppgave: ${oppgave.inntektsmeldingId} til tilstand: ${Tilstand.Opprettet.name} gosys oppgaveID: ${resultat.oppgaveId} duplikat? ${resultat.duplikat}") | ||
return | ||
} | ||
metrikk.tellUtsattOppgave_Forkast() | ||
logger.info("Endret oppgave: ${oppgave.arkivreferanse} til tilstand: ${Tilstand.Forkastet.name}") | ||
} | ||
|
||
metrikk.tellUtsattOppgave_Irrelevant() | ||
logger.info("Oppdatering på dokumentId: ${oppdatering.id} ikke relevant") | ||
} | ||
oppgave.tilstand in listOf(Tilstand.Utsatt, Tilstand.Forkastet) && oppdatering.handling == Handling.Opprett -> { | ||
val inntektsmeldingEntitet = inntektsmeldingRepository.findByArkivReferanse(oppgave.arkivreferanse) | ||
val resultat = opprettOppgaveIGosys(oppgave, gjelderSpeil, inntektsmeldingEntitet) | ||
|
||
oppgave | ||
.apply { | ||
oppdatert = LocalDateTime.now() | ||
} | ||
.copy( | ||
tilstand = Tilstand.Opprettet, | ||
speil = gjelderSpeil, | ||
) | ||
.lagre() | ||
|
||
fun lagre(oppgave: UtsattOppgaveEntitet) { | ||
utsattOppgaveDAO.lagre(oppgave) | ||
metrikk.tellUtsattOppgave_Opprett() | ||
logger.info("Endret oppgave: ${oppgave.inntektsmeldingId} til tilstand: ${Tilstand.Opprettet.name} gosys oppgaveID: ${resultat.oppgaveId} duplikat? ${resultat.duplikat}") | ||
} | ||
|
||
else -> { | ||
metrikk.tellUtsattOppgave_Irrelevant() | ||
logger.info("Oppdatering på dokumentId: ${oppdatering.id} ikke relevant") | ||
} | ||
} | ||
} | ||
|
||
fun opprett(utsattOppgave: UtsattOppgaveEntitet) { | ||
utsattOppgaveDAO.opprett(utsattOppgave) | ||
} | ||
} | ||
|
||
fun opprettOppgaveIGosys( | ||
utsattOppgave: UtsattOppgaveEntitet, | ||
oppgaveClient: OppgaveClient, | ||
utsattOppgaveDAO: UtsattOppgaveDAO, | ||
behandlendeEnhetConsumer: BehandlendeEnhetConsumer, | ||
speil: Boolean, | ||
imEntitet: InntektsmeldingEntitet, | ||
om: ObjectMapper | ||
): OppgaveResultat { | ||
val logger = LoggerFactory.getLogger(UtsattOppgaveService::class.java)!! | ||
val behandlendeEnhet = behandlendeEnhetConsumer.hentBehandlendeEnhet( | ||
utsattOppgave.fnr, | ||
utsattOppgave.inntektsmeldingId | ||
) | ||
val gjelderUtland = (SYKEPENGER_UTLAND == behandlendeEnhet) | ||
val inntektsmelding = om.readValue<Inntektsmelding>(imEntitet.data!!) | ||
val behandlingsTema = finnBehandlingsTema(inntektsmelding) | ||
logger.info("Fant enhet $behandlendeEnhet for ${utsattOppgave.arkivreferanse}") | ||
val resultat = runBlocking { | ||
oppgaveClient.opprettOppgave( | ||
journalpostId = utsattOppgave.journalpostId, | ||
tildeltEnhetsnr = null, | ||
aktoerId = utsattOppgave.aktørId, | ||
gjelderUtland = gjelderUtland, | ||
gjelderSpeil = speil, | ||
tema = behandlingsTema | ||
) | ||
private fun UtsattOppgaveEntitet.lagre() { | ||
utsattOppgaveDAO.lagre(this) | ||
} | ||
utsattOppgave.enhet = behandlendeEnhet | ||
utsattOppgave.gosysOppgaveId = resultat.oppgaveId.toString() | ||
utsattOppgave.utbetalingBruker = resultat.utbetalingBruker | ||
utsattOppgaveDAO.lagre(utsattOppgave) | ||
return resultat | ||
} | ||
|
||
class OppgaveOppdatering( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Denne er bare flyttet på, men noen småforbedringer som ikke endrer funksjonalitet.