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
fdfce929
Commit
fdfce929
authored
Oct 27, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化对话返回
parent
a2402a1b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
16 deletions
+83
-16
src/main/java/com/ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
...ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
+26
-0
src/main/java/com/ikonke/konkeaialibabamcp/controller/param/WebSocketParam.java
...ke/konkeaialibabamcp/controller/param/WebSocketParam.java
+13
-0
src/main/java/com/ikonke/konkeaialibabamcp/event/listener/DifyChatSteamEventListener.java
...alibabamcp/event/listener/DifyChatSteamEventListener.java
+16
-16
src/test/java/com/ikonke/konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
.../konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
+28
-0
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/controller/DifyControllerV2.java
View file @
fdfce929
...
...
@@ -9,12 +9,14 @@ import cn.hutool.json.JSONUtil;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.ikonke.konkeaialibabamcp.constant.RedisKeys
;
import
com.ikonke.konkeaialibabamcp.controller.param.DifyStreamResponse
;
import
com.ikonke.konkeaialibabamcp.controller.param.WebSocketParam
;
import
com.ikonke.konkeaialibabamcp.entity.cdc.UserEntity
;
import
com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken
;
import
com.ikonke.konkeaialibabamcp.event.mode.DifyChatSteamEvent
;
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
;
...
...
@@ -22,6 +24,7 @@ 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
;
...
...
@@ -41,6 +44,8 @@ public class DifyControllerV2 {
private
WebClient
webClient
;
@Autowired
private
CdcHttpUtils
cdcHttpUtils
;
@Autowired
private
WebSocketUtil
webSocketUtil
;
private
final
ApplicationEventPublisher
eventPublisher
;
...
...
@@ -73,6 +78,27 @@ public class DifyControllerV2 {
// }
// }
@PostMapping
(
value
=
"/sendToWebSocket"
)
public
void
sendToWebSocket
(
@RequestBody
WebSocketParam
param
)
{
String
sn
=
param
.
getSn
();
String
msg
=
param
.
getMsg
();
String
type
=
param
.
getType
();
String
sceneid
=
param
.
getSceneid
();
if
(
StrUtil
.
isNotBlank
(
sn
)
&&
StrUtil
.
isNotBlank
(
msg
)){
log
.
info
(
"【{}】:sendToWebSocket..请求参数:{},type:{}"
,
sn
,
msg
,
type
);
if
(
StrUtil
.
isBlank
(
type
)){
type
=
"other"
;
}
JSONObject
json
=
new
JSONObject
();
json
.
set
(
"msg"
,
msg
);
json
.
set
(
"type"
,
type
);
if
(
StrUtil
.
isNotBlank
(
sceneid
)){
json
.
set
(
"sceneid"
,
sceneid
);
}
webSocketUtil
.
sendToSingle
(
sn
,
json
.
toString
());
}
}
/**
...
...
src/main/java/com/ikonke/konkeaialibabamcp/controller/param/WebSocketParam.java
0 → 100644
View file @
fdfce929
package
com.ikonke.konkeaialibabamcp.controller.param
;
import
lombok.Data
;
@Data
public
class
WebSocketParam
{
private
String
sn
;
private
String
type
;
private
String
sceneid
;
private
String
msg
;
}
src/main/java/com/ikonke/konkeaialibabamcp/event/listener/DifyChatSteamEventListener.java
View file @
fdfce929
...
...
@@ -57,24 +57,24 @@ public class DifyChatSteamEventListener {
.
execute
().
body
();
log
.
info
(
"dify请求返回11--->:{}"
,
ai_result
);
ai_result
=
ai_result
.
replaceAll
(
"\n"
,
"##"
).
trim
();
log
.
info
(
"dify请求返回22--->:{}"
,
ai_result
);
JSONObject
json
=
new
JSONObject
();
if
(!
JSONUtil
.
isTypeJSON
(
ai_result
)){
json
.
put
(
"msg"
,
ai_result
);
json
.
put
(
"type"
,
"other"
);
}
else
{
json
=
JSONUtil
.
parseObj
(
ai_result
);
if
(!
json
.
containsKey
(
"type"
)){
json
.
put
(
"type"
,
"other"
);
}
}
log
.
info
(
"【{}】:dify请求返回:{}"
,
event
.
getSn
(),
json
);
//
ai_result = ai_result.replaceAll("\n", "##").trim();
//
log.info("dify请求返回22--->:{}",ai_result);
//
//
JSONObject json = new JSONObject();
//
if(!JSONUtil.isTypeJSON(ai_result)){
//
json.put("msg", ai_result);
//
json.put("type", "other");
//
}else{
//
json = JSONUtil.parseObj(ai_result);
//
if(!json.containsKey("type")){
//
json.put("type", "other");
//
}
//
}
//
//
log.info("【{}】:dify请求返回:{}",event.getSn(),json);
// 通过WebSocket发送消息给屏端
webSocketUtil
.
sendToSingle
(
event
.
getSn
(),
json
.
toString
());
//
webSocketUtil.sendToSingle(event.getSn(), json.toString());
log
.
info
(
"【{}】:dify异步请求耗时--->:{}"
,
event
.
getSn
(),
System
.
currentTimeMillis
()
-
startTime
);
}
...
...
src/test/java/com/ikonke/konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
View file @
fdfce929
...
...
@@ -51,6 +51,34 @@ class KonkeAiAlibabaMcpApplicationTests {
// @Test
// void test() {
// String ai_result = "{\"msg\":\"{\"msg\":\"{\"msg\":\"中行游泳馆830目前无法获取详细信息,可能已下架或不存在。您可以尝试其他可预约的共享空间,如健身房或茶室。如需进一步帮助,请告知具体需求。\",\"type\":\"cdc\"}\",\"type\":\"cdc\"}\",\"type\":\"cdc\"}";
//
// ai_result = ai_result.replaceAll("\n", "##").trim();
//
// JSONObject json = new JSONObject();
// if(!JSONUtil.isTypeJSON(ai_result)){
// json.put("msg", ai_result);
// json.put("type", "other");
// }else{
// json = JSONUtil.parseObj(ai_result);
// if(json.containsKey("msg")){
// String msg = json.getStr("msg");
// if(JSONUtil.isTypeJSON(msg)){
// JSONObject msgJson = JSONUtil.parseObj(msg);
// if(msgJson.containsKey("type") && msgJson.containsKey("msg")){
// ai_result = msg;
// }
// }
// }
// if(!json.containsKey("type")){
// json.put("type", "other");
// }
// }
//
// System.out.println("----->"+ 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