Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
konke-ai-alibaba-mcp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何金镒
konke-ai-alibaba-mcp
Commits
0894277f
Commit
0894277f
authored
Oct 29, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理
parent
3c009632
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
100 deletions
+111
-100
src/main/java/com/ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
...ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
+103
-100
src/main/java/com/ikonke/konkeaialibabamcp/event/listener/DifyChatSteamEventListener.java
...alibabamcp/event/listener/DifyChatSteamEventListener.java
+8
-0
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
View file @
0894277f
...
...
@@ -2,8 +2,6 @@ package com.ikonke.konkeaialibabamcp.controller;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.json.JSON
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
...
...
@@ -18,19 +16,16 @@ import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils;
import
com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService
;
import
com.ikonke.konkeaialibabamcp.utils.CcuUtils
;
import
com.ikonke.konkeaialibabamcp.utils.WebSocketUtil
;
import
jakarta.annotation.PostConstruct
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Flux
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.time.Duration
;
...
...
@@ -155,10 +150,15 @@ public class DifyControllerV2 {
||
cleanedInput
.
equalsIgnoreCase
(
"闭嘴"
)
||
cleanedInput
.
equalsIgnoreCase
(
"不要说话"
)){
res
=
String
.
format
(
res
,
"好的"
,
true
);
}
else
{
// 异步执行对话????
if
(!
webSocketUtil
.
getWebSocket
(
token
.
getSn
()))
{
log
.
error
(
"未找到sn:{}的WebSocket连接,不处理对话1"
,
token
.
getSn
());
res
=
String
.
format
(
res
,
"网络异常,请检查网络"
,
false
);
}
else
{
// 异步执行对话
eventPublisher
.
publishEvent
(
new
DifyChatSteamEvent
(
this
,
token
.
getSn
(),
cleanedInput
));
res
=
String
.
format
(
res
,
"正在思考中"
,
false
);
}
}
}
else
{
res
=
String
.
format
(
res
,
"未检查到输入"
,
false
);
}
...
...
@@ -184,7 +184,8 @@ public class DifyControllerV2 {
@GetMapping
(
"/chatSteamMessages"
)
public
Flux
<
String
>
chatSteamMessages
(
@RequestParam
(
name
=
"query"
)
String
query
,
@RequestHeader
(
"sn"
)
String
sn
)
throws
UnsupportedEncodingException
{
@RequestHeader
(
"sn"
)
String
sn
)
{
try
{
log
.
info
(
"【{}】:开始 流式 对话, query:{}"
,
sn
,
query
);
QueryWrapper
<
CDCToken
>
wrapper
=
new
QueryWrapper
<>();
...
...
@@ -228,12 +229,10 @@ public class DifyControllerV2 {
inputs
.
set
(
"communityId"
,
userEntity
.
getCommunityId
());
inputs
.
set
(
"easId"
,
userEntity
.
getEasId
());
inputs
.
set
(
"roomId"
,
userEntity
.
getRoomInfo
().
getRoomId
());
// inputs.set("roomName",userEntity.getRoomInfo().getRoomName());
inputs
.
set
(
"roomName"
,
URLEncoder
.
encode
(
userEntity
.
getRoomInfo
().
getRoomName
(),
StandardCharsets
.
UTF_8
.
name
()));
inputs
.
set
(
"buildingId"
,
userEntity
.
getRoomInfo
().
getBuildingId
());
inputs
.
set
(
"userPhone"
,
userEntity
.
getPhoneNum
());
// inputs.set("userName",userEntity.getPhoneNum());
inputs
.
set
(
"userName"
,
URLEncoder
.
encode
(
userEntity
.
getNickName
(),
StandardCharsets
.
UTF_8
.
name
()));
inputs
.
set
(
"today"
,
DateUtil
.
today
());
...
...
@@ -281,6 +280,10 @@ public class DifyControllerV2 {
log
.
info
(
"异常输出:"
+
throwable
.
getMessage
());
return
null
;
});
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
Flux
.
just
(
"服务器异常,稍后重试."
);
}
private
String
convertToCustomResponseAsync
(
DifyStreamResponse
difyStreamResponse
,
String
sn
,
String
ccuName
,
String
token
,
Object
redis_conversationId
)
{
...
...
src/main/java/com/ikonke/konkeaialibabamcp/event/listener/DifyChatSteamEventListener.java
View file @
0894277f
...
...
@@ -57,6 +57,14 @@ public class DifyChatSteamEventListener {
.
execute
().
body
();
log
.
info
(
"dify请求返回11--->:{}"
,
ai_result
);
if
(
ai_result
.
contains
(
"服务器异常"
)){
JSONObject
json
=
new
JSONObject
();
json
.
set
(
"msg"
,
ai_result
);
json
.
set
(
"type"
,
"other"
);
webSocketUtil
.
sendToSingle
(
event
.
getSn
(),
json
.
toString
());
}
// ai_result = ai_result.replaceAll("\n", "##").trim();
// log.info("dify请求返回22--->:{}",ai_result);
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment