Skip to content

Commit febe7c0

Browse files
committed
fix: currentStep logic is modified
1 parent 93d4cec commit febe7c0

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

src/main/java/com/back/domain/chatbot/dto/ChatRequestDto.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public class ChatRequestDto {
1616
private Long userId;
1717

1818
// 단계별 추천 관련 필드들
19+
/**
20+
* @deprecated currentStep 필드를 사용하세요. 이 필드는 하위 호환성을 위해 유지됩니다.
21+
*/
22+
@Deprecated
1923
private boolean isStepRecommendation = false;
24+
2025
private Integer currentStep;
2126
// "ALL" 처리를 위해 스텝 3개 String으로 변경
2227
private String selectedAlcoholStrength;

src/main/java/com/back/domain/chatbot/service/ChatbotService.java

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,45 @@ public void init() throws IOException {
8989
@Transactional
9090
public ChatResponseDto sendMessage(ChatRequestDto requestDto) {
9191
try {
92-
// 단계별 추천 모드 확인 (currentStep이 있으면 무조건 단계별 추천 모드)
93-
if (requestDto.isStepRecommendation() ||
94-
requestDto.getCurrentStep() != null ||
95-
isStepRecommendationTrigger(requestDto.getMessage())) {
96-
log.info("Recommendation chat mode for userId: {}", requestDto.getUserId());
92+
Integer currentStep = requestDto.getCurrentStep();
93+
94+
// ========== 1순위: currentStep 명시적 제어 ==========
95+
if (currentStep != null) {
96+
log.info("[EXPLICIT] currentStep={}, userId={}, mode={}",
97+
currentStep, requestDto.getUserId(),
98+
currentStep == 0 ? "QA" : "STEP");
99+
100+
if (currentStep == 0) {
101+
// 질문형 추천 (일반 AI 대화)
102+
log.info("질문형 추천 모드 진입 - userId: {}", requestDto.getUserId());
103+
return generateAIResponseWithContext(requestDto, "질문형 추천");
104+
}
105+
else if (currentStep >= 1 && currentStep <= 4) {
106+
// 단계별 추천
107+
log.info("단계별 추천 모드 진입 - Step: {}, userId: {}",
108+
currentStep, requestDto.getUserId());
109+
return handleStepRecommendation(requestDto);
110+
}
111+
else {
112+
// 유효하지 않은 step 값
113+
log.warn("유효하지 않은 currentStep: {}, userId: {}", currentStep, requestDto.getUserId());
114+
return createErrorResponse("잘못된 단계 정보입니다.");
115+
}
116+
}
117+
118+
// ========== 2순위: 키워드 감지 (하위 호환성) ==========
119+
if (isStepRecommendationTrigger(requestDto.getMessage())) {
120+
log.info("[LEGACY] 키워드 기반 단계별 추천 감지 - userId: {}", requestDto.getUserId());
121+
122+
// FE에서 currentStep을 보내지 않았을 때 자동 설정
123+
requestDto.setCurrentStep(1);
97124
return handleStepRecommendation(requestDto);
98125
}
99126

100-
// 일반 대화 모드
127+
// ========== 3순위: 기본 일반 대화 ==========
128+
log.info("[DEFAULT] 일반 대화 모드 - userId: {}", requestDto.getUserId());
101129
String response = generateAIResponse(requestDto);
102130

103-
// 일반 텍스트 응답 생성 (type이 자동으로 TEXT로 설정됨)
104131
return ChatResponseDto.builder()
105132
.message(response)
106133
.type(MessageType.TEXT)
@@ -109,13 +136,7 @@ public ChatResponseDto sendMessage(ChatRequestDto requestDto) {
109136

110137
} catch (Exception e) {
111138
log.error("채팅 응답 생성 중 오류 발생: ", e);
112-
113-
// 에러 응답
114-
return ChatResponseDto.builder()
115-
.message("죄송합니다. 일시적인 오류가 발생했습니다.")
116-
.type(MessageType.ERROR)
117-
.timestamp(LocalDateTime.now())
118-
.build();
139+
return createErrorResponse("죄송합니다. 일시적인 오류가 발생했습니다.");
119140
}
120141
}
121142

@@ -398,10 +419,45 @@ private InternalMessageType detectMessageType(String message) {
398419
return InternalMessageType.CASUAL_CHAT;
399420
}
400421

401-
// 단계별 추천 시작 키워드 감지
422+
/**
423+
* 단계별 추천 시작 키워드 감지 (레거시 지원)
424+
* @deprecated currentStep 명시적 전달 방식을 사용하세요. 이 메서드는 하위 호환성을 위해 유지됩니다.
425+
*/
426+
@Deprecated
402427
private boolean isStepRecommendationTrigger(String message) {
428+
log.warn("레거시 키워드 감지 사용됨. currentStep 사용 권장. message: {}", message);
403429
String lower = message.toLowerCase().trim();
404-
return lower.contains("단계별 추천");
430+
return lower.contains("단계별 취향 찾기");
431+
}
432+
433+
/**
434+
* 질문형 추천 전용 AI 응답 생성
435+
* 일반 대화와 구분하여 추천에 특화된 응답 생성
436+
*/
437+
private ChatResponseDto generateAIResponseWithContext(ChatRequestDto requestDto, String mode) {
438+
String response = generateAIResponse(requestDto);
439+
440+
return ChatResponseDto.builder()
441+
.message(response)
442+
.type(MessageType.TEXT)
443+
.timestamp(LocalDateTime.now())
444+
.metaData(ChatResponseDto.MetaData.builder()
445+
.actionType(mode)
446+
.currentStep(0)
447+
.totalSteps(0)
448+
.build())
449+
.build();
450+
}
451+
452+
/**
453+
* 에러 응답 생성
454+
*/
455+
private ChatResponseDto createErrorResponse(String errorMessage) {
456+
return ChatResponseDto.builder()
457+
.message(errorMessage)
458+
.type(MessageType.ERROR)
459+
.timestamp(LocalDateTime.now())
460+
.build();
405461
}
406462

407463
private ChatResponseDto handleStepRecommendation(ChatRequestDto requestDto) {
@@ -417,7 +473,7 @@ private ChatResponseDto handleStepRecommendation(ChatRequestDto requestDto) {
417473
switch (currentStep) {
418474
case 1:
419475
stepData = getAlcoholStrengthOptions();
420-
message = "단계별 맞춤 추천을 시작합니다! 🎯\n원하시는 도수를 선택해주세요!";
476+
message = "단계별 맞춤 취향 추천을 시작합니다! 🎯\n원하시는 도수를 선택해주세요!";
421477
type = MessageType.RADIO_OPTIONS;
422478
break;
423479

@@ -448,7 +504,7 @@ private ChatResponseDto handleStepRecommendation(ChatRequestDto requestDto) {
448504

449505
default:
450506
stepData = getAlcoholStrengthOptions();
451-
message = "단계별 맞춤 추천을 시작합니다! 🎯";
507+
message = "단계별 맞춤 취향 추천을 시작합니다! 🎯";
452508
type = MessageType.RADIO_OPTIONS;
453509
}
454510

0 commit comments

Comments
 (0)