@@ -8,7 +8,6 @@ import eu.pretix.libpretixsync.crypto.isValidSignature
88import eu.pretix.libpretixsync.crypto.readPubkeyFromPem
99import eu.pretix.libpretixsync.crypto.sig1.TicketProtos
1010import eu.pretix.libpretixsync.db.Answer
11- import eu.pretix.libpretixsync.db.CheckIn
1211import eu.pretix.libpretixsync.db.CheckInList
1312import eu.pretix.libpretixsync.db.CheckInList_Item
1413import eu.pretix.libpretixsync.db.Item
@@ -19,6 +18,7 @@ import eu.pretix.libpretixsync.db.QuestionLike
1918import eu.pretix.libpretixsync.db.QueuedCall
2019import eu.pretix.libpretixsync.db.QueuedCheckIn
2120import eu.pretix.libpretixsync.db.ReusableMedium
21+ import eu.pretix.libpretixsync.models.CheckIn
2222import eu.pretix.libpretixsync.models.Event
2323import eu.pretix.libpretixsync.models.Question
2424import eu.pretix.libpretixsync.models.db.toModel
@@ -713,11 +713,9 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
713713 res.isRequireAttention = require_attention || variation?.isCheckin_attention == true
714714 res.checkinTexts = listOfNotNull(order.checkin_text?.trim(), variation?.checkin_text?.trim(), item.checkin_text?.trim()).filterNot { it.isBlank() || it == " null" }
715715
716- val storedCheckIns = dataStore.select(CheckIn ::class .java)
717- .where(CheckIn .POSITION_ID .eq(position.getId()))
718- .get().toList()
716+ val storedCheckIns = db.checkInQueries.selectByPositionId(position.getId()).executeAsList().map { it.toModel() }
719717 val checkIns = storedCheckIns.filter {
720- it.getListId() == listId
718+ it.listServerId == listId
721719 }.sortedWith(compareBy({ it.fullDatetime }, { it.id }))
722720
723721 if (order.getStatus() != " p" && order.getStatus() != " n" ) {
@@ -797,41 +795,41 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
797795 data.put(" now_isoweekday" , dt.withZone(tz).dayOfWeek().get())
798796 data.put(" entries_number" , checkIns.filter { it.type == " entry" }.size)
799797 data.put(" entries_today" , checkIns.filter {
800- DateTime ( it.fullDatetime) .withZone(tz).toLocalDate() == dt.withZone(tz).toLocalDate() && it.type == " entry"
798+ it.fullDatetime.withZone(tz).toLocalDate() == dt.withZone(tz).toLocalDate() && it.type == " entry"
801799 }.size)
802800 data.put(" entries_since" , { cutoff: DateTime ->
803801 checkIns.filter {
804- DateTime ( it.fullDatetime) .withZone(tz).isAfter(cutoff.minus(Duration .millis(1 ))) && it.type == " entry"
802+ it.fullDatetime.withZone(tz).isAfter(cutoff.minus(Duration .millis(1 ))) && it.type == " entry"
805803 }.size
806804 })
807805 data.put(" entries_days_since" , { cutoff: DateTime ->
808806 checkIns.filter {
809- DateTime ( it.fullDatetime) .withZone(tz).isAfter(cutoff.minus(Duration .millis(1 ))) && it.type == " entry"
807+ it.fullDatetime.withZone(tz).isAfter(cutoff.minus(Duration .millis(1 ))) && it.type == " entry"
810808 }.map {
811- DateTime ( it.fullDatetime) .withZone(tz).toLocalDate()
809+ it.fullDatetime.withZone(tz).toLocalDate()
812810 }.toHashSet().size
813811 })
814812 data.put(" entries_before" , { cutoff: DateTime ->
815813 checkIns.filter {
816- DateTime ( it.fullDatetime) .withZone(tz).isBefore(cutoff) && it.type == " entry"
814+ it.fullDatetime.withZone(tz).isBefore(cutoff) && it.type == " entry"
817815 }.size
818816 })
819817 data.put(" entries_days_before" , { cutoff: DateTime ->
820818 checkIns.filter {
821- DateTime ( it.fullDatetime) .withZone(tz).isBefore(cutoff) && it.type == " entry"
819+ it.fullDatetime.withZone(tz).isBefore(cutoff) && it.type == " entry"
822820 }.map {
823- DateTime ( it.fullDatetime) .withZone(tz).toLocalDate()
821+ it.fullDatetime.withZone(tz).toLocalDate()
824822 }.toHashSet().size
825823 })
826824 data.put(" entries_days" , checkIns.filter { it.type == " entry" }.map {
827- DateTime ( it.fullDatetime) .withZone(tz).toLocalDate()
825+ it.fullDatetime.withZone(tz).toLocalDate()
828826 }.toHashSet().size)
829827 val minutes_since_entries = checkIns.filter { it.type == " entry" }.map {
830- Duration (DateTime ( it.fullDatetime) .withZone(tz), dt).toStandardMinutes().minutes
828+ Duration (it.fullDatetime.withZone(tz), dt).toStandardMinutes().minutes
831829 }
832830 data.put(" minutes_since_last_entry" , minutes_since_entries.minOrNull() ? : - 1 )
833831 data.put(" minutes_since_first_entry" , minutes_since_entries.maxOrNull() ? : - 1 )
834- data.put(" entry_status" , if (checkIns.lastOrNull()?.getType() == " entry" ) {
832+ data.put(" entry_status" , if (checkIns.lastOrNull()?.type == " entry" ) {
835833 " present"
836834 } else {
837835 " absent"
@@ -916,7 +914,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
916914 )
917915 if (! entry_allowed) {
918916 res.isCheckinAllowed = false
919- res.firstScanned = checkIns.first().fullDatetime
917+ res.firstScanned = checkIns.first().fullDatetime.toDate()
920918 res.type = TicketCheckProvider .CheckResult .Type .USED
921919 storeFailedCheckin(eventSlug, list.getServer_id(), " already_redeemed" , position.secret, type, position = position.getServer_id(), item = position.getItem().getServer_id(), variation = position.getVariation_id(), subevent = position.getSubevent_id(), nonce = nonce)
922920 } else {
@@ -936,13 +934,14 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
936934 qci.setType(type.toString().lowercase(Locale .getDefault()))
937935 qci.setCheckinListId(listId)
938936 dataStore.insert(qci)
939- val ci = CheckIn ()
940- ci.setListId(listId)
941- ci.setPosition(position)
942- ci.setType(type.toString().lowercase(Locale .getDefault()))
943- ci.setDatetime(dt.toDate())
944- ci.setJson_data(" {\" local\" : true, \" type\" : \" ${type.toString().lowercase(Locale .getDefault())} \" , \" datetime\" : \" ${QueuedCheckIn .formatDatetime(dt.toDate())} \" }" )
945- dataStore.insert(ci)
937+ db.checkInQueries.insert(
938+ server_id = null ,
939+ listId = listId,
940+ position = position.getId(),
941+ type = type.toString().lowercase(Locale .getDefault()),
942+ datetime = dt.toDate(),
943+ json_data = " {\" local\" : true, \" type\" : \" ${type.toString().lowercase(Locale .getDefault())} \" , \" datetime\" : \" ${QueuedCheckIn .formatDatetime(dt.toDate())} \" }" ,
944+ )
946945 }
947946 }
948947
@@ -1083,9 +1082,10 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
10831082
10841083 if (onlyCheckedIn) {
10851084 lq = lq.and (OrderPosition .ID .`in `(
1086- dataStore.select(CheckIn .POSITION_ID )
1087- .where(CheckIn .LIST_ID .eq(list.getServer_id()))
1088- .and (CheckIn .TYPE .eq(" entry" ))
1085+ db.checkInQueries.selectPositionIdByListIdAndType(
1086+ list_server_id = list.getServer_id(),
1087+ type = " entry"
1088+ ).executeAsList().map { it.position }
10891089 ))
10901090 }
10911091 q = q.or (lq)
@@ -1160,4 +1160,15 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
11601160 private fun now (): DateTime {
11611161 return overrideNow ? : DateTime ()
11621162 }
1163+
1164+ private val CheckIn .fullDatetime : DateTime
1165+ get() {
1166+ // To avoid Joda Time code in the models, handle the case where we don't have a datetime value from JSON here
1167+ return if (this .datetime != null ) {
1168+ DateTime (this .datetime.toInstant())
1169+ } else {
1170+ val date = db.checkInQueries.selectById(this .id).executeAsOne().datetime
1171+ DateTime (date)
1172+ }
1173+ }
11631174}
0 commit comments