-
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
f2f36e6
commit 7baf546
Showing
8 changed files
with
60 additions
and
35 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
28 changes: 14 additions & 14 deletions
28
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 |
---|---|---|
@@ -1,32 +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 com.hero.alignlab.domain.log.application.SystemActionLogService | ||
import com.hero.alignlab.domain.user.application.UserInfoService | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
class UserLevelJob( | ||
private val systemActionLogRepository: SystemActionLogRepository, | ||
private val userInfoRepository: UserInfoRepository, | ||
private val systemActionLogService: SystemActionLogService, | ||
private val userInfoService: UserInfoService, | ||
) { | ||
fun run() { | ||
suspend fun run() { | ||
val toDate = LocalDateTime.now() | ||
val fromDate = LocalDateTime.now().minusDays(1) | ||
val fromDate = toDate.minusDays(1) | ||
|
||
val activeUsers = systemActionLogRepository.countActiveUser(fromDate, toDate, 1000) | ||
.filter { it.count > 100 } | ||
.map { it.uid } | ||
val activeUsers = systemActionLogService.countActiveUser(fromDate, toDate, 1000) | ||
.filter { user -> user.count > 100 } | ||
.map { user -> user.uid } | ||
|
||
val users = userInfoRepository.findAllById(activeUsers) | ||
.mapNotNull { | ||
if (it.maxLevel) { | ||
val users = userInfoService.findAllById(activeUsers) | ||
.mapNotNull { user -> | ||
if (user.maxLevel) { | ||
return@mapNotNull null | ||
} | ||
|
||
it.apply { this.level += 1 } | ||
user.apply { this.level += 1 } | ||
} | ||
|
||
userInfoRepository.saveAll(users) | ||
userInfoService.saveAll(users) | ||
} | ||
} |
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
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
15 changes: 3 additions & 12 deletions
15
src/main/kotlin/com/hero/alignlab/event/listener/GroupEventListener.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 |
---|---|---|
@@ -1,28 +1,19 @@ | ||
package com.hero.alignlab.event.listener | ||
|
||
import com.hero.alignlab.common.extension.executes | ||
import com.hero.alignlab.config.database.TransactionTemplates | ||
import com.hero.alignlab.domain.group.domain.GroupUser | ||
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository | ||
import com.hero.alignlab.domain.group.application.GroupUserService | ||
import com.hero.alignlab.event.model.CreateGroupEvent | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
|
||
@Component | ||
class GroupEventListener( | ||
private val groupUserRepository: GroupUserRepository, | ||
private val txTemplates: TransactionTemplates, | ||
private val groupUserService: GroupUserService, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
@TransactionalEventListener | ||
fun handle(event: CreateGroupEvent) { | ||
txTemplates.newTxWriter.executes { | ||
GroupUser( | ||
groupId = event.group.id, | ||
uid = event.group.ownerUid | ||
).run { groupUserRepository.save(this) } | ||
} | ||
groupUserService.saveSync(event.group.id, event.group.ownerUid) | ||
} | ||
} |
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