当前位置: 首页> 教育> 培训 > 爱客装修官网_江门模板建站定制网站_百度建站平台官网_青岛官网优化

爱客装修官网_江门模板建站定制网站_百度建站平台官网_青岛官网优化

时间:2025/9/8 15:03:11来源:https://blog.csdn.net/2301_76212858/article/details/147253724 浏览次数:0次
爱客装修官网_江门模板建站定制网站_百度建站平台官网_青岛官网优化

一、目标功能

用户可修改问题重新提问的功能

二、代码实现

Service层

// 添加消息修改方法
@Transactional
public QaMessage updateMessage(Long messageId, String newContent) {
    QaMessage message = messageRepository.findById(messageId)
            .orElseThrow(() -> new RuntimeException("Message not found"));
    
    if (!"user".equals(message.getRole())) {
        throw new IllegalArgumentException("只能修改用户消息");
    }
    
    // 清除关联的后续对话
    message.getQaMessages().clear();
    message.setContent(newContent);
    message.setIsCurrent(true);
    
    // 生成新的AI回答
    String aiResponse = aiService.getAIResponse(newContent);
    QaMessage aiMessage = new QaMessage();
    aiMessage.setSession(message.getSession());
    aiMessage.setRole("assistant");
    aiMessage.setContent(aiResponse);
    aiMessage.setParent(message);
    aiMessage.setCreatedAt(Instant.now());
    
    messageRepository.save(message);
    return messageRepository.save(aiMessage);
}

2.Controller层

// 添加消息修改端点
@PutMapping("/messages/{messageId}")
public ResponseEntity<QaMessage> updateMessage(
        @PathVariable Long messageId,
        @RequestBody UpdateMessageRequest request) {
    return ResponseEntity.ok(qaService.updateMessage(messageId, request.newContent()));
}

// DTO定义
public record UpdateMessageRequest(String newContent) {}

关键字:爱客装修官网_江门模板建站定制网站_百度建站平台官网_青岛官网优化

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: