|
| 1 | +package no.nav.dagpenger.inntekt |
| 2 | + |
| 3 | +import kotlinx.coroutines.delay |
| 4 | +import kotliquery.queryOf |
| 5 | +import kotliquery.sessionOf |
| 6 | +import kotliquery.using |
| 7 | +import mu.KotlinLogging |
| 8 | +import no.nav.dagpenger.inntekt.inntektskomponenten.v1.ArbeidsInntektMaaned |
| 9 | +import no.nav.dagpenger.inntekt.inntektskomponenten.v1.InntektkomponentRequest |
| 10 | +import no.nav.dagpenger.inntekt.inntektskomponenten.v1.InntektkomponentResponse |
| 11 | +import no.nav.dagpenger.inntekt.inntektskomponenten.v1.InntektskomponentClient |
| 12 | +import no.nav.dagpenger.inntekt.opptjeningsperiode.Opptjeningsperiode |
| 13 | +import java.time.LocalDate |
| 14 | +import java.util.concurrent.TimeUnit |
| 15 | +import javax.sql.DataSource |
| 16 | + |
| 17 | +internal class Uttrekksjobb(private val dataSource: DataSource, private val client: InntektskomponentClient) { |
| 18 | + |
| 19 | + private val inntekter = setOf( |
| 20 | + "01DP8G798K6RHW42XCDHQRB706", |
| 21 | + "01DP8DWGXVH2HKFW0BJM4WN9TF", |
| 22 | + "01DPARVSWZPWB1M711VQD07PNQ", |
| 23 | + "01DXJNSNDCV1Y7E273DNKK8NAY", |
| 24 | + "01ERPHTNPSPJAKZ3Y8ZMNN0J6D" |
| 25 | + ) |
| 26 | + |
| 27 | + companion object { |
| 28 | + private val logger = KotlinLogging.logger { } |
| 29 | + } |
| 30 | + |
| 31 | + internal suspend fun hentInntekterOgSjekk() { |
| 32 | + delay(TimeUnit.SECONDS.toMillis(10)) |
| 33 | + val stringBuilder = StringBuilder().append(System.lineSeparator()).append("***********************************************") |
| 34 | + inntekter.forEach { inntektId -> |
| 35 | + val result = using(sessionOf(dataSource)) { session -> |
| 36 | + session.run( |
| 37 | + queryOf( |
| 38 | + "SELECT kontekstid, beregningsdato, aktørId FROM inntekt_v1_person_mapping WHERE inntektid = :id ", |
| 39 | + mapOf( |
| 40 | + "id" to inntektId |
| 41 | + ) |
| 42 | + ).map { |
| 43 | + Result( |
| 44 | + inntektsId = inntektId, |
| 45 | + beregningsdato = it.localDate("beregningsdato"), |
| 46 | + vedtakId = it.int("kontekstid"), |
| 47 | + aktørId = it.string("aktørId"), |
| 48 | + ) |
| 49 | + }.asSingle |
| 50 | + ) ?: throw IllegalStateException("Kunne ikke hendte id") |
| 51 | + } |
| 52 | + val inntekt: InntektkomponentResponse = client.getInntekt( |
| 53 | + InntektkomponentRequest( |
| 54 | + aktørId = result.aktørId, |
| 55 | + månedFom = result.opptjeningsperiode.sisteAvsluttendeKalenderMåned, |
| 56 | + månedTom = result.opptjeningsperiode.førsteMåned |
| 57 | + ) |
| 58 | + ) |
| 59 | + val sisteMnd: ArbeidsInntektMaaned? = |
| 60 | + inntekt.arbeidsInntektMaaned?.maxByOrNull { it.aarMaaned } |
| 61 | + |
| 62 | + stringBuilder.append(System.lineSeparator()).append("Inntekt").append("\t") |
| 63 | + |
| 64 | + if (sisteMnd == null) { |
| 65 | + |
| 66 | + stringBuilder.append("Tom arbeids inntekt maaned $inntektId") |
| 67 | + } else if (sisteMnd.arbeidsInntektInformasjon == null) { |
| 68 | + stringBuilder.append("Tom arbeidsInntektInformasjon $inntektId") |
| 69 | + } else if (sisteMnd.arbeidsInntektInformasjon.inntektListe?.isEmpty() == true) { |
| 70 | + stringBuilder.append("Tom inntektList $inntektId") |
| 71 | + } else if (sisteMnd.arbeidsInntektInformasjon.inntektListe?.isEmpty() == false) { |
| 72 | + stringBuilder.append("Ikke tom inntektList $inntektId") |
| 73 | + } |
| 74 | + } |
| 75 | + stringBuilder.append(System.lineSeparator()).append("***********************************************") |
| 76 | + logger.info { |
| 77 | + stringBuilder.toString() |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + private data class Result( |
| 82 | + val inntektsId: String, |
| 83 | + val beregningsdato: LocalDate, |
| 84 | + val vedtakId: Int, |
| 85 | + val aktørId: String |
| 86 | + ) { |
| 87 | + val opptjeningsperiode = Opptjeningsperiode(beregningsdato) |
| 88 | + } |
| 89 | +} |
0 commit comments