Skip to content
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 @@ -2,7 +2,6 @@ package io.github.devcavin.gatelog.visitors

import io.github.devcavin.gatelog.common.exception.ResourceNotFoundException
import io.github.devcavin.gatelog.common.time.TimeUtil
import io.github.devcavin.gatelog.sites.SiteRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.scheduling.annotation.Scheduled
Expand All @@ -13,7 +12,6 @@ import org.springframework.transaction.annotation.Transactional
class OverdueVisitJob(
private val visitRepository: VisitRepository,
private val visitorStatusRepository: VisitStatusRepository,
private val siteRepository: SiteRepository,
private val timeUtil: TimeUtil,

@Value($$"${gatelog.scheduler.overdue-threshold-hours:2}")
Expand All @@ -32,40 +30,21 @@ class OverdueVisitJob(
visitorStatusRepository.findByName("OVERDUE")
?: throw ResourceNotFoundException(
"Visit Status",
"OVERDUE"
"OVERDUE".lowercase()
)

val threshold =
timeUtil.timeNow().minusHours(overdueThresholdHours)

val sites = siteRepository.findAll()
val flagged = visitRepository.markOverdue(
threshold,
overdueStatus
)

var totalFlagged = 0

sites.forEach { site ->

val siteId = requireNotNull(site.id)

val flagged = visitRepository.markOverdue(
threshold = threshold,
overdueStatus = overdueStatus
)

if (flagged > 0) {
log.info(
"Flagged {} overdue visitor(s) at site {}",
flagged,
siteId
)
}

totalFlagged += flagged
}

if (totalFlagged > 0) {
if (flagged > 0) {
log.info(
"Overdue job complete - {} visitor(s) flagged",
totalFlagged
flagged
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class VisitResponseMapper(
purpose = visit.purpose,
status = visit.visitStatus.name,
siteId = requireNotNull(visit.site.id),
siteName = requireNotNull(visit.site.name),
zoneId = visit.zone?.id,
zoneName = visit.zone?.name,
createdById = requireNotNull(visit.createdBy.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class VisitService(
visitId
)

if (visit.visitStatus.name != CHECKED_IN) {
if (visit.visitStatus.name != CHECKED_IN && visit.visitStatus.name != OVERDUE) {
throw InvalidStateException(
"Visitor is already ${
visit.visitStatus.name
Expand Down
Loading