Skip to content

Commit

Permalink
Merge pull request #25 from DAY0522/feature/ranking-log
Browse files Browse the repository at this point in the history
Feature/ranking log
  • Loading branch information
chae52 authored Sep 4, 2023
2 parents 7cf5238 + 9d92936 commit 9f42b80
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/management/web/domain/RankingHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.management.web.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

@Entity
@NoArgsConstructor
public class RankingHistory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String kakaoId;
private Long reward;
private Timestamp date;

@Builder
public RankingHistory(String kakaoId, Long reward, Timestamp date) {
this.kakaoId = kakaoId;
this.reward = reward;
this.date = date;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.management.web.repository;

import com.management.web.domain.RankingHistory;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RankingHistoryRepository extends JpaRepository<RankingHistory, Long> {
RankingHistory save(RankingHistory rankingHistory);
}
18 changes: 14 additions & 4 deletions src/main/java/com/management/web/service/RankingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.management.chatbot.domain.Member;
import com.management.chatbot.repository.MemberRepository;
import com.management.web.domain.RankingHistory;
import com.management.web.repository.MemberWebRepository;
import com.management.web.repository.RankingHistoryRepository;
import com.management.web.service.dto.MyPrivateRankingInfoDto;
import com.management.web.service.dto.MyRankingInfoDto;
import com.management.web.repository.MemberWebRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

@Service
Expand All @@ -18,6 +21,7 @@ public class RankingService {

private final MemberWebRepository memberWebRepository;
private final MemberRepository memberRepository;
private final RankingHistoryRepository rankingHistoryRepository;

public List<MyRankingInfoDto> getMyRankingInfo(){
return memberWebRepository.findRankingInfoList();
Expand All @@ -27,9 +31,8 @@ public MyPrivateRankingInfoDto getMyPrivateRankingInfo(String kakaoId) {
}

@Transactional
@Scheduled(cron = "1 0 0 * * 1") // 매주 월요일 00:00:01 마다 실행
@Scheduled(cron = "0 59 23 * * 0") // 매주 일요일 23시 59분에 실행
public void updateRanking() {

List<MyRankingInfoDto> rankingInfoList = memberWebRepository.findRankingInfoList();
for (MyRankingInfoDto rankingInfo : rankingInfoList) {
if (rankingInfo.getCertRank() > 5){
Expand All @@ -38,6 +41,13 @@ public void updateRanking() {
Long additionalReward = Long.valueOf(getAdditionalRankingReward(rankingInfo.getCertRank()));
String kakaoId = rankingInfo.getKakaoId();
Member member = memberRepository.findByKakaoId(kakaoId);

// 현재 시간 timestamp
rankingHistoryRepository.save(RankingHistory.builder()
.kakaoId(kakaoId)
.reward(additionalReward)
.date(new Timestamp(System.currentTimeMillis()))
.build());
member.updateReward(additionalReward);
}
}
Expand Down Expand Up @@ -65,4 +75,4 @@ public int getAdditionalRankingReward(Integer rank) {
return additionalAmount;
}

}
}

0 comments on commit 9f42b80

Please sign in to comment.