diff --git a/gradle.properties b/gradle.properties index 1bf5794a..2d48fba9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.2.0 +version=1.2.1 diff --git a/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java b/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java index dbe4fe1e..1fbd9914 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java @@ -66,6 +66,7 @@ public ExpectationsResponseDto getExpectations(ExpectationsRequest expectationsR .map((expectation -> { String expectationComment = expectation.getExpectationComment(); String name = expectation.getUser().getName(); + name = maskName(name); return new ExpectationContentDto(name, expectationComment); })) .toList(); @@ -104,4 +105,12 @@ public Expectation expectationRegisterApi( return expectationRepository.save(expectation); } + + public static String maskName(String name) { + if(name == null || name.length() < 2) { + return name; + } + + return name.substring(0, 1) + "*" + name.substring(2); + } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java index f8dda485..c5de8677 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java @@ -237,6 +237,10 @@ public QuizFirstComeSubmitResponseDto quizSubmit(QuizFirstComeSubmitRequest quiz return QuizFirstComeSubmitResponseDto.notCorrect(); } + if(eventUserRepository.findByUserIdAndSubEventId(authenticatedUser.getId(), subEventId).isPresent()) { + return QuizFirstComeSubmitResponseDto.alreadyParticipant(); + } + EventUser newEventUser = EventUser.builder() .user(authenticatedUser) .subEvent(subEvent) diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/scheduler/QueueScheduler.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/scheduler/QueueScheduler.java index 0930678b..a8039b6f 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/scheduler/QueueScheduler.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/scheduler/QueueScheduler.java @@ -37,7 +37,6 @@ private void EventScheduler() { for (Long subEventId : subEventIds) { Set tokens = queueService.popTokensFromWaitingQueue(subEventId, POP_CNT); queueService.addTokensToWorkingQueue(tokens); - log.info("waiting queue pop tokens size from subEventId: {} is {}", subEventId, tokens.size()); } } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java index e98edcac..65c4f8b2 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java @@ -20,18 +20,21 @@ import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; +import java.util.*; @Service @RequiredArgsConstructor @Slf4j public class DrawingLotteryService implements LotteryService { + @Autowired + private final MessageSource messageSource; private final SubEventRepository subEventRepository; private final EventUserRepository eventUserRepository; @@ -39,6 +42,8 @@ public class DrawingLotteryService implements LotteryService { private final ScoreCalculator scoreCalculator; private final DrawingRank drawingRank; + private final Random random = new Random(); + public static final int RANK_COUNT = 20; @Value("${properties.event-id}") @@ -165,16 +170,44 @@ public DrawingScoreDto getDrawingScore(User authenticatedUser, DrawingScoreReque }); optionalEventUser.orElseThrow(() -> new EventUserNotFoundException()); + String resultMsg = getRandomMessageForScore((int) accuracy); return DrawingScoreDto.builder() .score(accuracy) .blurImgUrl(drawingEvent.getBlurImgUrl()) - // TODO 점수에 따른 랜덤 메세지 삽입 - .resultMsg("좀 만 더하면 고득점!") + .resultMsg(resultMsg) .resultDetail(drawingEvent.getResultDetail()) .build(); } + private String getRandomMessageForScore(int score) { + String messageKey = getMessageKeyForScore(score); + String messagesString = messageSource.getMessage(messageKey, null, Locale.getDefault()); + List messages = Arrays.asList(messagesString.split(",")); + return getRandomMessage(messages); + } + + private String getMessageKeyForScore(int score) { + if (score >= 90) { + return "drawing.score.message.range.90_100"; + } else if (score >= 70) { + return "drawing.score.message.range.70_90"; + } else if (score >= 50) { + return "drawing.score.message.range.50_70"; + } else if (score >= 30) { + return "drawing.score.message.range.30_50"; + } else if (score >= 10) { + return "drawing.score.message.range.10_30"; + } else { + return "drawing.score.message.range.0_10"; + } + } + + private String getRandomMessage(List messages) { + int index = random.nextInt(messages.size()); + return messages.get(index); + } + @Transactional public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest) { return drawingRank.getDrawingTotalScore(authenticatedUser, subEventRequest, RANK_COUNT); diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/ScoreCalculator.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/ScoreCalculator.java index ca6806a6..7639ac0d 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/ScoreCalculator.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/ScoreCalculator.java @@ -10,7 +10,9 @@ public class ScoreCalculator { public double calculateAverageEuclideanDistance(List userPoints, List answerPoints) { double totalScore = 0.0; int count = 0; - double maxDistance = 100 * Math.sqrt(2); // 최대 거리 계산 + + // 최대 거리를 줄여 점수를 감소시킵니다. + double maxDistance = 20 * Math.sqrt(2); // 예: 최대 거리 조정 for (PositionDto answerPoint : answerPoints) { double minDistance = Double.MAX_VALUE; @@ -21,14 +23,14 @@ public double calculateAverageEuclideanDistance(List userPoints, Li minDistance = Math.min(minDistance, distance); } - // 점수 계산 + // 점수 계산 (감쇠 비율 조정) double score; if (minDistance >= maxDistance) { score = 0; // 최대 거리 이상일 경우 0점 } else if (minDistance == 0) { score = 100; // 완벽히 일치할 경우 100점 } else { - score = 100 * (1 - (minDistance / maxDistance)); // 점수 계산 + score = 100 * Math.pow(1 - (minDistance / maxDistance), 0.3); // 감쇠 비율 조정 } totalScore += score; // 전체 점수에 추가 @@ -38,6 +40,7 @@ public double calculateAverageEuclideanDistance(List userPoints, Li return count == 0 ? 0 : totalScore / count; // count가 0일 경우 0 반환 } + private double getDistance(PositionDto answerPoint, PositionDto userPoint) { double distance = Math.sqrt(Math.pow(answerPoint.getX() - userPoint.getX(), 2) + Math.pow(answerPoint.getY() - userPoint.getY(), 2)); return distance; diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java index 2add7a80..5a0dd056 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java @@ -35,6 +35,7 @@ public List getRankList(SubEventRequest subEventRequest, int rankCount) for (int i = 0; i < topNBySubEventId.size(); i++) { topNBySubEventId.get(i).setRank(i + 1); + topNBySubEventId.get(i).maskingName(); } return topNBySubEventId; diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/dto/RankDto.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/dto/RankDto.java index 43db8407..72706373 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/dto/RankDto.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/dto/RankDto.java @@ -26,4 +26,8 @@ public RankDto(String name, Double score) { public void setRank(Integer rank) { this.rank = rank; } + + public void maskingName() { + this.name = this.name.substring(0, 1) + "*" + this.name.substring(2); + } } diff --git a/src/main/java/com/hyundai/softeer/backend/global/filter/JwtAuthorizationFilter.java b/src/main/java/com/hyundai/softeer/backend/global/filter/JwtAuthorizationFilter.java index b350ecd0..bdbf0570 100644 --- a/src/main/java/com/hyundai/softeer/backend/global/filter/JwtAuthorizationFilter.java +++ b/src/main/java/com/hyundai/softeer/backend/global/filter/JwtAuthorizationFilter.java @@ -48,7 +48,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if ( whiteListCheck(httpServletRequest.getRequestURI()) || - isPreflight(httpServletRequest) + isPreflight(httpServletRequest) ) { chain.doFilter(request, response); return; @@ -60,7 +60,6 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha try { String token = getToken(httpServletRequest); AuthenticateUser authenticateUser = getAuthenticateUser(token); - log.info("값 : {}", authenticateUser.getEmail()); chain.doFilter(request, response); } catch (JsonParseException e) { log.error("JsonParseException"); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties new file mode 100644 index 00000000..aeb23ea3 --- /dev/null +++ b/src/main/resources/messages.properties @@ -0,0 +1,6 @@ +drawing.score.message.range.0_10=이거... 디 올 뉴 싼타페 맞나요? 조금 더 힘내봐요!,이렇게 뾰족한 자동차는 처음 봐요 +drawing.score.message.range.10_30=이건... 세모?,조금 더 빠르고 정확하게 그려주세요! +drawing.score.message.range.30_50=그림이 조금 어렵긴 하죠? 여러 번 그리고 더 높은 점수 노려봐요!,출제자는 잘 그리냐고요? 그 분도 어려워해요 +drawing.score.message.range.50_70=조금만 더 하면 고득점!,딱 80점만 넘겨봐요! +drawing.score.message.range.70_90=그림에 소질이 있으시군요? 조금만 더 하면 100점!,완벽에 가까워지고 있어요:),디 올 뉴 싼타페 장인! +drawing.score.message.range.90_100=완벽해요~! 당신은 디 올 뉴 싼타페 전문가!,이렇게 완벽한 그림을.. 혹시 화가?! diff --git a/src/test/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationServiceTest.java b/src/test/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationServiceTest.java index 798026f6..28fe64a4 100644 --- a/src/test/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationServiceTest.java +++ b/src/test/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationServiceTest.java @@ -158,7 +158,7 @@ void expectationSubmitTest() { ExpectationRegisterRequest request = new ExpectationRegisterRequest(); User authenticatedUser = User.builder() .id(1L) - .name("김민준") + .name("김*준") .email("minjun@naver.com") .phoneNumber("010-6860-6823") .birthDate(LocalDate.now()) @@ -193,7 +193,7 @@ void expectationSubmitTest() { assertThat(resultEvent.getEventName()).isEqualTo("산타페 이벤트"); assertThat(resultEvent.getId()).isEqualTo(1L); - assertThat(resultUser.getName()).isEqualTo("김민준"); + assertThat(resultUser.getName()).isEqualTo("김*준"); assertThat(resultUser.getEmail()).isEqualTo("minjun@naver.com"); assertThat(resultUser.getOAuthProvider()).isEqualTo(OAuthProvider.NAVER); @@ -205,8 +205,9 @@ private List makeMockExpectationContent() { List result = new ArrayList<>(); for (int i = 1; i <= 11; i++) { - result.add(new ExpectationContentDto("김민준" + i, "안녕하세요" + i)); + result.add(new ExpectationContentDto("김*준" + i, "안녕하세요" + i)); } + return result; } diff --git a/src/test/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryServiceTest.java b/src/test/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryServiceTest.java index fb498a96..fd155e86 100644 --- a/src/test/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryServiceTest.java +++ b/src/test/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryServiceTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import org.springframework.context.MessageSource; import java.time.LocalDateTime; import java.util.*; @@ -54,6 +55,9 @@ class DrawingLotteryServiceTest { @Spy private ScoreCalculator scoreCalculator; + @Spy + private MessageSource messageSource; + @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); @@ -542,12 +546,13 @@ void getDrawingScore_success() { when(drawingLotteryRepository.findBySubEventIdAndSequence(any(), any())).thenReturn(Optional.of(drawingEvent)); when(eventUserRepository.findByUserIdAndSubEventId(anyLong(), anyLong())).thenReturn(Optional.of(eventUser)); when(eventUserRepository.save(any())).thenReturn(eventUser); + when(messageSource.getMessage(any(), any(), any())).thenReturn("message"); DrawingScoreDto drawingScore = drawingLotteryService.getDrawingScore(user, drawingScoreRequest); // Then assertThat(drawingScore.getScore()).isInstanceOf(Double.class); - assertThat(drawingScore.getScore()).isGreaterThan(90.0); + assertThat(drawingScore.getScore()).isGreaterThan(80.0); log.info("drawingScore: {}", drawingScore); } @@ -738,6 +743,7 @@ void getDrawingScore_success_low_score() { when(drawingLotteryRepository.findBySubEventIdAndSequence(any(), any())).thenReturn(Optional.of(drawingEvent)); when(eventUserRepository.findByUserIdAndSubEventId(anyLong(), anyLong())).thenReturn(Optional.of(eventUser)); when(eventUserRepository.save(any())).thenReturn(eventUser); + when(messageSource.getMessage(any(), any(), any())).thenReturn("message"); DrawingScoreDto drawingScore = drawingLotteryService.getDrawingScore(user, drawingScoreRequest); @@ -745,6 +751,7 @@ void getDrawingScore_success_low_score() { assertThat(drawingScore.getScore()).isInstanceOf(Double.class); assertThat(drawingScore.getScore()).isLessThan(50.0); log.info("drawingScore: {}", drawingScore); + log.info("drawing result message: {}", drawingScore.getResultMsg()); } }