Skip to content
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

Ei tehdä tilauksia Jamixiin suljetuista yksiköistä/ryhmistä #5961

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,33 @@ class JamixIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {

planJamixOrderJobs(db, asyncJobRunner, TestJamixClient(customerNumberToIdMapping), now)

val jobs =
db.read { tx ->
tx.createQuery {
sql("SELECT payload FROM async_job WHERE type = 'SendJamixOrder'")
}
.map { jsonColumn<AsyncJob.SendJamixOrder>("payload") }
.toList()
}
assertEquals(emptyList(), getJobs())
}

assertEquals(emptyList(), jobs)
@Test
fun `meal order jobs for closed units are not planned`() {
// Tuesday
val now = HelsinkiDateTime.of(LocalDate.of(2024, 4, 2), LocalTime.of(2, 25))
val area = DevCareArea()
val daycare =
DevDaycare(
areaId = area.id,
mealtimeBreakfast = TimeRange(LocalTime.of(8, 0), LocalTime.of(8, 20)),
mealtimeLunch = TimeRange(LocalTime.of(11, 15), LocalTime.of(11, 45)),
mealtimeSnack = TimeRange(LocalTime.of(13, 30), LocalTime.of(13, 50)),
closingDate = now.toLocalDate().minusDays(1),
)
val group1 = DevDaycareGroup(daycareId = daycare.id, jamixCustomerNumber = 88)

db.transaction { tx ->
tx.insert(area)
tx.insert(daycare)
tx.insert(group1)
}

planJamixOrderJobs(db, asyncJobRunner, TestJamixClient(customerNumberToIdMapping), now)

assertEquals(emptyList(), getJobs())
}

@Test
Expand Down Expand Up @@ -93,14 +110,7 @@ class JamixIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {

planJamixOrderJobs(db, asyncJobRunner, TestJamixClient(customerNumberToIdMapping), now)

val jobs =
db.read { tx ->
tx.createQuery {
sql("SELECT payload FROM async_job WHERE type = 'SendJamixOrder'")
}
.map { jsonColumn<AsyncJob.SendJamixOrder>("payload") }
.toList()
}
val jobs = getJobs()

val mondayNextWeek = LocalDate.of(2024, 4, 8)
val sundayNextWeek = LocalDate.of(2024, 4, 14)
Expand Down Expand Up @@ -159,14 +169,7 @@ class JamixIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
date = date,
)

val jobs =
db.read { tx ->
tx.createQuery {
sql("SELECT payload FROM async_job WHERE type = 'SendJamixOrder'")
}
.map { jsonColumn<AsyncJob.SendJamixOrder>("payload") }
.toList()
}
val jobs = getJobs()

assertEquals(
listOf(
Expand Down Expand Up @@ -531,6 +534,13 @@ Seuraavien lasten erityisruokavaliot on poistettu johtuen erityisruokavalioiden
}
}

private fun getJobs() =
db.read { tx ->
tx.createQuery { sql("SELECT payload FROM async_job WHERE type = 'SendJamixOrder'") }
.map { jsonColumn<AsyncJob.SendJamixOrder>("payload") }
.toList()
}

private fun sendOrders(
client: JamixClient,
customerNumber: Int,
Expand Down
12 changes: 10 additions & 2 deletions service/src/main/kotlin/fi/espoo/evaka/jamix/JamixQueries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fi.espoo.evaka.placement.PlacementType
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.TimeRange
import java.time.LocalDate
import org.jdbi.v3.json.Json
Expand All @@ -24,10 +25,17 @@ data class JamixChildData(
val absences: Set<AbsenceCategory>,
)

fun Database.Read.getJamixCustomerNumbers(): Set<Int> =
fun Database.Read.getJamixCustomerNumbers(range: FiniteDateRange): Set<Int> =
createQuery {
sql(
"SELECT DISTINCT jamix_customer_number FROM daycare_group WHERE jamix_customer_number IS NOT NULL"
"""
SELECT DISTINCT dg.jamix_customer_number
FROM daycare_group dg
JOIN daycare d ON d.id = dg.daycare_id
WHERE dg.jamix_customer_number IS NOT NULL
AND daterange(d.opening_date, d.closing_date, '[]') && ${bind(range)}
AND daterange(dg.start_date, dg.end_date, '[]') && ${bind(range)}
"""
)
}
.toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fun planJamixOrderJobs(
val range = now.toLocalDate().startOfNextWeek().weekSpan()
val customerMapping = getCustomerMapping(client)
dbc.transaction { tx ->
val customerNumbers = tx.getJamixCustomerNumbers()
val customerNumbers = tx.getJamixCustomerNumbers(range)
planJamixOrderJobs(tx, asyncJobRunner, now, range, customerNumbers, customerMapping)
}
}
Expand Down