캐릭터 챗봇 #338
| @@ -75,13 +75,13 @@ class ChatCharacter( | |||||||
|     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) |     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) | ||||||
|     var tagMappings: MutableList<ChatCharacterTagMapping> = mutableListOf() |     var tagMappings: MutableList<ChatCharacterTagMapping> = mutableListOf() | ||||||
|  |  | ||||||
|     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY) |     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) | ||||||
|     var valueMappings: MutableList<ChatCharacterValueMapping> = mutableListOf() |     var valueMappings: MutableList<ChatCharacterValueMapping> = mutableListOf() | ||||||
|  |  | ||||||
|     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY) |     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) | ||||||
|     var hobbyMappings: MutableList<ChatCharacterHobbyMapping> = mutableListOf() |     var hobbyMappings: MutableList<ChatCharacterHobbyMapping> = mutableListOf() | ||||||
|  |  | ||||||
|     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY) |     @OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) | ||||||
|     var goalMappings: MutableList<ChatCharacterGoalMapping> = mutableListOf() |     var goalMappings: MutableList<ChatCharacterGoalMapping> = mutableListOf() | ||||||
|  |  | ||||||
|     // 태그 추가 헬퍼 메소드 |     // 태그 추가 헬퍼 메소드 | ||||||
|   | |||||||
| @@ -172,6 +172,66 @@ class ChatCharacterService( | |||||||
|         goals.forEach { addGoalToCharacter(chatCharacter, it) } |         goals.forEach { addGoalToCharacter(chatCharacter, it) } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 가치관 매핑 증분 업데이트 | ||||||
|  |      */ | ||||||
|  |     @Transactional | ||||||
|  |     fun updateValuesForCharacter(chatCharacter: ChatCharacter, values: List<String>) { | ||||||
|  |         val desired = values.distinct() | ||||||
|  |         val current = chatCharacter.valueMappings.map { it.value.value } | ||||||
|  |         val toAdd = desired.filterNot { current.contains(it) } | ||||||
|  |         toAdd.forEach { addValueToCharacter(chatCharacter, it) } | ||||||
|  |         if (chatCharacter.valueMappings.isNotEmpty()) { | ||||||
|  |             val iterator = chatCharacter.valueMappings.iterator() | ||||||
|  |             while (iterator.hasNext()) { | ||||||
|  |                 val mapping = iterator.next() | ||||||
|  |                 if (!desired.contains(mapping.value.value)) { | ||||||
|  |                     iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 취미 매핑 증분 업데이트 | ||||||
|  |      */ | ||||||
|  |     @Transactional | ||||||
|  |     fun updateHobbiesForCharacter(chatCharacter: ChatCharacter, hobbies: List<String>) { | ||||||
|  |         val desired = hobbies.distinct() | ||||||
|  |         val current = chatCharacter.hobbyMappings.map { it.hobby.hobby } | ||||||
|  |         val toAdd = desired.filterNot { current.contains(it) } | ||||||
|  |         toAdd.forEach { addHobbyToCharacter(chatCharacter, it) } | ||||||
|  |         if (chatCharacter.hobbyMappings.isNotEmpty()) { | ||||||
|  |             val iterator = chatCharacter.hobbyMappings.iterator() | ||||||
|  |             while (iterator.hasNext()) { | ||||||
|  |                 val mapping = iterator.next() | ||||||
|  |                 if (!desired.contains(mapping.hobby.hobby)) { | ||||||
|  |                     iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 목표 매핑 증분 업데이트 | ||||||
|  |      */ | ||||||
|  |     @Transactional | ||||||
|  |     fun updateGoalsForCharacter(chatCharacter: ChatCharacter, goals: List<String>) { | ||||||
|  |         val desired = goals.distinct() | ||||||
|  |         val current = chatCharacter.goalMappings.map { it.goal.goal } | ||||||
|  |         val toAdd = desired.filterNot { current.contains(it) } | ||||||
|  |         toAdd.forEach { addGoalToCharacter(chatCharacter, it) } | ||||||
|  |         if (chatCharacter.goalMappings.isNotEmpty()) { | ||||||
|  |             val iterator = chatCharacter.goalMappings.iterator() | ||||||
|  |             while (iterator.hasNext()) { | ||||||
|  |                 val mapping = iterator.next() | ||||||
|  |                 if (!desired.contains(mapping.goal.goal)) { | ||||||
|  |                     iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 캐릭터 저장 |      * 캐릭터 저장 | ||||||
|      */ |      */ | ||||||
| @@ -441,18 +501,15 @@ class ChatCharacterService( | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (request.values != null) { |         if (request.values != null) { | ||||||
|             chatCharacter.valueMappings.clear() |             updateValuesForCharacter(chatCharacter, request.values) | ||||||
|             addValuesToCharacter(chatCharacter, request.values) |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (request.hobbies != null) { |         if (request.hobbies != null) { | ||||||
|             chatCharacter.hobbyMappings.clear() |             updateHobbiesForCharacter(chatCharacter, request.hobbies) | ||||||
|             addHobbiesToCharacter(chatCharacter, request.hobbies) |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (request.goals != null) { |         if (request.goals != null) { | ||||||
|             chatCharacter.goalMappings.clear() |             updateGoalsForCharacter(chatCharacter, request.goals) | ||||||
|             addGoalsToCharacter(chatCharacter, request.goals) |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // 추가 정보 설정 - 변경된 데이터만 업데이트 |         // 추가 정보 설정 - 변경된 데이터만 업데이트 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user