-
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.
Browse files
Browse the repository at this point in the history
feat: νμ κ΄κ³ μ μ κ³μ°
- Loading branch information
Showing
4 changed files
with
56 additions
and
3 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
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
46 changes: 46 additions & 0 deletions
46
backEnd/src/main/java/com/quiz/ourclass/global/util/scheduler/SchedulingService.java
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,25 +1,71 @@ | ||
package com.quiz.ourclass.global.util.scheduler; | ||
|
||
import com.quiz.ourclass.domain.organization.entity.Relationship; | ||
import com.quiz.ourclass.domain.organization.repository.RelationshipRepository; | ||
import com.quiz.ourclass.domain.relay.repository.RelayMemberRepository; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.TaskScheduler; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
|
||
@EnableScheduling | ||
@RequiredArgsConstructor | ||
@Service | ||
public class SchedulingService { | ||
|
||
private final TaskScheduler taskScheduler; | ||
private final TransactionTemplate transactionTemplate; | ||
private final RelationshipRepository relationshipRepository; | ||
private final RelayMemberRepository relayMemberRepository; | ||
|
||
public <T> void scheduleTask(T target, Consumer<T> action, LocalDateTime executionTime) { | ||
SchedulingTask<T> task = new SchedulingTask<>(target, action, transactionTemplate); | ||
Instant executionDate = executionTime.atZone(ZoneId.systemDefault()).toInstant(); | ||
|
||
taskScheduler.schedule(task, executionDate); | ||
} | ||
|
||
@Transactional | ||
@Scheduled(cron = "0 0 3 * * *") | ||
protected void relationShipScore() { | ||
List<Relationship> relationshipList = | ||
relationshipRepository.findAllByOrganizationIdOrderByMember1(1L); | ||
|
||
if (!relationshipList.isEmpty()) { | ||
relationshipList.stream() | ||
.map(this::updateRelationShipScore) | ||
.forEach(relationshipRepository::save); | ||
} | ||
} | ||
|
||
private Relationship updateRelationShipScore(Relationship relationship) { | ||
double newScore = calculateScore(relationship); | ||
relationship.updateRelationPoint(newScore); | ||
return relationship; | ||
} | ||
|
||
private double calculateScore(Relationship relationship) { | ||
//TODO : relayCount λΉμ κ·νν΄μ κ°μ Έμ€κΈ° | ||
int sendCount = relayMemberRepository.countByCurMemberIdAndNextMemberId( | ||
relationship.getMember1().getId(), relationship.getMember2().getId() | ||
); | ||
int receiveCount = relayMemberRepository.countByCurMemberIdAndNextMemberId( | ||
relationship.getMember1().getId(), relationship.getMember2().getId() | ||
); | ||
|
||
return relationship.getFreeGroupCount() * 1.5 | ||
+ relationship.getSocialCount() * 1.0 | ||
+ relationship.getTagGreetingCount() * 0.75 | ||
// + relationship.getRelayCount() * 0.5 | ||
+ (sendCount + receiveCount) * 0.5 | ||
+ relationship.getDesignGroupCount() * 0.25; | ||
} | ||
} |