Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

버튼게임 수정사항 #179

Merged
merged 3 commits into from
May 12, 2024
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 @@ -5,6 +5,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import team.gsmgogo.domain.bet.entity.BetEntity;
import team.gsmgogo.domain.bet.repository.BetJpaRepository;
import team.gsmgogo.domain.buttongame.entity.ButtonGameEntity;
import team.gsmgogo.domain.buttongame.repository.ButtonGameRepository;
import team.gsmgogo.domain.buttongameparticipate.entity.ButtonGameParticipate;
Expand All @@ -15,13 +17,19 @@
import team.gsmgogo.global.exception.error.ExpectedException;
import team.gsmgogo.global.facade.UserFacade;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Service
@RequiredArgsConstructor
public class ButtonGameServiceImpl implements ButtonGameService {

private final UserFacade userFacade;
private final ButtonGameRepository buttonGameRepository;
private final ButtonGameParticipateRepository buttonGameParticipateRepository;
private final BetJpaRepository buttonGameParticipate;

private final int LIMIT_POINT = 500_000;

@Override
@Transactional(isolation = Isolation.SERIALIZABLE)
Expand All @@ -35,6 +43,15 @@ public void execute(ButtonGameRequest request) {
if (buttonGameParticipateRepository.existsByButtonGameAndUser(buttonGame, currentUser))
throw new ExpectedException("이미 버튼을 눌렀습니다.", HttpStatus.BAD_REQUEST);

AtomicInteger betPoint = new AtomicInteger();
buttonGameParticipate.findByUser(currentUser)
.stream()
.filter(bet -> !bet.getMatch().getIsEnd()).toList()
.forEach(bet -> betPoint.addAndGet(bet.getBetPoint().intValue()));

if ((currentUser.getPoint() + betPoint.get()) >= LIMIT_POINT)
throw new ExpectedException("50만 포인트 이상 보유한 유저는 버튼게임에 참여할 수 없습니다.", HttpStatus.BAD_REQUEST);

ButtonGameParticipate buttonGameParticipate = ButtonGameParticipate.builder()
.buttonGame(buttonGame)
.user(currentUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ public class ButtonGameCalculateScheduler {
private final UserJpaRepository userJpaRepository;
private final ButtonGameParticipateQueryDslRepository buttonGameParticipateQueryDslRepository;

@Scheduled(cron = "0 0 23 * * *")
public void start() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
// @Scheduled(cron = "0 0 23 * * *")
// public void start() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
//
// Map<String, JobParameter<?>> jobParametersMap = new HashMap<>();
// jobParametersMap.put("button-game-time", new JobParameter(System.currentTimeMillis(), String.class));
// JobParameters jobParameters = new JobParameters(jobParametersMap);
//
// jobLauncher.run(
// new CalculateButtonGameJob(
// jobRepository,
// platformTransactionManager,
// buttonGameRepository,
// userJpaRepository,
// buttonGameParticipateQueryDslRepository).calculateButtonGameJob(),
// jobParameters
// );
// }

Map<String, JobParameter<?>> jobParametersMap = new HashMap<>();
jobParametersMap.put("button-game-time", new JobParameter(System.currentTimeMillis(), String.class));
JobParameters jobParameters = new JobParameters(jobParametersMap);

jobLauncher.run(
new CalculateButtonGameJob(
jobRepository,
platformTransactionManager,
buttonGameRepository,
userJpaRepository,
buttonGameParticipateQueryDslRepository).calculateButtonGameJob(),
jobParameters
);
}
}
Loading