diff --git a/backend-single/src/main/java/com/emotion/service/impl/AiChatServiceImpl.java b/backend-single/src/main/java/com/emotion/service/impl/AiChatServiceImpl.java index 357a86e..04e094c 100644 --- a/backend-single/src/main/java/com/emotion/service/impl/AiChatServiceImpl.java +++ b/backend-single/src/main/java/com/emotion/service/impl/AiChatServiceImpl.java @@ -971,7 +971,11 @@ public class AiChatServiceImpl implements AiChatService { // 只处理answer类型的消息内容 if ("answer".equals(messageType) && content != null && !content.trim().isEmpty()) { log.debug("提取增量内容: {}", content); - responseBuilder.append(content); + // 解析content中的JSON,提取output字段 + String extractedContent = extractOutputFromContent(content); + if (extractedContent != null) { + responseBuilder.append(extractedContent); + } } } @@ -990,7 +994,11 @@ public class AiChatServiceImpl implements AiChatService { // 如果增量方式没有获取到内容,使用完整消息作为备用 if (responseBuilder.length() == 0) { log.info("使用完整消息内容作为备用: {}", content); - responseBuilder.append(content); + // 解析content中的JSON,提取output字段 + String extractedContent = extractOutputFromContent(content); + if (extractedContent != null) { + responseBuilder.append(extractedContent); + } } // 记录完整消息用于验证 log.debug("完整消息内容: {}", content); @@ -1096,7 +1104,11 @@ public class AiChatServiceImpl implements AiChatService { if ("answer".equals(jsonData.getString("type"))) { String content = jsonData.getString("content"); if (content != null && !content.trim().isEmpty()) { - lastCompletedContent = content; + // 解析content中的JSON,提取output字段 + String extractedContent = extractOutputFromContent(content); + if (extractedContent != null) { + lastCompletedContent = extractedContent; + } } } } catch (Exception e) { @@ -1987,6 +1999,27 @@ public class AiChatServiceImpl implements AiChatService { return "/v3/chat"; } + /** + * 从content字段中提取output内容 + */ + private String extractOutputFromContent(String content) { + try { + // 尝试解析content为JSON + JSONObject contentJson = JSON.parseObject(content); + if (contentJson.containsKey("output")) { + String output = contentJson.getString("output"); + log.debug("成功提取output内容: {}", output); + return output; + } else { + log.debug("content中没有output字段,返回原始内容: {}", content); + return content; + } + } catch (Exception e) { + log.debug("content不是有效JSON,返回原始内容: {}, 错误: {}", content, e.getMessage()); + return content; + } + } + /** * 验证Coze请求参数 */ diff --git a/web-admin/.env.production b/web-admin/.env.production index 3a63be0..e6af9e0 100644 --- a/web-admin/.env.production +++ b/web-admin/.env.production @@ -1,4 +1,4 @@ # 生产环境配置 VITE_APP_TITLE=情绪博物馆管理后台 -# 生产环境需要配置实际的后端服务器地址 -VITE_APP_BASE_API=http://localhost:19089/api +# 生产环境使用相对路径,通过nginx代理到后端服务 +VITE_APP_BASE_API=/api diff --git a/web-admin/deploy.sh b/web-admin/deploy.sh index 5cb5d00..3753fa0 100755 --- a/web-admin/deploy.sh +++ b/web-admin/deploy.sh @@ -14,9 +14,13 @@ if ! command -v npm &> /dev/null; then exit 1 fi -# 执行构建(无论dist目录是否存在,都必须构建) -echo "📦 开始构建管理后台项目..." -if npm run build; then +# 清理旧的构建文件 +echo "🧹 清理旧的构建文件..." +rm -rf dist + +# 执行构建(使用生产环境配置) +echo "📦 开始构建管理后台项目(生产环境)..." +if NODE_ENV=production npm run build; then echo "✅ 管理后台项目构建成功" else echo "❌ 管理后台项目构建失败,请检查代码" diff --git a/web/src/services/stomp-websocket.ts b/web/src/services/stomp-websocket.ts index 95504b8..afce415 100644 --- a/web/src/services/stomp-websocket.ts +++ b/web/src/services/stomp-websocket.ts @@ -273,7 +273,7 @@ export class StompWebSocketService { private subscribeToMessages(): void { if (!this.client?.connected) return - // 订阅用户私有消息 + // 订阅用户私有消息 - 这是主要的消息接收频道 if (this.userId) { const userQueuePath = `/user/${this.userId}/queue/messages` console.log('📨 订阅用户私有队列:', userQueuePath) @@ -283,17 +283,18 @@ export class StompWebSocketService { }) } - // 订阅广播消息 + // 订阅广播消息(系统通知等) this.client.subscribe('/topic/broadcast', (message: IMessage) => { this.handleMessage(message) }) - // 如果有会话ID,订阅会话特定消息 - if (this.conversationId) { - this.client.subscribe(`/topic/conversation/${this.conversationId}`, (message: IMessage) => { - this.handleMessage(message) - }) - } + // 注释掉会话特定消息订阅,避免重复接收消息 + // 所有消息都通过用户私有队列接收,确保消息不重复 + // if (this.conversationId) { + // this.client.subscribe(`/topic/conversation/${this.conversationId}`, (message: IMessage) => { + // this.handleMessage(message) + // }) + // } } /**