diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/domain/statistikk/SakStatistikk.kt b/src/main/java/no/nav/veilarbvedtaksstotte/domain/statistikk/SakStatistikk.kt index b9f978221..5afe28f37 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/domain/statistikk/SakStatistikk.kt +++ b/src/main/java/no/nav/veilarbvedtaksstotte/domain/statistikk/SakStatistikk.kt @@ -22,9 +22,9 @@ data class SakStatistikk( val tekniskTid: Instant? = null, val sakYtelse: String? = null, val behandlingType: BehandlingType? = null, - val behandlingStatus: BehandlingStatus, + val behandlingStatus: BehandlingStatus? = null, val behandlingResultat: BehandlingResultat? = null, - val behandlingMetode: BehandlingMetode, + val behandlingMetode: BehandlingMetode? = null, val opprettetAv: String? = null, val saksbehandler: String? = null, val ansvarligBeslutter: String? = null, @@ -122,9 +122,6 @@ fun SakStatistikk.validate() { if (ansvarligEnhet == null) { throw IllegalStateException("ansvarligEnhet kan ikke være null") } - if (avsender == null) { - throw IllegalStateException("avsender kan ikke være null") - } if (versjon == null) { throw IllegalStateException("versjon kan ikke være null") } diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/repository/SakStatistikkRepository.kt b/src/main/java/no/nav/veilarbvedtaksstotte/repository/SakStatistikkRepository.kt index 65428fad2..53c5a186e 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/repository/SakStatistikkRepository.kt +++ b/src/main/java/no/nav/veilarbvedtaksstotte/repository/SakStatistikkRepository.kt @@ -76,9 +76,9 @@ class SakStatistikkRepository(val jdbcTemplate: JdbcTemplate) { TimeUtils.toTimestampOrNull(sakStatistikkRad.tekniskTid), sakStatistikkRad.sakYtelse, sakStatistikkRad.behandlingType?.name, - sakStatistikkRad.behandlingStatus.name, + sakStatistikkRad.behandlingStatus?.name, sakStatistikkRad.behandlingResultat?.name, - sakStatistikkRad.behandlingMetode.name, + sakStatistikkRad.behandlingMetode?.name, sakStatistikkRad.innsatsgruppe?.name, sakStatistikkRad.hovedmal?.name, sakStatistikkRad.opprettetAv, diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/service/BeslutterService.java b/src/main/java/no/nav/veilarbvedtaksstotte/service/BeslutterService.java index 43fc2e2c5..71c8cad3f 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/service/BeslutterService.java +++ b/src/main/java/no/nav/veilarbvedtaksstotte/service/BeslutterService.java @@ -46,6 +46,8 @@ public class BeslutterService { private final MetricsService metricsService; + private final SakStatistikkService sakStatistikkService; + public void startBeslutterProsess(long vedtakId) { Vedtak utkast = vedtaksstotteRepository.hentUtkastEllerFeil(vedtakId); authService.sjekkTilgangTilBrukerOgEnhet(AktorId.of(utkast.getAktorId())); @@ -63,6 +65,7 @@ public void startBeslutterProsess(long vedtakId) { vedtaksstotteRepository.setBeslutterProsessStatus(utkast.getId(), BeslutterProsessStatus.KLAR_TIL_BESLUTTER); vedtakStatusEndringService.beslutterProsessStartet(utkast); meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.BESLUTTER_PROSESS_STARTET, utkast.getVeilederIdent()); + sakStatistikkService.startetKvalitetssikring(utkast); } public void avbrytBeslutterProsess(long vedtakId) { @@ -80,6 +83,7 @@ public void avbrytBeslutterProsess(long vedtakId) { vedtaksstotteRepository.setBeslutter(utkast.getId(), null); vedtakStatusEndringService.beslutterProsessAvbrutt(utkast); meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.BESLUTTER_PROSESS_AVBRUTT, utkast.getVeilederIdent()); + sakStatistikkService.avbrytKvalitetssikringsprosess(utkast); }); } @@ -111,6 +115,8 @@ public void bliBeslutter(long vedtakId) { vedtakStatusEndringService.tattOverForBeslutter(utkast, innloggetVeilederIdent); meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.TATT_OVER_SOM_BESLUTTER, innloggetVeilederIdent); } + + sakStatistikkService.bliEllerTaOverSomKvalitetssikrer(utkast, innloggetVeilederIdent); } public void setGodkjentAvBeslutter(long vedtakId) { @@ -154,7 +160,6 @@ public void oppdaterBeslutterProsessStatus(long vedtakId) { } vedtaksstotteRepository.setBeslutterProsessStatus(utkast.getId(), nyStatus); - if (nyStatus == BeslutterProsessStatus.KLAR_TIL_BESLUTTER) { beslutteroversiktRepository.oppdaterStatus(utkast.getId(), BeslutteroversiktStatus.KLAR_TIL_BESLUTTER); meldingRepository.opprettSystemMelding(vedtakId, SystemMeldingType.SENDT_TIL_BESLUTTER, innloggetVeilederIdent); diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/service/BigQueryService.kt b/src/main/java/no/nav/veilarbvedtaksstotte/service/BigQueryService.kt index c934775c1..6e3fc9d99 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/service/BigQueryService.kt +++ b/src/main/java/no/nav/veilarbvedtaksstotte/service/BigQueryService.kt @@ -38,9 +38,9 @@ class BigQueryService(@Value("\${gcp.projectId}") val projectId: String, "teknisk_tid" to sakStatistikk.tekniskTid.toString(), "sak_ytelse" to sakStatistikk.sakYtelse, "behandling_type" to sakStatistikk.behandlingType?.name, - "behandling_status" to sakStatistikk.behandlingStatus.name, + "behandling_status" to sakStatistikk.behandlingStatus?.name, "behandling_resultat" to sakStatistikk.behandlingResultat?.name, - "behandling_metode" to sakStatistikk.behandlingMetode.name, + "behandling_metode" to sakStatistikk.behandlingMetode?.name, "innsatsgruppe" to sakStatistikk.innsatsgruppe?.name, "hovedmal" to sakStatistikk.hovedmal?.name, "opprettet_av" to sakStatistikk.opprettetAv, diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/service/SakStatistikkService.kt b/src/main/java/no/nav/veilarbvedtaksstotte/service/SakStatistikkService.kt index a54e4966c..e9cb056f9 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/service/SakStatistikkService.kt +++ b/src/main/java/no/nav/veilarbvedtaksstotte/service/SakStatistikkService.kt @@ -33,7 +33,8 @@ class SakStatistikkService @Autowired constructor( val statistikkRad = SakStatistikk( ferdigbehandletTid = Instant.now(), behandlingStatus = BehandlingStatus.FATTET, - behandlingMetode = BehandlingMetode.MANUELL, + behandlingMetode = if(vedtak.beslutterIdent != null) BehandlingMetode.TOTRINNS else BehandlingMetode.MANUELL, + ansvarligBeslutter = vedtak.beslutterIdent ) val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad) @@ -81,19 +82,94 @@ class SakStatistikkService @Autowired constructor( val aktorId = AktorId(vedtak.aktorId) val fnr = aktorOppslagClient.hentFnr(aktorId) - val statistikkRad = SakStatistikk( + val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk()) + val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak) + val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr) + + val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy( + innsatsgruppe = null, + hovedmal = null, + behandlingResultat = null, behandlingStatus = BehandlingStatus.AVBRUTT, behandlingMetode = BehandlingMetode.MANUELL, ) + try { + ferdigpopulertStatistikkRad.validate() + sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad) + bigQueryService.logEvent(ferdigpopulertStatistikkRad) + } catch (e: Exception) { + secureLog.error("Kunne ikke lagre slettetutkast - sakstatistikk", e) + } + } + } + + fun startetKvalitetssikring (vedtak: Vedtak) { + val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA) + if (statistikkPaa) { + val aktorId = AktorId(vedtak.aktorId) + val fnr = aktorOppslagClient.hentFnr(aktorId) + + val statistikkRad = SakStatistikk( + behandlingStatus = BehandlingStatus.SENDT_TIL_KVALITETSSIKRING, + behandlingMetode = BehandlingMetode.TOTRINNS, + ) val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad) val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak) + val ferdigpopulertStatistikkRad = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr) + + try { + ferdigpopulertStatistikkRad.validate() + sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad) + bigQueryService.logEvent(ferdigpopulertStatistikkRad) + } catch (e: Exception) { + secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e) + } + } + } + + fun bliEllerTaOverSomKvalitetssikrer(vedtak: Vedtak, innloggetVeileder: String) { + val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA) + if (statistikkPaa) { + val aktorId = AktorId(vedtak.aktorId) + val fnr = aktorOppslagClient.hentFnr(aktorId) + + val statistikkRad = SakStatistikk( + behandlingStatus = BehandlingStatus.SENDT_TIL_KVALITETSSIKRING, + behandlingMetode = BehandlingMetode.TOTRINNS, + ansvarligBeslutter = innloggetVeileder, + ) + val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad) + val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak) + val ferdigpopulertStatistikkRad = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr) + + try { + ferdigpopulertStatistikkRad.validate() + sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad) + bigQueryService.logEvent(ferdigpopulertStatistikkRad) + } catch (e: Exception) { + secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e) + } + } + } + + fun avbrytKvalitetssikringsprosess(vedtak: Vedtak) { + val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA) + if (statistikkPaa) { + val aktorId = AktorId(vedtak.aktorId) + val fnr = aktorOppslagClient.hentFnr(aktorId) + + val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk()) + val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak) val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr) val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy( - innsatsgruppe = null, + ansvarligBeslutter = null, + behandlingResultat = null, hovedmal = null, - behandlingResultat = null + innsatsgruppe = null, + behandlingStatus = BehandlingStatus.UNDER_BEHANDLING, + behandlingMetode = BehandlingMetode.MANUELL, ) try { @@ -101,7 +177,34 @@ class SakStatistikkService @Autowired constructor( sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad) bigQueryService.logEvent(ferdigpopulertStatistikkRad) } catch (e: Exception) { - secureLog.error("Kunne ikke lagre slettetutkast - sakstatistikk", e) + secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e) + } + } + } + + fun overtattUtkast(vedtak: Vedtak, innloggetVeilederIdent: String, erAlleredeBeslutter: Boolean) { + val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA) + if (statistikkPaa) { + val aktorId = AktorId(vedtak.aktorId) + val fnr = aktorOppslagClient.hentFnr(aktorId) + + val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk()) + val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak) + val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr) + + val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy( + ansvarligBeslutter = if (erAlleredeBeslutter) innloggetVeilederIdent else vedtak.beslutterIdent, + behandlingStatus = if (vedtak.beslutterProsessStatus != null) BehandlingStatus.SENDT_TIL_KVALITETSSIKRING else BehandlingStatus.UNDER_BEHANDLING, + behandlingMetode = if (vedtak.beslutterProsessStatus != null) BehandlingMetode.TOTRINNS else BehandlingMetode.MANUELL, + saksbehandler = innloggetVeilederIdent + ) + + try { + ferdigpopulertStatistikkRad.validate() + sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad) + bigQueryService.logEvent(ferdigpopulertStatistikkRad) + } catch (e: Exception) { + secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e) } } } diff --git a/src/main/java/no/nav/veilarbvedtaksstotte/service/VedtakService.java b/src/main/java/no/nav/veilarbvedtaksstotte/service/VedtakService.java index f3f832f49..f896cbc87 100644 --- a/src/main/java/no/nav/veilarbvedtaksstotte/service/VedtakService.java +++ b/src/main/java/no/nav/veilarbvedtaksstotte/service/VedtakService.java @@ -344,6 +344,7 @@ public void taOverUtkast(long vedtakId) { vedtaksstotteRepository.oppdaterUtkastVeileder(utkast.getId(), innloggetVeilederIdent); beslutteroversiktRepository.oppdaterVeileder(utkast.getId(), veileder.getNavn()); meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.TATT_OVER_SOM_VEILEDER, innloggetVeilederIdent); + sakStatistikkService.overtattUtkast(utkast, innloggetVeilederIdent, erAlleredeBeslutter); }); vedtakStatusEndringService.tattOverForVeileder(utkast, innloggetVeilederIdent); diff --git a/src/test/java/no/nav/veilarbvedtaksstotte/service/BeslutterServiceTest.java b/src/test/java/no/nav/veilarbvedtaksstotte/service/BeslutterServiceTest.java index 9a0f571f6..7f41e907d 100644 --- a/src/test/java/no/nav/veilarbvedtaksstotte/service/BeslutterServiceTest.java +++ b/src/test/java/no/nav/veilarbvedtaksstotte/service/BeslutterServiceTest.java @@ -61,13 +61,15 @@ public class BeslutterServiceTest { private final AuthService authService = mock(AuthService.class); + private final SakStatistikkService sakStatistikkService = mock(SakStatistikkService.class); + private final JdbcTemplate db = SingletonPostgresContainer.init().createJdbcTemplate(); private TransactionTemplate transactor = new TransactionTemplate(new DataSourceTransactionManager(db.getDataSource())); private BeslutterService beslutterService = new BeslutterService( authService, vedtaksstotteRepository, vedtakStatusEndringService, beslutteroversiktRepository, - meldingRepository, veilederService, veilarbpersonClient, transactor, metricsService + meldingRepository, veilederService, veilarbpersonClient, transactor, metricsService, sakStatistikkService );