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)
......
...@@ -10,6 +10,7 @@ import com.ikonke.konkeaialibabamcp.constant.DeviceConstant; ...@@ -10,6 +10,7 @@ import com.ikonke.konkeaialibabamcp.constant.DeviceConstant;
import com.ikonke.konkeaialibabamcp.constant.RedisKeys; import com.ikonke.konkeaialibabamcp.constant.RedisKeys;
import com.ikonke.konkeaialibabamcp.controller.param.AddSceneParam; import com.ikonke.konkeaialibabamcp.controller.param.AddSceneParam;
import com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus; import com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus;
import com.ikonke.konkeaialibabamcp.entity.mysql.DeviceModel;
import com.ikonke.konkeaialibabamcp.service.SycDeviceService; import com.ikonke.konkeaialibabamcp.service.SycDeviceService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -21,10 +22,8 @@ import org.springframework.stereotype.Component; ...@@ -21,10 +22,8 @@ import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
...@@ -69,64 +68,23 @@ public class KonkeIotUtils { ...@@ -69,64 +68,23 @@ public class KonkeIotUtils {
} }
public String optDeviceOpen(String ccuName, String devId,String operateId){ public String optDeviceOpen(String ccuName, String devId,String operateId){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
String action = null; String action = null;
switch (operateId) {
case "1": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
case "3": List<String> list = Arrays.asList(deviceModel.getActions().split(","));
case "4": if(list.contains("SwitchOpt")){
case "5":
case "7":
case "9":
case "10":
case "11":
case "12":
case "13":
case "14":
case "15":
case "17":
case "18":
case "201":
case "492":
case "493":
case "501":
case "502":
case "503":
case "504":
case "505":
case "506":
case "507":
case "508":
case "509":
case "510":
case "511":
case "513":
case "514":
case "515":
case "516":
case "517":
case "518":
case "519":
case "701":
case "2006":
case "15005":
case "12505":
action = "SwitchOpt"; action = "SwitchOpt";
break; }else if(list.contains("MotorOpt")){
case "1001":
case "1003":
case "1014":
action = "MotorOpt"; action = "MotorOpt";
break; }else if(list.contains("FreshAirSwitch")){
case "14003":
action = "FreshAirSwitch"; action = "FreshAirSwitch";
break;
default:
break;
} }
if(action == null){ if(action == null){
...@@ -143,63 +101,23 @@ public class KonkeIotUtils { ...@@ -143,63 +101,23 @@ public class KonkeIotUtils {
return optAIDevice(ccuName, devId, action,opt.toString()); return optAIDevice(ccuName, devId, action,opt.toString());
} }
public String optDeviceClosed(String ccuName, String devId,String operateId){ public String optDeviceClosed(String ccuName, String devId,String operateId){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
String action = null; String action = null;
switch (operateId) {
case "1": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
case "3": List<String> list = Arrays.asList(deviceModel.getActions().split(","));
case "4": if(list.contains("SwitchOpt")){
case "5":
case "7":
case "9":
case "10":
case "11":
case "12":
case "13":
case "14":
case "15":
case "17":
case "18":
case "201":
case "492":
case "493":
case "501":
case "502":
case "503":
case "504":
case "505":
case "506":
case "507":
case "508":
case "509":
case "510":
case "511":
case "513":
case "514":
case "515":
case "516":
case "517":
case "518":
case "519":
case "701":
case "2006":
case "15005":
case "12505":
action = "SwitchOpt"; action = "SwitchOpt";
break; }else if(list.contains("MotorOpt")){
case "1001":
case "1003":
case "1014":
action = "MotorOpt"; action = "MotorOpt";
break; }else if(list.contains("FreshAirSwitch")){
case "14003":
action = "FreshAirSwitch"; action = "FreshAirSwitch";
break;
default:
break;
} }
if(action == null){ if(action == null){
...@@ -218,23 +136,121 @@ public class KonkeIotUtils { ...@@ -218,23 +136,121 @@ public class KonkeIotUtils {
return optAIDevice(ccuName, devId, action,opt.toString()); return optAIDevice(ccuName, devId, action,opt.toString());
} }
/**
* 设置亮度
*/
public String setBrightness(String ccuName, String devId,String operateId,int brightness){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || brightness < 0 || brightness > 100){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线");
}
String action = null;
DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("DimmerAdjustLuminance")){
action = "DimmerAdjustLuminance";
}
if(action == null){
throw new StatefulException(-20, "暂不支持该操作");
}
JSONObject opt = new JSONObject();
if("DimmerAdjustLuminance".equals(action)){
opt.set("progress", brightness);
}else{
throw new StatefulException(-20, "暂不支持该操作");
}
return optAIDevice(ccuName, devId, action,opt.toString());
}
/**
* 设置色温
*/
public String setColourTemperature(String ccuName, String devId,String operateId,int colourTemperature){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || colourTemperature < 0 || colourTemperature > 100){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线");
}
String action = null;
DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("AdjustColourTemperature")){
action = "AdjustColourTemperature";
}
if(action == null){
throw new StatefulException(-20, "暂不支持该操作");
}
JSONObject opt = new JSONObject();
if("AdjustColourTemperature".equals(action)){
opt.set("progress", colourTemperature);
}else{
throw new StatefulException(-20, "暂不支持该操作");
}
return optAIDevice(ccuName, devId, action,opt.toString());
}
/**
* 设置颜色
*/
public String setColor(String ccuName, String devId,String operateId,String color){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线");
}
String action = null;
DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("DimmerAdjustColor")){
action = "DimmerAdjustColor";
}
if(action == null){
throw new StatefulException(-20, "暂不支持该操作");
}
JSONObject opt = new JSONObject();
if("DimmerAdjustColor".equals(action)){
Color c = ColorUtil.getColor(StrUtil.upperFirst(color.toLowerCase()));
int [] rgb = {c.getRed(),c.getGreen(),c.getBlue()};
opt.set("rgb", rgb);
}else{
throw new StatefulException(-20, "暂不支持该操作");
}
return optAIDevice(ccuName, devId, action,opt.toString());
}
/** /**
* 暂停-目前只有窗帘才支持暂停 * 暂停-目前只有窗帘才支持暂停
*/ */
public String setPause(String ccuName, String devId,String operateId){ public String setPause(String ccuName, String devId,String operateId){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
String action = null; String action = null;
switch (operateId) {
case "1001": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
case "1003": List<String> list = Arrays.asList(deviceModel.getActions().split(","));
case "1014": if(list.contains("MotorOpt")){
action = "MotorOpt"; action = "MotorOpt";
break;
default:
break;
} }
if(action == null){ if(action == null){
throw new StatefulException(-20, "暂不支持该操作"); throw new StatefulException(-20, "暂不支持该操作");
} }
...@@ -251,6 +267,9 @@ public class KonkeIotUtils { ...@@ -251,6 +267,9 @@ public class KonkeIotUtils {
* 移动位置-目前只有窗帘电机才支持移动位置 * 移动位置-目前只有窗帘电机才支持移动位置
*/ */
public String setMove(String ccuName, String devId,String operateId,int progress){ public String setMove(String ccuName, String devId,String operateId,int progress){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || (progress<0 || progress>100)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
...@@ -258,13 +277,13 @@ public class KonkeIotUtils { ...@@ -258,13 +277,13 @@ public class KonkeIotUtils {
throw new StatefulException(-31, "移动的位置只能是0到100"); throw new StatefulException(-31, "移动的位置只能是0到100");
} }
String action = null; String action = null;
switch (operateId) {
case "1003": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("DooyaMotorSeek")){
action = "DooyaMotorSeek"; action = "DooyaMotorSeek";
break;
default:
break;
} }
if(action == null){ if(action == null){
throw new StatefulException(-20, "暂不支持该操作"); throw new StatefulException(-20, "暂不支持该操作");
} }
...@@ -283,6 +302,9 @@ public class KonkeIotUtils { ...@@ -283,6 +302,9 @@ public class KonkeIotUtils {
* delayTime:分钟 最多24小时 * delayTime:分钟 最多24小时
*/ */
public String setDelayedShutdown(String ccuName, String devId,String operateId,int delayTime){ public String setDelayedShutdown(String ccuName, String devId,String operateId,int delayTime){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || (delayTime<0 || delayTime>24*60)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
...@@ -290,19 +312,17 @@ public class KonkeIotUtils { ...@@ -290,19 +312,17 @@ public class KonkeIotUtils {
throw new StatefulException(-31, "延时时间在0-24小时之间"); throw new StatefulException(-31, "延时时间在0-24小时之间");
} }
String action = null; String action = null;
switch (operateId) {
case "15005": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("FancoilSetDelaytask")){
action = "FancoilSetDelaytask"; action = "FancoilSetDelaytask";
break; }else if(list.contains("SetFloorheatingOffTime")){
case "12505":
action = "SetFloorheatingOffTime"; action = "SetFloorheatingOffTime";
break; }else if(list.contains("SetChopinFreshAirTimeOff")){
case "14003":
action = "SetChopinFreshAirTimeOff"; action = "SetChopinFreshAirTimeOff";
break;
default:
break;
} }
if(action == null){ if(action == null){
throw new StatefulException(-20, "暂不支持该操作"); throw new StatefulException(-20, "暂不支持该操作");
} }
...@@ -347,6 +367,9 @@ public class KonkeIotUtils { ...@@ -347,6 +367,9 @@ public class KonkeIotUtils {
* 设置温度 * 设置温度
*/ */
public String setTemperature(String ccuName, String devId,String operateId,double temperature){ public String setTemperature(String ccuName, String devId,String operateId,double temperature){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || (temperature<0 || temperature>35)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
...@@ -354,16 +377,15 @@ public class KonkeIotUtils { ...@@ -354,16 +377,15 @@ public class KonkeIotUtils {
throw new StatefulException(-31, "温度范围在5到35之间"); throw new StatefulException(-31, "温度范围在5到35之间");
} }
String action = null; String action = null;
switch (operateId) {
case "15005": DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("FancoilSetRunTemp")){
action = "FancoilSetRunTemp"; action = "FancoilSetRunTemp";
break; }else if(list.contains("SetFloorheatingWorkTemperature")){
case "12505":
action = "SetFloorheatingWorkTemperature"; action = "SetFloorheatingWorkTemperature";
break;
default:
break;
} }
if(action == null){ if(action == null){
throw new StatefulException(-20, "暂不支持该操作"); throw new StatefulException(-20, "暂不支持该操作");
} }
...@@ -385,25 +407,36 @@ public class KonkeIotUtils { ...@@ -385,25 +407,36 @@ public class KonkeIotUtils {
* 设置模式 * 设置模式
*/ */
public String setModel(String ccuName, String devId,String operateId,String mode){ public String setModel(String ccuName, String devId,String operateId,String mode){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || StrUtil.isBlank(mode)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
String action = null; String action = null;
DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("FancoilSetRunModel")){
action = "FancoilSetRunModel";
}else if(list.contains("SetFloorheatingWorkMode")){
action = "SetFloorheatingWorkMode";
}else if(list.contains("FreshAirSetRunModel")){
action = "FreshAirSetRunModel";
}
switch (operateId) { switch (operateId) {
case "15005"://空调 case "15005"://空调
action = "FancoilSetRunModel";//WIND HOT COLD DEHUMIDIFICATION
if(!DeviceConstant.mode_15005.contains(mode)){ if(!DeviceConstant.mode_15005.contains(mode)){
throw new StatefulException(-32, "不支持的模式"); throw new StatefulException(-32, "不支持的模式");
} }
break; break;
case "12505"://地暖 case "12505"://地暖
action = "SetFloorheatingWorkMode";//AUTO MANUAL
if(!DeviceConstant.mode_12505.contains(mode)){ if(!DeviceConstant.mode_12505.contains(mode)){
throw new StatefulException(-32, "不支持的模式"); throw new StatefulException(-32, "不支持的模式");
} }
break; break;
case "14003"://新风 case "14003"://新风
action = "FreshAirSetRunModel";//AUTO MANUAL
if(!DeviceConstant.mode_12505.contains(mode)){ if(!DeviceConstant.mode_12505.contains(mode)){
throw new StatefulException(-32, "不支持的模式"); throw new StatefulException(-32, "不支持的模式");
} }
...@@ -432,19 +465,29 @@ public class KonkeIotUtils { ...@@ -432,19 +465,29 @@ public class KonkeIotUtils {
* 设置风速 * 设置风速
*/ */
public String setSpeed(String ccuName, String devId,String operateId,String speed){ public String setSpeed(String ccuName, String devId,String operateId,String speed){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(devId) || StrUtil.isBlank(operateId) || StrUtil.isBlank(speed)){
throw new StatefulException(-20, "参数不能为空");
}
if (getDeviceOnline(ccuName, devId)) { if (getDeviceOnline(ccuName, devId)) {
throw new StatefulException(-30, "设备已离线"); throw new StatefulException(-30, "设备已离线");
} }
String action = null; String action = null;
DeviceModel deviceModel = sycDeviceService.getDeviceModel(Integer.valueOf(operateId));
List<String> list = Arrays.asList(deviceModel.getActions().split(","));
if(list.contains("FancoilSetFanSpeed")){
action = "FancoilSetFanSpeed";
}else if(list.contains("FreshAirSetSpeed")){
action = "FreshAirSetSpeed";
}
switch (operateId) { switch (operateId) {
case "15005"://空调 case "15005"://空调
action = "FancoilSetFanSpeed";//LOW MID HIGH AUTO
if(!DeviceConstant.speed_15005.contains(speed)){ if(!DeviceConstant.speed_15005.contains(speed)){
throw new StatefulException(-32, "不支持的风速"); throw new StatefulException(-32, "不支持的风速");
} }
break; break;
case "14003"://新风 case "14003"://新风
action = "FreshAirSetSpeed";//LOW MID HIGH STOP
if(!DeviceConstant.speed_12505.contains(speed)){ if(!DeviceConstant.speed_12505.contains(speed)){
throw new StatefulException(-32, "不支持的风速"); throw new StatefulException(-32, "不支持的风速");
} }
...@@ -487,6 +530,9 @@ public class KonkeIotUtils { ...@@ -487,6 +530,9 @@ public class KonkeIotUtils {
* 触发场景 * 触发场景
*/ */
public String optScene(String ccuName, String sceneId){ public String optScene(String ccuName, String sceneId){
if(StrUtil.isBlank(ccuName) || StrUtil.isBlank(sceneId)){
throw new StatefulException(-20, "参数不能为空");
}
String url = baseUrl + "/1.0/app/ccu/" + ccuName + "/dev/" + sceneId + "/opt"; String url = baseUrl + "/1.0/app/ccu/" + ccuName + "/dev/" + sceneId + "/opt";
log.info("KonkeIotServer optScene url {}, param {}, appId {}, appKey {}", url, "", appId, appKey); log.info("KonkeIotServer optScene url {}, param {}, appId {}, appKey {}", url, "", appId, appKey);
JSONObject opt = new JSONObject(); JSONObject opt = new JSONObject();
...@@ -528,9 +574,9 @@ public class KonkeIotUtils { ...@@ -528,9 +574,9 @@ public class KonkeIotUtils {
if(StrUtil.isBlank(sn) || StrUtil.isBlank(ccuName) || StrUtil.isBlank(sceneId)){ if(StrUtil.isBlank(sn) || StrUtil.isBlank(ccuName) || StrUtil.isBlank(sceneId)){
return false; return false;
} }
log.info("delScene....sn:{},ccuName:{},sceneId:{}",sn,ccuName,sceneId); log.info("delScene..删除场景..sn:{},ccuName:{},sceneId:{}",sn,ccuName,sceneId);
String redisKey = RedisKeys.KONKE_CDC + sn + ":" + RedisKeys.ADD_TEMPORARY_SCENE+ ":" +sceneId; String redisKey = RedisKeys.KONKE_CDC + ccuName + ":" + RedisKeys.ADD_TEMPORARY_SCENE+ ":" +sceneId;
redisTemplate.delete(redisKey); redisTemplate.delete(redisKey);
String url = baseUrl + "/2.0/ccu/" + ccuName + "/scene/" + sceneId; String url = baseUrl + "/2.0/ccu/" + ccuName + "/scene/" + sceneId;
...@@ -587,7 +633,7 @@ public class KonkeIotUtils { ...@@ -587,7 +633,7 @@ public class KonkeIotUtils {
body.set("actions", actions); body.set("actions", actions);
String url = baseUrl + "/2.0/ccu/" + ccuName + "/scenes"; String url = baseUrl + "/2.0/ccu/" + ccuName + "/scenes";
log.info("addScene..新增场景..ccuName:{},scene:{}",ccuName,body.toString()); log.info("addScene..新增场景..url:{},body:{}",url,body.toString());
String result = HttpRequest.post(url) String result = HttpRequest.post(url)
.header("appId", appId) .header("appId", appId)
.header("appKey", appKey) .header("appKey", appKey)
...@@ -601,7 +647,7 @@ public class KonkeIotUtils { ...@@ -601,7 +647,7 @@ public class KonkeIotUtils {
}else{ }else{
Integer scene_id = response.getInt("data"); Integer scene_id = response.getInt("data");
String redisKey = RedisKeys.KONKE_CDC + sn + ":" + RedisKeys.ADD_TEMPORARY_SCENE+ ":" +scene_id; String redisKey = RedisKeys.KONKE_CDC + ccuName + ":" + RedisKeys.ADD_TEMPORARY_SCENE+ ":" +scene_id;
redisTemplate.opsForValue().set(redisKey, JSONUtil.toJsonStr(body),5*60, TimeUnit.SECONDS); redisTemplate.opsForValue().set(redisKey, JSONUtil.toJsonStr(body),5*60, TimeUnit.SECONDS);
log.info("addScene..新增场景..result:{}",scene_id); log.info("addScene..新增场景..result:{}",scene_id);
...@@ -628,6 +674,12 @@ public class KonkeIotUtils { ...@@ -628,6 +674,12 @@ public class KonkeIotUtils {
return "OFF"; return "OFF";
}else if("true".equalsIgnoreCase(firstValue.toString())){ }else if("true".equalsIgnoreCase(firstValue.toString())){
return "ON"; return "ON";
}else if("STOP".equalsIgnoreCase(firstValue.toString())){
return "STOP";
}else if("CLOSE".equalsIgnoreCase(firstValue.toString())){
return "CLOSE";
}else if("OPEN".equalsIgnoreCase(firstValue.toString())){
return "OPEN";
}else{ }else{
return firstValue; return firstValue;
} }
...@@ -651,11 +703,8 @@ public class KonkeIotUtils { ...@@ -651,11 +703,8 @@ public class KonkeIotUtils {
jsonObject.set("white_bri", operation.get(key)); jsonObject.set("white_bri", operation.get(key));
}else if("rgb".equalsIgnoreCase(key)){ }else if("rgb".equalsIgnoreCase(key)){
Color c = ColorUtil.getColor((String) operation.get(key)); Color c = ColorUtil.getColor((String) operation.get(key));
Map<String,Object> rgbMap = new HashMap<>(); int [] rgb = {c.getRed(),c.getGreen(),c.getBlue()};
rgbMap.put("Red",c.getRed()); jsonObject.set("rgb", rgb);
rgbMap.put("Green",c.getGreen());
rgbMap.put("Blue",c.getBlue());
jsonObject.set("rgb", rgbMap);
}else if("speed".equalsIgnoreCase(key)){ }else if("speed".equalsIgnoreCase(key)){
jsonObject.set("speed", operation.get(key)); jsonObject.set("speed", operation.get(key));
}else if("runModel".equalsIgnoreCase(key)){ }else if("runModel".equalsIgnoreCase(key)){
......
...@@ -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