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
c8acc664
Commit
c8acc664
authored
Aug 27, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备控制与场景
parent
08cd8d80
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
315 additions
and
187 deletions
+315
-187
src/main/java/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
...ava/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
+25
-0
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
...java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
+13
-0
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisKeyExpireListener.java
...onke/konkeaialibabamcp/config/RedisKeyExpireListener.java
+28
-0
src/main/java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
...java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
+2
-0
src/main/java/com/ikonke/konkeaialibabamcp/service/SycDeviceService.java
...om/ikonke/konkeaialibabamcp/service/SycDeviceService.java
+18
-0
src/main/java/com/ikonke/konkeaialibabamcp/service/mongdbservice/DeviceStatusService.java
...alibabamcp/service/mongdbservice/DeviceStatusService.java
+6
-0
src/main/java/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
...ava/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
+206
-157
src/main/resources/application-prod.yml
src/main/resources/application-prod.yml
+0
-13
src/main/resources/application-test.yml
src/main/resources/application-test.yml
+0
-13
src/main/resources/application.yml
src/main/resources/application.yml
+17
-4
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
View file @
c8acc664
...
...
@@ -53,6 +53,31 @@ public class DeviceTools {
return
konkeIotServer
.
optDeviceClosed
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
);
}
@Tool
(
description
=
"根据主机号和设备ID控制:设置亮度"
)
public
String
setBrightness
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"设置的亮度百分比大小,范围是0-100"
)
int
brightness
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制设备亮度....ccuName:{},devId:{},type:{},brightness:{}"
,
ccuName
,
devId
,
typeId
,
brightness
);
return
konkeIotServer
.
setBrightness
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
brightness
);
}
@Tool
(
description
=
"根据主机号和设备ID控制:设置色温"
)
public
String
setColourTemperature
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"设置的色温百分比大小,范围是0-100"
)
int
colourTemperature
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制设备的色温....ccuName:{},devId:{},type:{},colourTemperature:{}"
,
ccuName
,
devId
,
typeId
,
colourTemperature
);
return
konkeIotServer
.
setColourTemperature
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
colourTemperature
);
}
@Tool
(
description
=
"根据主机号和设备ID控制:设置显示的颜色"
)
public
String
setColor
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"要设置的颜色,支持的颜色:Red,Yellow,Blue,Green,White,Black,Cyan,Purple,Orange,Pink,Violet,Magenta,Indigo,SlateBlue,DarkBlue,SkyBlue,DarkCyan,Beige,Brown"
)
String
color
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制设备的颜色....ccuName:{},devId:{},type:{},color:{}"
,
ccuName
,
devId
,
typeId
,
color
);
return
konkeIotServer
.
setColor
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
color
);
}
@Tool
(
description
=
"根据主机号和设备ID控制:暂停设备.只支持窗帘类型"
)
public
String
setPause
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
...
...
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisConfig.java
View file @
c8acc664
...
...
@@ -4,6 +4,7 @@ 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.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
...
...
@@ -18,4 +19,16 @@ public class RedisConfig {
template
.
setValueSerializer
(
new
Jackson2JsonRedisSerializer
<>(
Object
.
class
));
return
template
;
}
@Bean
public
RedisMessageListenerContainer
redisMessageListenerContainer
(
RedisConnectionFactory
factory
)
{
RedisMessageListenerContainer
container
=
new
RedisMessageListenerContainer
();
container
.
setConnectionFactory
(
factory
);
// container.setTaskExecutor(null); // 设置用于执行监听器方法的 Executor
// container.setErrorHandler(null); // 设置监听器方法执行过程中出现异常的处理器
// container.addMessageListener(null, null); // 手动设置监听器 & 监听的 topic 表达式
return
container
;
}
}
src/main/java/com/ikonke/konkeaialibabamcp/config/RedisKeyExpireListener.java
0 → 100644
View file @
c8acc664
package
com.ikonke.konkeaialibabamcp.config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.connection.Message
;
import
org.springframework.data.redis.listener.KeyExpirationEventMessageListener
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.stereotype.Component
;
@Slf4j
@Component
public
class
RedisKeyExpireListener
extends
KeyExpirationEventMessageListener
{
public
RedisKeyExpireListener
(
RedisMessageListenerContainer
listenerContainer
)
{
super
(
listenerContainer
);
}
@Override
public
void
doHandleMessage
(
Message
message
)
{
// 过期的 key
byte
[]
body
=
message
.
getBody
();
// 消息通道
byte
[]
channel
=
message
.
getChannel
();
log
.
info
(
"redis 过期 ------> message = {}, channel = {}"
,
new
String
(
body
),
new
String
(
channel
));
}
}
src/main/java/com/ikonke/konkeaialibabamcp/constant/RedisKeys.java
View file @
c8acc664
...
...
@@ -6,4 +6,6 @@ public class RedisKeys {
// key--> konke:cdc:mac:add_temporary_scene:scene_id value-->
public
static
final
String
ADD_TEMPORARY_SCENE
=
"add_temporary_scene"
;
// 临时场景的存活时间 5分钟
public
static
final
int
TEMPORARY_SCENE_TIME
=
60
*
5
;
//TimeUnit.SECONDS
}
src/main/java/com/ikonke/konkeaialibabamcp/service/SycDeviceService.java
View file @
c8acc664
...
...
@@ -87,6 +87,9 @@ public class SycDeviceService {
public
boolean
synchronousDevice
(
String
ccuName
)
{
log
.
info
(
"synchronousDevice..同步设备..ccuName:{}"
,
ccuName
);
if
(
StrUtil
.
isBlank
(
ccuName
)){
throw
new
StatefulException
(-
20
,
"参数不能为空"
);
}
//查询房间信息
Query
regionQuery
=
new
Query
(
Criteria
.
where
(
"ccuName"
).
is
(
ccuName
));
...
...
@@ -204,4 +207,19 @@ public class SycDeviceService {
return
"UNKNOWN"
;
}
public
DeviceModel
getDeviceModel
(
Integer
oid
){
String
deviceModel_json_str
=
device_model_cache
.
get
(
String
.
valueOf
(
oid
));
if
(
StrUtil
.
isBlank
(
deviceModel_json_str
)){
QueryWrapper
<
DeviceModel
>
deviceModel_wrapper
=
new
QueryWrapper
<>();
deviceModel_wrapper
.
eq
(
"operateId"
,
oid
);
List
<
DeviceModel
>
model_list
=
deviceModelService
.
list
(
deviceModel_wrapper
);
if
(!
model_list
.
isEmpty
()){
return
model_list
.
get
(
0
);
}
}
else
{
return
JSONUtil
.
toBean
(
deviceModel_json_str
,
DeviceModel
.
class
);
}
return
null
;
}
}
src/main/java/com/ikonke/konkeaialibabamcp/service/mongdbservice/DeviceStatusService.java
View file @
c8acc664
package
com.ikonke.konkeaialibabamcp.service.mongdbservice
;
import
cn.hutool.core.exceptions.StatefulException
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.ikonke.konkeaialibabamcp.entity.mongodb.Device
;
import
com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus
;
...
...
@@ -29,6 +31,10 @@ public class DeviceStatusService {
public
DeviceStatus
findUserByUserId
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
Integer
devId
)
{
log
.
info
(
"DeviceStatusUtil:findUserByUserId....ccuName:{},devId:{}"
,
ccuName
,
devId
);
if
(
StrUtil
.
isBlank
(
ccuName
)
||
devId
==
null
){
throw
new
StatefulException
(-
20
,
"参数不能为空"
);
}
return
mongoTemplate
.
findOne
(
Query
.
query
(
Criteria
.
where
(
"ccuName"
).
is
(
ccuName
)
.
and
(
"devId"
).
is
(
devId
)
...
...
src/main/java/com/ikonke/konkeaialibabamcp/utils/KonkeIotUtils.java
View file @
c8acc664
This diff is collapsed.
Click to expand it.
src/main/resources/application-prod.yml
View file @
c8acc664
...
...
@@ -21,19 +21,6 @@ spring:
max-redirects
:
3
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:7103
ai
:
mcp
:
server
:
name
:
konke-ai-alibaba-mcp-server
version
:
0.0.1
type
:
ASYNC
# Recommended for reactive applications
sse-endpoint
:
/sse
sse-message-endpoint
:
/mcp
capabilities
:
tool
:
true
resource
:
true
prompt
:
true
completion
:
true
mybatis-plus
:
mapper-locations
:
classpath*:/mapper/**/*.xml
...
...
src/main/resources/application-test.yml
View file @
c8acc664
...
...
@@ -21,19 +21,6 @@ spring:
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
:
name
:
konke-ai-alibaba-mcp-server
version
:
0.0.1
type
:
ASYNC
# Recommended for reactive applications
sse-endpoint
:
/sse
sse-message-endpoint
:
/mcp
capabilities
:
tool
:
true
resource
:
true
prompt
:
true
completion
:
true
mybatis-plus
:
mapper-locations
:
classpath*:/mapper/**/*.xml
...
...
src/main/resources/application.yml
View file @
c8acc664
spring
:
profiles
:
active
:
prod
server
:
address
:
0.0.0.0
port
:
9998
spring
:
profiles
:
active
:
prod
ai
:
mcp
:
server
:
name
:
konke-ai-alibaba-mcp-server
version
:
0.0.1
type
:
ASYNC
# Recommended for reactive applications
sse-endpoint
:
/sse
sse-message-endpoint
:
/mcp
capabilities
:
tool
:
true
resource
:
true
prompt
:
true
completion
:
true
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