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
1027c09e
Commit
1027c09e
authored
Sep 18, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
建发接口优化 2
parent
6870a890
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
283 additions
and
169 deletions
+283
-169
src/main/java/com/ikonke/konkeaialibabamcp/aitools/CDCVisitorTools.java
...com/ikonke/konkeaialibabamcp/aitools/CDCVisitorTools.java
+5
-5
src/main/java/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
...ava/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
+151
-151
src/main/java/com/ikonke/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
...e/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
+25
-13
src/main/java/com/ikonke/konkeaialibabamcp/utils/TimeSlotMerger.java
...va/com/ikonke/konkeaialibabamcp/utils/TimeSlotMerger.java
+102
-0
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/aitools/CDCVisitorTools.java
View file @
1027c09e
...
...
@@ -6,8 +6,8 @@ import org.springframework.stereotype.Service;
/**
* 访客相关
*/
@Slf4j
@Service
public
class
CDCVisitorTools
{
}
//
@Slf4j
//
@Service
//
public class CDCVisitorTools {
//
//
}
src/main/java/com/ikonke/konkeaialibabamcp/aitools/DeviceTools.java
View file @
1027c09e
package
com.ikonke.konkeaialibabamcp.aitools
;
import
com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus
;
import
com.ikonke.konkeaialibabamcp.service.SycDeviceService
;
import
com.ikonke.konkeaialibabamcp.service.mongdbservice.DeviceStatusService
;
import
com.ikonke.konkeaialibabamcp.utils.CcuUtils
;
import
com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.ai.tool.annotation.Tool
;
import
org.springframework.ai.tool.annotation.ToolParam
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
DeviceTools
{
private
final
DeviceStatusService
deviceStatusUtil
;
private
final
KonkeIotUtils
konkeIotServer
;
private
final
SycDeviceService
sycDeviceService
;
public
DeviceTools
(
DeviceStatusService
deviceStatusUtil
,
KonkeIotUtils
konkeIotServer
,
SycDeviceService
sycDeviceService
){
this
.
deviceStatusUtil
=
deviceStatusUtil
;
this
.
konkeIotServer
=
konkeIotServer
;
this
.
sycDeviceService
=
sycDeviceService
;
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID查询设备状态信息."
)
public
DeviceStatus
findDeviceState
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
Integer
devId
)
{
log
.
info
(
"mcp调用--->根据主机号和设备ID查询设备状态信息....ccuName:{},devId:{}"
,
ccuName
,
devId
);
return
deviceStatusUtil
.
findUserByUserId
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
);
}
@Tool
(
description
=
"智能家居相关:根据主机号同步设备"
)
public
boolean
synchronousDevice
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
){
log
.
info
(
"mcp调用--->根据主机号同步设备....ccuName:{}"
,
ccuName
);
return
sycDeviceService
.
synchronousDevice
(
CcuUtils
.
getCcuName
(
ccuName
));
}
//==============================设备控制=============================================
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID控制:打开设备"
)
public
String
optDeviceOpen
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制打开设备....ccuName:{},devId:{},type:{}"
,
ccuName
,
devId
,
typeId
);
return
konkeIotServer
.
optDeviceOpen
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和多个设备ID批量控制:打开设备"
)
public
String
batchOptDeviceOpen
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID,多个使用逗号隔开"
)
String
devIds
){
log
.
info
(
"mcp调用--->根据主机号和多个设备ID与设备类型ID批量控制....ccuName:{},devIds:{}"
,
ccuName
,
devIds
);
return
konkeIotServer
.
batchOptDeviceOpen
(
CcuUtils
.
getCcuName
(
ccuName
),
devIds
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID控制:关闭设备"
)
public
String
optDeviceClosed
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制关闭设备....ccuName:{},devId:{},type:{}"
,
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控制:暂停设备.只支持窗帘类型"
)
public
String
setPause
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制暂停设备....ccuName:{},devId:{},type:{}"
,
ccuName
,
devId
,
typeId
);
return
konkeIotServer
.
setPause
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID控制设备:移动位置.只支持窗帘电机(CURTAIN_MOTOR)类型"
)
public
String
setMove
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"移动的距离,范围是0-100"
)
int
progress
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制其移动位置....ccuName:{},devId:{},type:{},progress:{}"
,
ccuName
,
devId
,
typeId
,
progress
);
return
konkeIotServer
.
setMove
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
progress
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID控制设备:延时关机.只支持新风、地暖、空调"
)
public
String
setDelayedShutdown
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"多少分钟后关机,范围30-1440,必须是30的倍数,最小是半小时"
)
int
delayTime
){
log
.
info
(
"mcp调用--->根据主机号和设备ID控制设备延时关机....ccuName:{},devId:{},type:{},delayTime:{}"
,
ccuName
,
devId
,
typeId
,
delayTime
);
return
konkeIotServer
.
setDelayedShutdown
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
delayTime
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID设置设备的工作温度.只支持空调、地暖"
)
public
String
setTemperature
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"设置的温度大小,范围是5-35"
)
double
temperature
){
log
.
info
(
"mcp调用--->根据主机号和设备ID设置设备的工作温度....ccuName:{},devId:{},type:{},temperature:{}"
,
ccuName
,
devId
,
typeId
,
temperature
);
return
konkeIotServer
.
setTemperature
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
temperature
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID设置设备的工作模式.只支持地暖、空调、新风"
)
public
String
setModel
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"设置的工作模式,枚举值:WIND、HOT、COLD、DEHUMIDIFICATION、AUTO、MANUAL"
)
String
mode
){
log
.
info
(
"mcp调用--->根据主机号和设备ID设置设备的工作模式....ccuName:{},devId:{},type:{},mode:{}"
,
ccuName
,
devId
,
typeId
,
mode
);
return
konkeIotServer
.
setModel
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
mode
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和设备ID设置设备的工作风速.只支持空调、新风"
)
public
String
setSpeed
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"设备ID"
)
String
devId
,
@ToolParam
(
description
=
"设备类型ID"
)
String
typeId
,
@ToolParam
(
description
=
"设置的工作风速,枚举值:LOW、MID、HIGH、AUTO、STOP"
)
String
speed
){
log
.
info
(
"mcp调用--->根据主机号和设备ID设置设备的工作风速....ccuName:{},devId:{},type:{},mode:{}"
,
ccuName
,
devId
,
typeId
,
speed
);
return
konkeIotServer
.
setSpeed
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
,
typeId
,
speed
);
}
@Tool
(
description
=
"智能家居相关:根据主机号和场景ID:触发场景"
)
public
String
triggerScene
(
@ToolParam
(
description
=
"主机号"
)
String
ccuName
,
@ToolParam
(
description
=
"场景ID"
)
String
devId
,
@ToolParam
(
description
=
"场景类型ID,type等于scene"
)
String
typeId
){
log
.
info
(
"mcp调用--->根据主机号和场景ID触发场景....ccuName:{},devId:{},type:{}"
,
ccuName
,
devId
,
typeId
);
return
konkeIotServer
.
optScene
(
CcuUtils
.
getCcuName
(
ccuName
),
devId
);
}
//===================================================================================================
}
//
package com.ikonke.konkeaialibabamcp.aitools;
//
//
//
import com.ikonke.konkeaialibabamcp.entity.mongodb.DeviceStatus;
//
import com.ikonke.konkeaialibabamcp.service.SycDeviceService;
//
import com.ikonke.konkeaialibabamcp.service.mongdbservice.DeviceStatusService;
//
import com.ikonke.konkeaialibabamcp.utils.CcuUtils;
//
import com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils;
//
import lombok.extern.slf4j.Slf4j;
//
import org.springframework.ai.tool.annotation.Tool;
//
import org.springframework.ai.tool.annotation.ToolParam;
//
import org.springframework.stereotype.Service;
//
//
@Slf4j
//
@Service
//
public class DeviceTools {
//
//
private final DeviceStatusService deviceStatusUtil;
//
private final KonkeIotUtils konkeIotServer;
//
private final SycDeviceService sycDeviceService;
//
//
public DeviceTools(DeviceStatusService deviceStatusUtil, KonkeIotUtils konkeIotServer, SycDeviceService sycDeviceService){
//
this.deviceStatusUtil = deviceStatusUtil;
//
this.konkeIotServer = konkeIotServer;
//
this.sycDeviceService = sycDeviceService;
//
}
//
//
@Tool(description = "智能家居相关:根据主机号和设备ID查询设备状态信息.")
//
public DeviceStatus findDeviceState(@ToolParam(description = "主机号") String ccuName,
//
@ToolParam(description = "设备ID") Integer devId) {
//
log.info("mcp调用--->根据主机号和设备ID查询设备状态信息....ccuName:{},devId:{}",ccuName,devId);
//
return deviceStatusUtil.findUserByUserId(CcuUtils.getCcuName(ccuName), devId);
//
}
//
@Tool(description = "智能家居相关:根据主机号同步设备")
//
public boolean synchronousDevice(@ToolParam(description = "主机号")String ccuName){
//
log.info("mcp调用--->根据主机号同步设备....ccuName:{}",ccuName);
//
return sycDeviceService.synchronousDevice(CcuUtils.getCcuName(ccuName));
//
}
//
//
//==============================设备控制=============================================
//
@Tool(description = "智能家居相关:根据主机号和设备ID控制:打开设备")
//
public String optDeviceOpen(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId){
//
log.info("mcp调用--->根据主机号和设备ID控制打开设备....ccuName:{},devId:{},type:{}",ccuName,devId,typeId);
//
return konkeIotServer.optDeviceOpen(CcuUtils.getCcuName(ccuName), devId, typeId);
//
}
//
@Tool(description = "智能家居相关:根据主机号和多个设备ID批量控制:打开设备")
//
public String batchOptDeviceOpen(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID,多个使用逗号隔开")String devIds){
//
log.info("mcp调用--->根据主机号和多个设备ID与设备类型ID批量控制....ccuName:{},devIds:{}",ccuName,devIds);
//
return konkeIotServer.batchOptDeviceOpen(CcuUtils.getCcuName(ccuName), devIds);
//
}
//
@Tool(description = "智能家居相关:根据主机号和设备ID控制:关闭设备")
//
public String optDeviceClosed(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId){
//
log.info("mcp调用--->根据主机号和设备ID控制关闭设备....ccuName:{},devId:{},type:{}",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控制:暂停设备.只支持窗帘类型")
//
public String setPause(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId){
//
log.info("mcp调用--->根据主机号和设备ID控制暂停设备....ccuName:{},devId:{},type:{}",ccuName,devId,typeId);
//
return konkeIotServer.setPause(CcuUtils.getCcuName(ccuName), devId, typeId);
//
}
//
@Tool(description = "智能家居相关:根据主机号和设备ID控制设备:移动位置.只支持窗帘电机(CURTAIN_MOTOR)类型")
//
public String setMove(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId,
//
@ToolParam(description = "移动的距离,范围是0-100")int progress){
//
log.info("mcp调用--->根据主机号和设备ID控制其移动位置....ccuName:{},devId:{},type:{},progress:{}",ccuName,devId,typeId,progress);
//
return konkeIotServer.setMove(CcuUtils.getCcuName(ccuName), devId, typeId,progress);
//
}
//
//
@Tool(description = "智能家居相关:根据主机号和设备ID控制设备:延时关机.只支持新风、地暖、空调")
//
public String setDelayedShutdown(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId,
//
@ToolParam(description = "多少分钟后关机,范围30-1440,必须是30的倍数,最小是半小时")int delayTime){
//
log.info("mcp调用--->根据主机号和设备ID控制设备延时关机....ccuName:{},devId:{},type:{},delayTime:{}",ccuName,devId,typeId,delayTime);
//
return konkeIotServer.setDelayedShutdown(CcuUtils.getCcuName(ccuName), devId, typeId,delayTime);
//
}
//
//
@Tool(description = "智能家居相关:根据主机号和设备ID设置设备的工作温度.只支持空调、地暖")
//
public String setTemperature(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId,
//
@ToolParam(description = "设置的温度大小,范围是5-35")double temperature){
//
log.info("mcp调用--->根据主机号和设备ID设置设备的工作温度....ccuName:{},devId:{},type:{},temperature:{}",ccuName,devId,typeId,temperature);
//
return konkeIotServer.setTemperature(CcuUtils.getCcuName(ccuName), devId, typeId,temperature);
//
}
//
@Tool(description = "智能家居相关:根据主机号和设备ID设置设备的工作模式.只支持地暖、空调、新风")
//
public String setModel(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId,
//
@ToolParam(description = "设置的工作模式,枚举值:WIND、HOT、COLD、DEHUMIDIFICATION、AUTO、MANUAL")String mode){
//
log.info("mcp调用--->根据主机号和设备ID设置设备的工作模式....ccuName:{},devId:{},type:{},mode:{}",ccuName,devId,typeId,mode);
//
return konkeIotServer.setModel(CcuUtils.getCcuName(ccuName), devId, typeId,mode);
//
}
//
//
@Tool(description = "智能家居相关:根据主机号和设备ID设置设备的工作风速.只支持空调、新风")
//
public String setSpeed(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "设备ID")String devId,
//
@ToolParam(description = "设备类型ID")String typeId,
//
@ToolParam(description = "设置的工作风速,枚举值:LOW、MID、HIGH、AUTO、STOP")String speed){
//
log.info("mcp调用--->根据主机号和设备ID设置设备的工作风速....ccuName:{},devId:{},type:{},mode:{}",ccuName,devId,typeId,speed);
//
return konkeIotServer.setSpeed(CcuUtils.getCcuName(ccuName), devId, typeId,speed);
//
}
//
//
//
//
@Tool(description = "智能家居相关:根据主机号和场景ID:触发场景")
//
public String triggerScene(@ToolParam(description = "主机号")String ccuName,
//
@ToolParam(description = "场景ID")String devId,
//
@ToolParam(description = "场景类型ID,type等于scene")String typeId){
//
log.info("mcp调用--->根据主机号和场景ID触发场景....ccuName:{},devId:{},type:{}",ccuName,devId,typeId);
//
return konkeIotServer.optScene(CcuUtils.getCcuName(ccuName), devId);
//
}
//
//
//===================================================================================================
//
//
//
}
src/main/java/com/ikonke/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
View file @
1027c09e
...
...
@@ -9,6 +9,7 @@ import cn.hutool.json.JSONObject;
import
cn.hutool.json.JSONUtil
;
import
com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils
;
import
com.ikonke.konkeaialibabamcp.utils.CDCUtils
;
import
com.ikonke.konkeaialibabamcp.utils.TimeSlotMerger
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -164,22 +165,33 @@ public class SpacesService {
}
}
JSONArray
response_time
=
new
JSONArray
();
for
(
int
j
=
timeSegmentIndex
;
j
<
48
;
j
++){
Integer
number
=
info
.
getInt
(
j
);
//0=不可预定 1=可预订 2=已被预定
JSONObject
jsonObject1
=
new
JSONObject
();
jsonObject1
.
set
(
"timeSegment"
,
CDCUtils
.
time_segment
[
j
]);
if
(
number
==
1
){
jsonObject1
.
set
(
"availability"
,
"可预订"
);
}
else
if
(
number
==
2
){
jsonObject1
.
set
(
"availability"
,
"已被预定"
);
// JSONArray response_time = new JSONArray();
// for( int j = timeSegmentIndex; j < 48; j++){
// Integer number = info.getInt(j);//0=不可预定 1=可预订 2=已被预定
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.set("timeSegment", CDCUtils.time_segment[j]);
//
// if(number == 1){
// jsonObject1.set("availability", "可预订");
// }else if(number == 2){
// jsonObject1.set("availability", "已被预定");
// }else{
// jsonObject1.set("availability", "不可预定");
// }
// response_time.set(jsonObject1);
// }
int
[]
intArray
=
new
int
[
info
.
size
()];
for
(
int
i
=
0
;
i
<
info
.
size
();
i
++)
{
if
(
i
<
timeSegmentIndex
){
intArray
[
i
]
=
0
;
}
else
{
jsonObject1
.
set
(
"availability"
,
"不可预定"
);
intArray
[
i
]
=
info
.
getInt
(
i
);
}
response_time
.
set
(
jsonObject1
);
}
response
.
set
(
"time"
,
response_time
);
List
<
TimeSlotMerger
.
MergedSlot
>
merged
=
TimeSlotMerger
.
mergeTimeSlots
(
intArray
);
response
.
set
(
"time"
,
merged
);
}
else
{
response
.
set
(
"time"
,
"不可预约"
);
}
...
...
src/main/java/com/ikonke/konkeaialibabamcp/utils/TimeSlotMerger.java
0 → 100644
View file @
1027c09e
package
com.ikonke.konkeaialibabamcp.utils
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
TimeSlotMerger
{
public
static
class
MergedSlot
{
private
String
start
;
private
String
end
;
private
String
available
;
public
MergedSlot
(
String
start
,
String
end
,
String
available
)
{
this
.
start
=
start
;
this
.
end
=
end
;
this
.
available
=
available
;
}
public
String
getStart
()
{
return
start
;
}
public
String
getEnd
()
{
return
end
;
}
public
String
getAvailable
()
{
return
available
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"%s-%s: %s"
,
start
,
end
,
available
);
}
}
/**
* 合并时间段的方法
* @param slots 包含48个元素的数组,每个元素为0或1
* @return 合并后的时间段列表
* @throws IllegalArgumentException 如果输入不符合要求
*/
public
static
List
<
MergedSlot
>
mergeTimeSlots
(
int
[]
slots
)
{
// 验证输入
if
(
slots
==
null
||
slots
.
length
!=
48
)
{
throw
new
IllegalArgumentException
(
"输入必须是包含48个元素的数组"
);
}
// for (int slot : slots) {
// if (slot != 0 && slot != 1) {
// throw new IllegalArgumentException("数组元素只能是0或1");
// }
// }
List
<
MergedSlot
>
mergedSlots
=
new
ArrayList
<>();
if
(
slots
.
length
==
0
)
{
return
mergedSlots
;
}
int
currentStatus
=
slots
[
0
];
int
startTimeIndex
=
0
;
// 遍历所有时间段
for
(
int
i
=
1
;
i
<
slots
.
length
;
i
++)
{
if
(
slots
[
i
]
!=
currentStatus
)
{
// 状态改变,记录上一个时间段
mergedSlots
.
add
(
new
MergedSlot
(
formatTime
(
startTimeIndex
),
formatTime
(
i
),
currentStatus
==
1
?
"可预约"
:
"不可预约"
));
// 更新当前状态和开始索引
currentStatus
=
slots
[
i
];
startTimeIndex
=
i
;
}
}
// 添加最后一个时间段
mergedSlots
.
add
(
new
MergedSlot
(
formatTime
(
startTimeIndex
),
formatTime
(
slots
.
length
),
currentStatus
==
1
?
"可预约"
:
"不可预约"
));
return
mergedSlots
;
}
/**
* 将时间段索引转换为时间字符串
* @param index 时间段索引(0-48)
* @return 格式化的时间字符串,如"00:00"
*/
private
static
String
formatTime
(
int
index
)
{
int
hours
=
index
/
2
;
int
minutes
=
(
index
%
2
)
*
30
;
// 格式化小时和分钟为两位数
return
String
.
format
(
"%02d:%02d"
,
hours
,
minutes
);
}
public
static
void
main
(
String
[]
args
)
{
int
[]
slots
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
2
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
};
List
<
MergedSlot
>
merged
=
mergeTimeSlots
(
slots
);
// 输出结果
for
(
MergedSlot
slot
:
merged
)
{
System
.
out
.
println
(
slot
);
}
}
}
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