-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0b01b9
commit 8c77485
Showing
7 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/hero/alignlab/batch/user/job/UserLevelJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.hero.alignlab.batch.user.job | ||
|
||
import com.hero.alignlab.domain.log.infrastructure.SystemActionLogRepository | ||
import com.hero.alignlab.domain.user.infrastructure.UserInfoRepository | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
class UserLevelJob( | ||
private val systemActionLogRepository: SystemActionLogRepository, | ||
private val userInfoRepository: UserInfoRepository, | ||
) { | ||
fun run() { | ||
val toDate = LocalDateTime.now() | ||
val fromDate = LocalDateTime.now().minusDays(1) | ||
|
||
val activeUsers = systemActionLogRepository.countActiveUser(fromDate, toDate, 1000) | ||
.filter { it.count > 100 } | ||
.map { it.uid } | ||
|
||
val users = userInfoRepository.findAllById(activeUsers) | ||
.mapNotNull { | ||
if (it.maxLevel) { | ||
return@mapNotNull null | ||
} | ||
|
||
it.apply { this.level += 1 } | ||
} | ||
|
||
userInfoRepository.saveAll(users) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/hero/alignlab/batch/user/scheduler/UserLevelScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.hero.alignlab.batch.user.scheduler | ||
|
||
import com.hero.alignlab.batch.user.job.UserLevelJob | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UserLevelScheduler( | ||
private val userLevelJob: UserLevelJob, | ||
) { | ||
@Scheduled(cron = "0 0 * * * *") | ||
fun run() { | ||
CoroutineScope(Dispatchers.IO + Job()).launch { | ||
userLevelJob.run() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters