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
08cd8d80
Commit
08cd8d80
authored
Aug 26, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
场景推荐 1
parent
b12b1cae
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
153 additions
and
36 deletions
+153
-36
src/main/java/com/ikonke/konkeaialibabamcp/aitools/SceneRecommendTools.java
...ikonke/konkeaialibabamcp/aitools/SceneRecommendTools.java
+21
-0
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
...java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
+21
-0
src/main/java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
...java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
+9
-0
src/main/java/com/ikonke/konkeaialibabamcp/controller/DeviceController.java
...ikonke/konkeaialibabamcp/controller/DeviceController.java
+17
-4
src/main/java/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
...ava/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
+63
-31
src/main/java/com/ikonke/konkeaialibabamcp/utils/RedisCacheUtil.java
...va/com/ikonke/konkeaialibabamcp/utils/RedisCacheUtil.java
+3
-0
src/main/resources/application-prod.yml
src/main/resources/application-prod.yml
+1
-1
src/main/resources/application-test.yml
src/main/resources/application-test.yml
+12
-0
提示词.md
提示词.md
+6
-0
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/aitools/SceneRecommendTools.java
0 → 100644
View file @
08cd8d80
package
com.ikonke.konkeaialibabamcp.aitools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
SceneRecommendTools
{
private
final
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
SceneRecommendTools
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
redisTemplate
=
redisTemplate
;
}
//删除场景,会定时删除Redis中的临时场景
//保存场景,将Redis中的临时场景删除即可
}
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
0 → 100644
View file @
08cd8d80
package
com.ikonke.konkeaialibabamcp.config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
public
class
RedisConfig
{
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
template
.
setConnectionFactory
(
redisConnectionFactory
);
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setValueSerializer
(
new
Jackson2JsonRedisSerializer
<>(
Object
.
class
));
return
template
;
}
}
src/main/java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
0 → 100644
View file @
08cd8d80
package
com.ikonke.konkeaialibabamcp.constant
;
public
class
RedisKeys
{
public
static
final
String
KONKE_CDC
=
"konke:cdc:"
;
// key--> konke:cdc:mac:add_temporary_scene:scene_id value-->
public
static
final
String
ADD_TEMPORARY_SCENE
=
"add_temporary_scene"
;
}
src/main/java/com/ikonke/konkeaialibabamcp/controller/DeviceController.java
View file @
08cd8d80
package
com.ikonke.konkeaialibabamcp.controller
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
com.ikonke.konkeaialibabamcp.constant.RedisKeys
;
import
com.ikonke.konkeaialibabamcp.service.SycDeviceService
;
import
com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -15,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping
(
"/deviceController"
)
public
class
DeviceController
{
@Autowired
private
SycDeviceService
sycDeviceService
;
@Autowired
...
...
@@ -40,10 +42,21 @@ public class DeviceController {
@PostMapping
(
"/addScene"
)
public
String
addScene
(
@RequestParam
(
value
=
"ccuName"
)
String
ccuName
,
public
String
addScene
(
@RequestHeader
(
"temporarySceneId"
)
String
temporarySceneId
,
@RequestHeader
(
"sn"
)
String
sn
,
@RequestParam
(
value
=
"ccuName"
)
String
ccuName
,
@RequestBody
JSONObject
actions
)
{
log
.
info
(
"addScene..新增场景..ccuName:{},actions:{}"
,
ccuName
,
actions
);
return
konkeIotServer
.
addScene
(
ccuName
,
actions
);
log
.
info
(
"addScene..新增场景..ccuName:{},temporarySceneId:{},sn:{},actions:{}"
,
ccuName
,
temporarySceneId
,
sn
,
actions
);
konkeIotServer
.
delScene
(
sn
,
ccuName
,
temporarySceneId
);
return
konkeIotServer
.
addScene
(
sn
,
ccuName
,
actions
);
}
@DeleteMapping
(
"/delScene"
)
public
Boolean
delScene
(
@RequestHeader
(
"temporarySceneId"
)
String
temporarySceneId
,
@RequestHeader
(
"sn"
)
String
sn
,
@RequestParam
(
value
=
"ccuName"
)
String
ccuName
)
{
log
.
info
(
"addScene..删除场景..ccuName:{},temporarySceneId:{},sn:{}"
,
ccuName
,
temporarySceneId
,
sn
);
return
konkeIotServer
.
delScene
(
sn
,
ccuName
,
temporarySceneId
);
}
...
...
src/main/java/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
View file @
08cd8d80
package
com.ikonke.konkeaialibabamcp.utils
;
import
cn.hutool.core.exceptions.StatefulException
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.ikonke.konkeaialibabamcp.constant.DeviceConstant
;
import
com.ikonke.konkeaialibabamcp.constant.RedisKeys
;
import
com.ikonke.konkeaialibabamcp.controller.param.AddSceneParam
;
import
com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus
;
import
com.ikonke.konkeaialibabamcp.service.SycDeviceService
;
...
...
@@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
...
...
@@ -22,6 +25,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
@Slf4j
@Component
...
...
@@ -39,10 +43,12 @@ public class KonkeIotUtils {
private
final
MongoTemplate
mongoTemplate
;
private
final
SycDeviceService
sycDeviceService
;
private
final
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
KonkeIotUtils
(
MongoTemplate
mongoTemplate
,
SycDeviceService
sycDeviceService
)
{
public
KonkeIotUtils
(
MongoTemplate
mongoTemplate
,
SycDeviceService
sycDeviceService
,
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
mongoTemplate
=
mongoTemplate
;
this
.
sycDeviceService
=
sycDeviceService
;
this
.
redisTemplate
=
redisTemplate
;
}
public
final
static
Map
<
String
,
String
>
actionMap
=
Map
.
of
(
...
...
@@ -518,7 +524,15 @@ public class KonkeIotUtils {
/**
* 删除场景
*/
public
Boolean
delScene
(
String
ccuName
,
String
sceneId
){
public
Boolean
delScene
(
String
sn
,
String
ccuName
,
String
sceneId
){
if
(
StrUtil
.
isBlank
(
sn
)
||
StrUtil
.
isBlank
(
ccuName
)
||
StrUtil
.
isBlank
(
sceneId
)){
return
false
;
}
log
.
info
(
"delScene....sn:{},ccuName:{},sceneId:{}"
,
sn
,
ccuName
,
sceneId
);
String
redisKey
=
RedisKeys
.
KONKE_CDC
+
sn
+
":"
+
RedisKeys
.
ADD_TEMPORARY_SCENE
+
":"
+
sceneId
;
redisTemplate
.
delete
(
redisKey
);
String
url
=
baseUrl
+
"/2.0/ccu/"
+
ccuName
+
"/scene/"
+
sceneId
;
String
body
=
HttpRequest
.
delete
(
url
)
.
header
(
"appId"
,
appId
)
...
...
@@ -551,39 +565,51 @@ public class KonkeIotUtils {
*
* 5、这个场景应该是一个临时场景,若用户没有说保存,应该删除掉
*/
public
String
addScene
(
String
ccuName
,
JSONObject
scene
){
AddSceneParam
bean
=
JSONUtil
.
toBean
(
scene
,
AddSceneParam
.
class
);
public
String
addScene
(
String
sn
,
String
ccuName
,
JSONObject
scene
){
try
{
AddSceneParam
bean
=
JSONUtil
.
toBean
(
scene
,
AddSceneParam
.
class
);
JSONObject
body
=
new
JSONObject
();
body
.
set
(
"name"
,
bean
.
getName
());
body
.
set
(
"roomId"
,
bean
.
getRoomId
());
JSONArray
actions
=
new
JSONArray
();
for
(
AddSceneParam
.
SceneAction
action
:
bean
.
getActions
())
{
JSONObject
body_action
=
new
JSONObject
();
body_action
.
set
(
"id"
,
action
.
getDevId
());
body_action
.
set
(
"realType"
,
sycDeviceService
.
getDeviceRealType
(
Integer
.
valueOf
(
action
.
getTypeId
())));
body_action
.
set
(
"delay"
,
0
);
body_action
.
set
(
"operation"
,
this
.
getSceneAction
(
action
.
getOperation
()));
actions
.
set
(
body_action
);
}
JSONObject
body
=
new
JSONObject
();
body
.
set
(
"name"
,
bean
.
getName
());
body
.
set
(
"roomId"
,
bean
.
getRoomId
());
body
.
set
(
"actions"
,
actions
);
JSONArray
actions
=
new
JSONArray
();
for
(
AddSceneParam
.
SceneAction
action
:
bean
.
getActions
())
{
JSONObject
body_action
=
new
JSONObject
();
body_action
.
set
(
"id"
,
action
.
getDevId
());
body_action
.
set
(
"realType"
,
sycDeviceService
.
getDeviceRealType
(
Integer
.
valueOf
(
action
.
getTypeId
())));
body_action
.
set
(
"delay"
,
0
);
body_action
.
set
(
"operation"
,
this
.
getSceneAction
(
action
.
getOperation
()));
}
String
url
=
baseUrl
+
"/2.0/ccu/"
+
ccuName
+
"/scenes"
;
log
.
info
(
"addScene..新增场景..ccuName:{},scene:{}"
,
ccuName
,
body
.
toString
());
String
result
=
HttpRequest
.
post
(
url
)
.
header
(
"appId"
,
appId
)
.
header
(
"appKey"
,
appKey
)
.
body
(
body
.
toString
())
.
execute
().
body
();
body
.
set
(
"actions"
,
actions
);
log
.
info
(
"addScene..新增场景..result:{}"
,
result
);
JSONObject
response
=
JSONUtil
.
parseObj
(
result
);
if
(!
response
.
getBool
(
"success"
)){
throw
new
StatefulException
(-
1
,
response
.
getStr
(
"message"
));
}
else
{
Integer
scene_id
=
response
.
getInt
(
"data"
);
String
url
=
baseUrl
+
"/2.0/ccu/"
+
ccuName
+
"/scenes"
;
log
.
info
(
"addScene..新增场景..ccuName:{},scene:{}"
,
ccuName
,
scene
.
toString
());
String
result
=
HttpRequest
.
post
(
url
)
.
header
(
"appId"
,
appId
)
.
header
(
"appKey"
,
appKey
)
.
body
(
body
.
toString
())
.
execute
().
body
();
String
redisKey
=
RedisKeys
.
KONKE_CDC
+
sn
+
":"
+
RedisKeys
.
ADD_TEMPORARY_SCENE
+
":"
+
scene_id
;
redisTemplate
.
opsForValue
().
set
(
redisKey
,
JSONUtil
.
toJsonStr
(
body
),
5
*
60
,
TimeUnit
.
SECONDS
);
log
.
info
(
"addScene..新增场景..result:{}"
,
result
);
JSONObject
response
=
JSONUtil
.
parseObj
(
result
);
if
(!
response
.
getBool
(
"success"
)){
throw
new
StatefulException
(-
1
,
response
.
getStr
(
"message"
));
}
else
{
log
.
info
(
"addScene..新增场景..result:{}"
,
response
.
getStr
(
"data"
));
return
response
.
getStr
(
"data"
);
log
.
info
(
"addScene..新增场景..result:{}"
,
scene_id
);
return
scene_id
+
""
;
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
throw
new
StatefulException
(-
20
,
"新增临时场景失败"
);
}
}
...
...
@@ -598,7 +624,13 @@ public class KonkeIotUtils {
Object
firstValue
=
firstEntry
.
getValue
();
if
(
"on"
.
equalsIgnoreCase
(
firstKey
)){
return
firstValue
;
if
(
"false"
.
equalsIgnoreCase
(
firstValue
.
toString
())){
return
"OFF"
;
}
else
if
(
"true"
.
equalsIgnoreCase
(
firstValue
.
toString
())){
return
"ON"
;
}
else
{
return
firstValue
;
}
}
else
{
log
.
error
(
"不支持的操作1:{}"
,
JSONUtil
.
toJsonStr
(
operation
));
}
...
...
src/main/java/com/ikonke/konkeaialibabamcp/utils/RedisCacheUtil.java
View file @
08cd8d80
...
...
@@ -5,6 +5,9 @@ import org.springframework.stereotype.Component;
import
java.util.concurrent.TimeUnit
;
/**
*
*/
@Component
public
class
RedisCacheUtil
{
...
...
src/main/resources/application-prod.yml
View file @
08cd8d80
...
...
@@ -19,7 +19,7 @@ spring:
min-idle
:
0
# 连接池中的最小空闲连接
cluster
:
max-redirects
:
3
nodes
:
172.
17.14.1:7001,172.17.14.1:7002,172.17.14.1:7003,172.17.14.2:7001,172.17.14.2:7002,172.17.14.2:70
03
nodes
:
172.
24.70.175:7101,172.24.70.175:7102,172.24.70.175:7103,172.24.70.176:7101,172.24.70.176:7102,172.24.70.176:71
03
ai
:
mcp
:
...
...
src/main/resources/application-test.yml
View file @
08cd8d80
...
...
@@ -9,6 +9,18 @@ spring:
data
:
mongodb
:
uri
:
mongodb://user002:konke2025@172.17.13.1:27017,172.17.13.2:27017,172.17.13.3:27017/konke_iot?authSource=konke_iot&authMechanism=SCRAM-SHA-1
redis
:
password
:
kknjredis
lettuce
:
pool
:
max-active
:
8
# 连接池中的最大空闲连接
max-wait
:
500
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle
:
8
# 连接池最大连接数(使用负值表示没有限制)
min-idle
:
0
# 连接池中的最小空闲连接
cluster
:
max-redirects
:
3
nodes
:
172.17.14.1:7001,172.17.14.1:7002,172.17.14.1:7003,172.17.14.2:7001,172.17.14.2:7002,172.17.14.2:7003
ai
:
mcp
:
server
:
...
...
提示词.md
View file @
08cd8d80
...
...
@@ -44,3 +44,9 @@
## 示例引导:
用户输入:"帮我预约下午2点到4点的茶室"
期望输出:"预约成功" 或 "预约失败" 或 "你要预约的场所没有抵扣券,暂不支持AI购买,请手动购买"
##
2、当用户提出试用推荐的场景时,你需要根据获取到的临时场景ID{{#conversation.temporarySceneId#}}与家庭下的主机号,再调用mcp函数triggerScene来触发场景。
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