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

[FIX] #232 admin 게임 관리 페이지에서 점수 수정 시 승패 수정 안되는 문제 #473

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5852d44
[FIX] #232 add flush
AYoungSn Dec 15, 2023
136ee9b
[FIX] #232 repository param name add, flush add
AYoungSn Dec 15, 2023
5142014
[FIX] Merge conflict fix
AYoungSn Dec 15, 2023
e0dd1c7
[FIX] Merge Conflict fix
AYoungSn Dec 29, 2023
a45536c
[FIX] #232 update tier logic add
AYoungSn Dec 29, 2023
4f2ca68
[REFACT] #232 log edit
AYoungSn Jan 2, 2024
2bdb864
[TEST] #232 game result test assertThat add
AYoungSn Jan 2, 2024
144ca03
[FIX] #232 ranking score edit fix
AYoungSn Jan 2, 2024
f6beddc
[MERGE]
AYoungSn Jan 2, 2024
299988b
[FIX] #232 rank repository flush
AYoungSn Jan 2, 2024
6217113
[FIX] #232 rank repository refact
AYoungSn Jan 2, 2024
4c2acc2
Merge branch 'dev' of https://github.com/42organization/42gg.server.d…
AYoungSn Jan 4, 2024
c7a394d
Merge branch 'dev' of https://github.com/42organization/42gg.server.d…
AYoungSn Jan 24, 2024
a34b21d
[FIX] #232 game result edit fix - cache clear
AYoungSn Jan 24, 2024
4dea1af
[FIX] #232 entity manager clear fix
AYoungSn Jan 24, 2024
49eb9a0
[FIX] #232 update dirty checking -> clearAutomatically change
AYoungSn Jan 24, 2024
8f3714c
[TEST] #232 test code entity manger flush remove
AYoungSn Jan 24, 2024
e3536ff
[TEST] #232 test code sleep -> add
AYoungSn Jan 24, 2024
704b00d
[REFACT] #232 func param refactoring
AYoungSn Jan 24, 2024
edef83d
[TEST] #232 foreach -> fori
AYoungSn Jan 24, 2024
b782bab
[FIX] #232 db flush add
AYoungSn Jan 24, 2024
0b149de
[TEST] #232 entity manager clear remove
AYoungSn Jan 24, 2024
3792d65
[FIX] #232 rank redis 트랜잭션 오류 수정
AYoungSn Jan 25, 2024
dd4930e
[REFACT] #232 주석 제거, 안쓰는 함수 제거
AYoungSn Jan 25, 2024
51817ef
[CHORE] #232 yml file log trace 추가
AYoungSn Jan 25, 2024
db248ac
[FIX] #232 rank redis 트랜잭션 오류 수정
AYoungSn Jan 25, 2024
6ac04bb
[FIX] #232 query 2 count -> fetch join 수정
AYoungSn Jan 25, 2024
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
AYoungSn marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gg.server.admin.game.dto.GameUserLogAdminReqDto;
import com.gg.server.admin.game.dto.RankGamePPPModifyReqDto;
import com.gg.server.admin.game.service.GameAdminService;
import com.gg.server.domain.rank.redis.RankRedisService;
import com.gg.server.global.dto.PageRequestDto;
import com.gg.server.global.exception.ErrorCode;
import com.gg.server.global.exception.custom.InvalidParameterException;
Expand All @@ -23,6 +24,7 @@
@RequestMapping("/pingpong/admin/games")
public class GameAdminController {
private final GameAdminService gameAdminService;
private final RankRedisService rankRedisService;

@GetMapping
public GameLogListAdminResponseDto gameFindBySeasonId(@ModelAttribute @Valid PageRequestDto pageRequestDto) {
Expand Down Expand Up @@ -59,6 +61,7 @@ public ResponseEntity<Void> gameResultEdit(@Valid @RequestBody RankGamePPPModify
throw new InvalidParameterException("점수를 잘못 입력했습니다.", ErrorCode.VALID_FAILED);
}
gameAdminService.rankResultEdit(reqDto, gameId);
rankRedisService.updateAllTier(gameId);
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import com.gg.server.domain.season.data.Season;
import com.gg.server.domain.season.exception.SeasonNotFoundException;
import com.gg.server.domain.team.data.TeamUser;
import com.gg.server.domain.tier.service.TierService;
import com.gg.server.domain.user.data.User;
import com.gg.server.domain.user.exception.UserNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.*;
Expand All @@ -38,6 +40,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class GameAdminService {

private final GameAdminRepository gameAdminRepository;
Expand All @@ -48,6 +51,7 @@ public class GameAdminService {
private final RankRedisService rankRedisService;
private final TeamUserAdminRepository teamUserAdminRepository;
private final RedisMatchUserRepository redisMatchUserRepository;
private final TierService tierService;

/**
* <p>토너먼트 게임을 제외한 일반, 랭크 게임들을 찾아서 반환해준다.</p>
Expand Down Expand Up @@ -134,11 +138,15 @@ public void rankResultEdit(RankGamePPPModifyReqDto reqDto, Long gameId) {
throw new PChangeNotExistException();
}
rollbackGameResult(reqDto, season, teamUser, pChanges);
teamUserAdminRepository.flush();
pChangeAdminRepository.delete(pChanges.get(0));
}
for (TeamUser teamUser :
teamUsers) {
updateScore(reqDto, teamUser);
}
teamUserAdminRepository.flush();
rankRedisService.updateRankRedis(teamUsers.get(0), teamUsers.get(1), game);
rankRedisService.updateAllTier(gameId);
tierService.updateAllTier(game.getSeason());
}

private void rollbackGameResult(RankGamePPPModifyReqDto reqDto, Season season, TeamUser teamUser, List<PChange> pChanges) {
Expand All @@ -154,6 +162,9 @@ private void rollbackGameResult(RankGamePPPModifyReqDto reqDto, Season season, T
rankRedisService.rollbackRank(teamUser, pChanges.get(1).getPppResult(), season.getId());
teamUser.getUser().updateExp(pChanges.get(1).getExp());
}
}

private void updateScore(RankGamePPPModifyReqDto reqDto, TeamUser teamUser) {
if (teamUser.getTeam().getId().equals(reqDto.getTeam1Id())) {
teamUser.getTeam().updateScore(reqDto.getTeam1Score(), reqDto.getTeam1Score() > reqDto.getTeam2Score());
} else if (teamUser.getTeam().getId().equals(reqDto.getTeam2Id())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void updatePPP(TeamUser teamuser, RankRedis myTeam, int enemyScore, Integ
log.info("update after: intraId: " + teamuser.getUser().getIntraId() + ", win: db(" + rank.getWins()
+ "), redis(" + myTeam.getWins() + "), losses: db(" + rank.getLosses()
+ "), redis(" + myTeam.getLosses() + ")");
rankRepository.flush();
}

@Transactional
Expand Down Expand Up @@ -128,13 +129,14 @@ public void updateAllTier(Long gameId) {
}
}

@Transactional
public void rollbackRank(TeamUser teamUser, int ppp, Long seasonId) {
String hashkey = RedisKeyManager.getHashKey(seasonId);
RankRedis myTeam = rankRedisRepository.findRankByUserId(hashkey, teamUser.getUser().getId());
int win = teamUser.getTeam().getWin() ? myTeam.getWins() - 1 : myTeam.getWins();
int losses = !teamUser.getTeam().getWin() ? myTeam.getLosses() - 1: myTeam.getLosses();
Rank rank = rankRepository.findByUserIdAndSeasonId(myTeam.getUserId(), seasonId)
.orElseThrow(RankNotFoundException::new);
int win = teamUser.getTeam().getWin() ? rank.getWins() - 1 : rank.getWins();
int losses = !teamUser.getTeam().getWin() ? rank.getLosses() - 1: rank.getLosses();
log.info("Before: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank("
+ rank.getPpp() + "), redis(" + myTeam.getPpp() + "), win: " + myTeam.getWins()
+ ", losses: " + myTeam.getLosses());
Expand Down
Loading