人生轨迹功能完善
This commit is contained in:
@@ -68,4 +68,14 @@ public class EpicScriptCreateRequest extends BaseRequest {
|
||||
* 是否当前选中
|
||||
*/
|
||||
private Boolean isSelected;
|
||||
|
||||
/**
|
||||
* 角色信息(前端传入,用于AI生成)
|
||||
*/
|
||||
private String characterInfo;
|
||||
|
||||
/**
|
||||
* 过往经历关键词(前端传入,用于AI生成)
|
||||
*/
|
||||
private String lifeEventsSummary;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
|
||||
if (plotJson == null) {
|
||||
plotJson = new java.util.HashMap<>();
|
||||
}
|
||||
plotJson.put("aiGeneratedContent", aiGeneratedContent);
|
||||
plotJson.put("fullContent", aiGeneratedContent);
|
||||
script.setPlotJson(plotJson);
|
||||
log.info("AI生成剧本内容成功,用户ID: {}, 内容长度: {}", currentUserId, aiGeneratedContent.length());
|
||||
}
|
||||
@@ -203,6 +203,16 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
|
||||
private String assembleScriptInput(EpicScriptCreateRequest request) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 角色信息
|
||||
if (StringUtils.hasText(request.getCharacterInfo())) {
|
||||
sb.append("【角色信息】").append(request.getCharacterInfo()).append("\n");
|
||||
}
|
||||
|
||||
// 过往经历
|
||||
if (StringUtils.hasText(request.getLifeEventsSummary())) {
|
||||
sb.append("【过往经历】").append(request.getLifeEventsSummary()).append("\n");
|
||||
}
|
||||
|
||||
// 标题
|
||||
if (StringUtils.hasText(request.getTitle())) {
|
||||
sb.append("【剧本标题】").append(request.getTitle()).append("\n");
|
||||
|
||||
@@ -12,6 +12,9 @@ import com.emotion.entity.LifeEvent;
|
||||
import com.emotion.mapper.LifeEventMapper;
|
||||
import com.emotion.service.LifeEventService;
|
||||
import com.emotion.util.UserContextHolder;
|
||||
import com.emotion.service.AiChatService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -29,6 +32,7 @@ import java.util.stream.Collectors;
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent>
|
||||
implements LifeEventService {
|
||||
|
||||
@@ -36,6 +40,14 @@ public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent
|
||||
private static final DateTimeFormatter ISO_FORMATTER = DateTimeFormatter.ISO_DATE_TIME;
|
||||
private static final DateTimeFormatter DATE_ONLY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
/**
|
||||
* Coze工作流配置键 - AI疗愈
|
||||
*/
|
||||
private static final String COZE_HEALING_CONFIG_KEY = "coze.user.dairy.summary";
|
||||
|
||||
@Autowired
|
||||
private AiChatService aiChatService;
|
||||
|
||||
@Override
|
||||
public PageResult<LifeEventResponse> getPageByCurrentUser(LifeEventPageRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
@@ -139,10 +151,74 @@ public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent
|
||||
event.setEmotionScore(BigDecimal.valueOf(request.getEmotionScore()));
|
||||
}
|
||||
|
||||
// 调用Coze AI进行疗愈回复
|
||||
String aiGeneratedContent = generateHealingByAi(request, currentUserId);
|
||||
if (StringUtils.hasText(aiGeneratedContent)) {
|
||||
event.setAiReply(aiGeneratedContent);
|
||||
}
|
||||
|
||||
this.save(event);
|
||||
return convertToResponse(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用Coze AI生成疗愈内容
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @param userId 用户ID
|
||||
* @return AI生成的疗愈内容,失败时返回null
|
||||
*/
|
||||
private String generateHealingByAi(LifeEventCreateRequest request, String userId) {
|
||||
try {
|
||||
// 组装AI输入
|
||||
String input = assembleHealingInput(request);
|
||||
log.info("开始调用AI生成疗愈回复,用户ID: {}, 输入长度: {}", userId, input.length());
|
||||
|
||||
// 调用Coze工作流
|
||||
String result = aiChatService.callWorkflowByConfigKey(COZE_HEALING_CONFIG_KEY, input, userId);
|
||||
|
||||
log.info("AI生成疗愈回复完成,用户ID: {}, 结果长度: {}", userId, result != null ? result.length() : 0);
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("AI生成疗愈回复失败,用户ID: {}, 错误: {}", userId, e.getMessage(), e);
|
||||
// AI调用失败不影响事件创建,返回null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装AI疗愈输入内容
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @return 格式化的输入字符串
|
||||
*/
|
||||
private String assembleHealingInput(LifeEventCreateRequest request) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 标题
|
||||
if (StringUtils.hasText(request.getTitle())) {
|
||||
sb.append("【事件标题】").append(request.getTitle()).append("\n");
|
||||
}
|
||||
|
||||
// 发生时间
|
||||
if (StringUtils.hasText(request.getEventDate())) {
|
||||
sb.append("【发生时间】").append(request.getEventDate()).append("\n");
|
||||
}
|
||||
|
||||
// 经历详解
|
||||
if (StringUtils.hasText(request.getContent())) {
|
||||
sb.append("【经历详解】").append(request.getContent()).append("\n");
|
||||
}
|
||||
|
||||
// 情绪类型
|
||||
if (StringUtils.hasText(request.getEmotionType())) {
|
||||
sb.append("【情绪类型】").append(request.getEmotionType()).append("\n");
|
||||
}
|
||||
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifeEventResponse updateEvent(LifeEventUpdateRequest request) {
|
||||
LifeEvent event = this.getById(request.getId());
|
||||
|
||||
Reference in New Issue
Block a user