Skip to content

Commit 9795d44

Browse files
committed
Uttrekksjobb - hent og sjekk om inntekt er oppdatert
navikt/dagpenger#1012
1 parent 2c371f7 commit 9795d44

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/Application.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,7 @@ fun main() {
129129
}
130130

131131
Uttrekksjobb(dataSource, inntektskomponentHttpClient).also {
132-
133-
try {
134-
LOGGER.info { "Starter Uttrekksjobb " }
135-
it.hentInntekterOgSjekk()
136-
LOGGER.info { "Uttrekksjobb ferdig" }
137-
} catch (e: Exception) {
138-
LOGGER.error(e) { "Kunne ikke gjøre Uttrekksjobb" }
139-
}
140-
132+
it.hentInntekterOgSjekk()
141133
}
142134
}
143135
}

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/Uttrekksjobb.kt

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,58 @@ internal class Uttrekksjobb(private val dataSource: DataSource, private val clie
2929
}
3030

3131
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
32+
try {
33+
delay(TimeUnit.SECONDS.toMillis(10))
34+
logger.info { "Starter Uttrekksjobb " }
35+
val stringBuilder = StringBuilder().append(System.lineSeparator()).append("***********************************************")
36+
inntekter.forEach { inntektId ->
37+
val result = using(sessionOf(dataSource)) { session ->
38+
session.run(
39+
queryOf(
40+
"SELECT kontekstid, beregningsdato, aktørId FROM inntekt_v1_person_mapping WHERE inntektid = :id ",
41+
mapOf(
42+
"id" to inntektId
43+
)
44+
).map {
45+
Result(
46+
inntektsId = inntektId,
47+
beregningsdato = it.localDate("beregningsdato"),
48+
vedtakId = it.int("kontekstid"),
49+
aktørId = it.string("aktørId"),
50+
)
51+
}.asSingle
52+
) ?: throw IllegalStateException("Kunne ikke hendte id")
53+
}
54+
val inntekt: InntektkomponentResponse = client.getInntekt(
55+
InntektkomponentRequest(
56+
aktørId = result.aktørId,
57+
månedFom = result.opptjeningsperiode.førsteMåned,
58+
månedTom = result.opptjeningsperiode.sisteAvsluttendeKalenderMåned
59+
)
5760
)
58-
)
59-
val sisteMnd: ArbeidsInntektMaaned? =
60-
inntekt.arbeidsInntektMaaned?.maxByOrNull { it.aarMaaned }
61+
val sisteMnd: ArbeidsInntektMaaned? =
62+
inntekt.arbeidsInntektMaaned?.maxByOrNull { it.aarMaaned }
6163

62-
stringBuilder.append(System.lineSeparator()).append("Inntekt").append("\t")
64+
stringBuilder.append(System.lineSeparator()).append("Inntekt").append("\t")
6365

64-
if (sisteMnd == null) {
66+
if (sisteMnd == null) {
6567

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")
68+
stringBuilder.append("Tom arbeids inntekt maaned $inntektId")
69+
} else if (sisteMnd.arbeidsInntektInformasjon == null) {
70+
stringBuilder.append("Tom arbeidsInntektInformasjon $inntektId")
71+
} else if (sisteMnd.arbeidsInntektInformasjon.inntektListe?.isEmpty() == true) {
72+
stringBuilder.append("Tom inntektList $inntektId")
73+
} else if (sisteMnd.arbeidsInntektInformasjon.inntektListe?.isEmpty() == false) {
74+
stringBuilder.append("Ikke tom inntektList $inntektId")
75+
}
7376
}
74-
}
75-
stringBuilder.append(System.lineSeparator()).append("***********************************************")
76-
logger.info {
77-
stringBuilder.toString()
77+
stringBuilder.append(System.lineSeparator()).append("***********************************************")
78+
logger.info {
79+
stringBuilder.toString()
80+
}
81+
logger.info { "Uttrekksjobb ferdig" }
82+
} catch (e: Exception) {
83+
logger.error(e) { "Uttrekksjobb feilet" }
7884
}
7985
}
8086

0 commit comments

Comments
 (0)