Commit c8acc664 authored by 何金镒's avatar 何金镒

设备控制与场景

parent 08cd8d80
...@@ -53,6 +53,31 @@ public class DeviceTools { ...@@ -53,6 +53,31 @@ public class DeviceTools {
return konkeIotServer.optDeviceClosed(CcuUtils.getCcuName(ccuName), devId, typeId); 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控制:暂停设备.只支持窗帘类型") @Tool(description = "根据主机号和设备ID控制:暂停设备.只支持窗帘类型")
public String setPause(@ToolParam(description = "主机号")String ccuName, public String setPause(@ToolParam(description = "主机号")String ccuName,
@ToolParam(description = "设备ID")String devId, @ToolParam(description = "设备ID")String devId,
......
...@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean; ...@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; 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.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
...@@ -18,4 +19,16 @@ public class RedisConfig { ...@@ -18,4 +19,16 @@ public class RedisConfig {
template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class)); template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
return template; 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;
}
} }
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));
}
}
...@@ -6,4 +6,6 @@ public class RedisKeys { ...@@ -6,4 +6,6 @@ public class RedisKeys {
// key--> konke:cdc:mac:add_temporary_scene:scene_id value--> // key--> konke:cdc:mac:add_temporary_scene:scene_id value-->
public static final String ADD_TEMPORARY_SCENE = "add_temporary_scene"; public static final String ADD_TEMPORARY_SCENE = "add_temporary_scene";
// 临时场景的存活时间 5分钟
public static final int TEMPORARY_SCENE_TIME = 60 * 5;//TimeUnit.SECONDS
} }
...@@ -87,6 +87,9 @@ public class SycDeviceService { ...@@ -87,6 +87,9 @@ public class SycDeviceService {
public boolean synchronousDevice(String ccuName) { public boolean synchronousDevice(String ccuName) {
log.info("synchronousDevice..同步设备..ccuName:{}",ccuName); log.info("synchronousDevice..同步设备..ccuName:{}",ccuName);
if(StrUtil.isBlank(ccuName)){
throw new StatefulException(-20, "参数不能为空");
}
//查询房间信息 //查询房间信息
Query regionQuery = new Query(Criteria.where("ccuName").is(ccuName)); Query regionQuery = new Query(Criteria.where("ccuName").is(ccuName));
...@@ -204,4 +207,19 @@ public class SycDeviceService { ...@@ -204,4 +207,19 @@ public class SycDeviceService {
return "UNKNOWN"; 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;
}
} }
package com.ikonke.konkeaialibabamcp.service.mongdbservice; package com.ikonke.konkeaialibabamcp.service.mongdbservice;
import cn.hutool.core.exceptions.StatefulException;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.ikonke.konkeaialibabamcp.entity.mongodb.Device; import com.ikonke.konkeaialibabamcp.entity.mongodb.Device;
import com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus; import com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus;
...@@ -29,6 +31,10 @@ public class DeviceStatusService { ...@@ -29,6 +31,10 @@ public class DeviceStatusService {
public DeviceStatus findUserByUserId(@ToolParam(description = "主机号") String ccuName, public DeviceStatus findUserByUserId(@ToolParam(description = "主机号") String ccuName,
@ToolParam(description = "设备ID") Integer devId) { @ToolParam(description = "设备ID") Integer devId) {
log.info("DeviceStatusUtil:findUserByUserId....ccuName:{},devId:{}",ccuName,devId); log.info("DeviceStatusUtil:findUserByUserId....ccuName:{},devId:{}",ccuName,devId);
if(StrUtil.isBlank(ccuName) || devId == null){
throw new StatefulException(-20, "参数不能为空");
}
return mongoTemplate.findOne(Query.query( return mongoTemplate.findOne(Query.query(
Criteria.where("ccuName").is(ccuName) Criteria.where("ccuName").is(ccuName)
.and("devId").is(devId) .and("devId").is(devId)
......
...@@ -21,19 +21,6 @@ spring: ...@@ -21,19 +21,6 @@ spring:
max-redirects: 3 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 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: mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml mapper-locations: classpath*:/mapper/**/*.xml
......
...@@ -21,19 +21,6 @@ spring: ...@@ -21,19 +21,6 @@ spring:
max-redirects: 3 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 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: mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml mapper-locations: classpath*:/mapper/**/*.xml
......
spring:
profiles:
active: prod
server: server:
address: 0.0.0.0 address: 0.0.0.0
port: 9998 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment