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
3d841dd5
Commit
3d841dd5
authored
Aug 13, 2025
by
何金镒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
建发:共享空间优惠券预约 mcp 接口优化
parent
8dee8e33
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
19 deletions
+97
-19
src/main/java/com/ikonke/konkeaialibabamcp/aitools/CDCSpacesTools.java
.../com/ikonke/konkeaialibabamcp/aitools/CDCSpacesTools.java
+8
-8
src/main/java/com/ikonke/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
...e/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
+18
-3
src/main/java/com/ikonke/konkeaialibabamcp/utils/CDCUtils.java
...ain/java/com/ikonke/konkeaialibabamcp/utils/CDCUtils.java
+51
-7
src/test/java/com/ikonke/konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
.../konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
+20
-1
No files found.
src/main/java/com/ikonke/konkeaialibabamcp/aitools/CDCSpacesTools.java
View file @
3d841dd5
...
@@ -19,28 +19,28 @@ public class CDCSpacesTools {
...
@@ -19,28 +19,28 @@ public class CDCSpacesTools {
this
.
spacesService
=
spacesService
;
this
.
spacesService
=
spacesService
;
}
}
@Tool
(
description
=
"根据房间(
会
所)ID和日期查询该日期可预约情况"
)
@Tool
(
description
=
"根据房间(
场
所)ID和日期查询该日期可预约情况"
)
public
JSONObject
getAppointmentTimeByRoomId
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
public
JSONObject
getAppointmentTimeByRoomId
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
@ToolParam
(
description
=
"查询的日期,如:2025-08-12"
)
String
date
,
@ToolParam
(
description
=
"查询的日期,如:2025-08-12"
)
String
date
,
@ToolParam
(
description
=
"查询的房间ID"
)
String
roomId
,
@ToolParam
(
description
=
"查询的房间
(场所)
ID"
)
String
roomId
,
@ToolParam
(
description
=
"查询的房间的子空间ID,可省略"
,
required
=
false
)
String
subspaceId
){
@ToolParam
(
description
=
"查询的房间
(场所)
的子空间ID,可省略"
,
required
=
false
)
String
subspaceId
){
log
.
info
(
"mcp调用--->getAppointmentTimeByRoomId..获取预约时间..sn:{},time:{},roomId:{},roomSubspaceId:{}"
,
sn
,
date
,
roomId
,
subspaceId
);
log
.
info
(
"mcp调用--->getAppointmentTimeByRoomId..获取预约时间..sn:{},time:{},roomId:{},roomSubspaceId:{}"
,
sn
,
date
,
roomId
,
subspaceId
);
return
spacesService
.
getAppointmentTimeByRoomId
(
sn
,
date
,
roomId
,
subspaceId
);
return
spacesService
.
getAppointmentTimeByRoomId
(
sn
,
date
,
roomId
,
subspaceId
);
}
}
@Tool
(
description
=
"获取该房间(
会
所)ID下可使用的优惠卷"
)
@Tool
(
description
=
"获取该房间(
场
所)ID下可使用的优惠卷"
)
public
JSONArray
getUserSpacesCoupons
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
public
JSONArray
getUserSpacesCoupons
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
@ToolParam
(
description
=
"查询的房间ID"
)
String
roomId
){
@ToolParam
(
description
=
"查询的房间
(场所)
ID"
)
String
roomId
){
log
.
info
(
"mcp调用--->getUserCoupons..获取用户优惠券..sn:{},roomId:{}"
,
sn
,
roomId
);
log
.
info
(
"mcp调用--->getUserCoupons..获取用户优惠券..sn:{},roomId:{}"
,
sn
,
roomId
);
return
spacesService
.
getUserCoupons
(
sn
,
roomId
);
return
spacesService
.
getUserCoupons
(
sn
,
roomId
);
}
}
@Tool
(
description
=
"使用优惠卷预订房间(
会
所)"
)
@Tool
(
description
=
"使用优惠卷预订房间(
场
所)"
)
public
String
bookingSpaces
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
public
String
bookingSpaces
(
@ToolParam
(
description
=
"设备的sn号,如:00226DA86A12"
)
String
sn
,
@ToolParam
(
description
=
"使用的开始时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 09:00:00"
)
String
beginTime
,
@ToolParam
(
description
=
"使用的开始时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 09:00:00"
)
String
beginTime
,
@ToolParam
(
description
=
"使用的结束时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 10:30:00"
)
String
endTime
,
@ToolParam
(
description
=
"使用的结束时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 10:30:00"
)
String
endTime
,
@ToolParam
(
description
=
"预约的房间ID"
)
String
roomId
,
@ToolParam
(
description
=
"预约的房间
(场所)
ID"
)
String
roomId
,
@ToolParam
(
description
=
"预约的房间下的子空间ID,若不是预约子空间可省略"
,
required
=
false
)
String
subspaceId
,
@ToolParam
(
description
=
"预约的房间
(场所)
下的子空间ID,若不是预约子空间可省略"
,
required
=
false
)
String
subspaceId
,
@ToolParam
(
description
=
"使用的人数,必须大于0"
)
int
userQuantity
,
@ToolParam
(
description
=
"使用的人数,必须大于0"
)
int
userQuantity
,
@ToolParam
(
description
=
"使用的优惠券ID,不能为空"
)
String
couponsId
){
@ToolParam
(
description
=
"使用的优惠券ID,不能为空"
)
String
couponsId
){
log
.
info
(
"mcp调用--->bookingOrder..预约订单..sn:{},beginTime:{},endTime:{},roomId:{},roomSubspaceId:{},userQuantity:{},couponId:{}"
,
log
.
info
(
"mcp调用--->bookingOrder..预约订单..sn:{},beginTime:{},endTime:{},roomId:{},roomSubspaceId:{},userQuantity:{},couponId:{}"
,
...
...
src/main/java/com/ikonke/konkeaialibabamcp/service/cdc/spaces/SpacesService.java
View file @
3d841dd5
...
@@ -121,6 +121,9 @@ public class SpacesService {
...
@@ -121,6 +121,9 @@ public class SpacesService {
* 查询预约时间
* 查询预约时间
*/
*/
public
JSONObject
getAppointmentTimeByRoomId
(
String
sn
,
String
paramTime
,
String
roomId
,
String
roomSubspaceIds
)
{
public
JSONObject
getAppointmentTimeByRoomId
(
String
sn
,
String
paramTime
,
String
roomId
,
String
roomSubspaceIds
)
{
if
(
StrUtil
.
isBlank
(
sn
)
||
StrUtil
.
isBlank
(
roomId
)
||
StrUtil
.
isBlank
(
paramTime
)){
return
null
;
}
// 查询预约时间
// 查询预约时间
JSONObject
response
=
new
JSONObject
();
JSONObject
response
=
new
JSONObject
();
try
{
try
{
...
@@ -151,11 +154,17 @@ public class SpacesService {
...
@@ -151,11 +154,17 @@ public class SpacesService {
JSONArray
info
=
firstDayJson
.
getJSONArray
(
"info"
);
JSONArray
info
=
firstDayJson
.
getJSONArray
(
"info"
);
int
timeSegmentIndex
=
CDCUtils
.
getTimeSegmentIndex
(
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
if
(
timeSegmentIndex
<
0
){
timeSegmentIndex
=
0
;
}
JSONArray
response_time
=
new
JSONArray
();
JSONArray
response_time
=
new
JSONArray
();
for
(
int
j
=
0
;
j
<
48
;
j
++){
for
(
int
j
=
timeSegmentIndex
;
j
<
48
;
j
++){
Integer
number
=
info
.
getInt
(
j
);
//0=不可预定 1=可预订 2=已被预定
Integer
number
=
info
.
getInt
(
j
);
//0=不可预定 1=可预订 2=已被预定
JSONObject
jsonObject1
=
new
JSONObject
();
JSONObject
jsonObject1
=
new
JSONObject
();
jsonObject1
.
set
(
"timeSegment"
,
CDCUtils
.
time_segment
[
j
]);
jsonObject1
.
set
(
"timeSegment"
,
CDCUtils
.
time_segment
[
j
]);
if
(
number
==
1
){
if
(
number
==
1
){
jsonObject1
.
set
(
"availability"
,
"可预订"
);
jsonObject1
.
set
(
"availability"
,
"可预订"
);
}
else
if
(
number
==
2
){
}
else
if
(
number
==
2
){
...
@@ -181,6 +190,9 @@ public class SpacesService {
...
@@ -181,6 +190,9 @@ public class SpacesService {
* 预约订单,不使用钱 使用了优惠卷
* 预约订单,不使用钱 使用了优惠卷
*/
*/
public
boolean
bookingOrder
(
String
sn
,
String
beginTime
,
String
endTime
,
String
roomId
,
String
subspaceId
,
int
userQuantity
,
String
couponId
){
public
boolean
bookingOrder
(
String
sn
,
String
beginTime
,
String
endTime
,
String
roomId
,
String
subspaceId
,
int
userQuantity
,
String
couponId
){
if
(
StrUtil
.
isBlank
(
sn
)
||
StrUtil
.
isBlank
(
roomId
)
||
StrUtil
.
isBlank
(
beginTime
)
||
StrUtil
.
isBlank
(
endTime
)
||
StrUtil
.
isBlank
(
couponId
)
||
userQuantity
<
1
){
throw
new
StatefulException
(
530
,
"参数错误"
);
}
Date
begin_time
=
DateUtil
.
parse
(
beginTime
);
Date
begin_time
=
DateUtil
.
parse
(
beginTime
);
Date
end_time
=
DateUtil
.
parse
(
endTime
);
Date
end_time
=
DateUtil
.
parse
(
endTime
);
if
(
begin_time
.
getTime
()
>=
end_time
.
getTime
()){
if
(
begin_time
.
getTime
()
>=
end_time
.
getTime
()){
...
@@ -195,8 +207,8 @@ public class SpacesService {
...
@@ -195,8 +207,8 @@ public class SpacesService {
if
(
DateUtil
.
between
(
new
Date
(),
end_time
,
DateUnit
.
DAY
)
>
7
){
if
(
DateUtil
.
between
(
new
Date
(),
end_time
,
DateUnit
.
DAY
)
>
7
){
throw
new
StatefulException
(
533
,
"不能预约超过7天"
);
throw
new
StatefulException
(
533
,
"不能预约超过7天"
);
}
}
int
begin_num
=
CDCUtils
.
getTimeSegmentIndex
(
DateUtil
.
formatTime
(
begin_time
)
);
int
begin_num
=
CDCUtils
.
getTimeSegmentIndex
(
beginTime
);
int
end_num
=
CDCUtils
.
getTimeSegmentIndex
(
DateUtil
.
formatTime
(
end_time
)
);
int
end_num
=
CDCUtils
.
getTimeSegmentIndex
(
endTime
);
String
use_time
=
DateUtil
.
formatDate
(
begin_time
);
String
use_time
=
DateUtil
.
formatDate
(
begin_time
);
//校验预约时间
//校验预约时间
...
@@ -343,6 +355,9 @@ public class SpacesService {
...
@@ -343,6 +355,9 @@ public class SpacesService {
* 获取用户已领取的优惠券列表
* 获取用户已领取的优惠券列表
*/
*/
public
JSONArray
getUserCoupons
(
String
sn
,
String
roomId
){
public
JSONArray
getUserCoupons
(
String
sn
,
String
roomId
){
if
(
StrUtil
.
isBlank
(
sn
)
||
StrUtil
.
isBlank
(
roomId
)){
return
null
;
}
String
url
=
getUserCouponsUrl
+
"?status=0"
;
String
url
=
getUserCouponsUrl
+
"?status=0"
;
if
(
StrUtil
.
isNotBlank
(
roomId
)){
if
(
StrUtil
.
isNotBlank
(
roomId
)){
url
=
url
+
"&roomId="
+
roomId
;
url
=
url
+
"&roomId="
+
roomId
;
...
...
src/main/java/com/ikonke/konkeaialibabamcp/utils/CDCUtils.java
View file @
3d841dd5
package
com.ikonke.konkeaialibabamcp.utils
;
package
com.ikonke.konkeaialibabamcp.utils
;
import
cn.hutool.core.date.DateUtil
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.util.Date
;
public
class
CDCUtils
{
public
class
CDCUtils
{
public
static
String
[]
time_segment
=
{
"00:00-00:30"
,
"00:30-01:00"
,
"01:00-01:30"
,
"01:30-02:00"
,
"02:00-02:30"
,
"02:30-03:00"
,
"03:00-03:30"
,
"03:30-04:00"
,
"04:00-04:30"
,
"04:30-05:00"
,
public
static
String
[]
time_segment
=
{
"05:00-05:30"
,
"05:30-06:00"
,
"06:00-06:30"
,
"06:30-07:00"
,
"07:00-07:30"
,
"07:30-08:00"
,
"08:00-08:30"
,
"08:30-09:00"
,
"09:00-09:30"
,
"09:30-10:00"
,
"10:00-10:30"
,
"10:30-11:00"
,
"00:00-00:30"
,
"00:30-01:00"
,
"01:00-01:30"
,
"01:30-02:00"
,
"02:00-02:30"
,
"11:00-11:30"
,
"11:30-12:00"
,
"12:00-12:30"
,
"12:30-13:00"
,
"13:00-13:30"
,
"13:30-14:00"
,
"14:00-14:30"
,
"14:30-15:00"
,
"15:00-15:30"
,
"15:30-16:00"
,
"16:00-16:30"
,
"16:30-17:00"
,
"02:30-03:00"
,
"03:00-03:30"
,
"03:30-04:00"
,
"04:00-04:30"
,
"04:30-05:00"
,
"17:00-17:30"
,
"17:30-18:00"
,
"18:00-18:30"
,
"18:30-19:00"
,
"19:00-19:30"
,
"19:30-20:00"
,
"20:00-20:30"
,
"20:30-21:00"
,
"21:00-21:30"
,
"21:30-22:00"
,
"22:00-22:30"
,
"22:30-23:00"
,
"05:00-05:30"
,
"05:30-06:00"
,
"06:00-06:30"
,
"06:30-07:00"
,
"07:00-07:30"
,
"23:00-23:30"
,
"23:30-24:00"
};
//前面包含,后面不包含
"07:30-08:00"
,
"08:00-08:30"
,
"08:30-09:00"
,
"09:00-09:30"
,
"09:30-10:00"
,
"10:00-10:30"
,
"10:30-11:00"
,
"11:00-11:30"
,
"11:30-12:00"
,
"12:00-12:30"
,
"12:30-13:00"
,
"13:00-13:30"
,
"13:30-14:00"
,
"14:00-14:30"
,
"14:30-15:00"
,
"15:00-15:30"
,
"15:30-16:00"
,
"16:00-16:30"
,
"16:30-17:00"
,
"17:00-17:30"
,
"17:30-18:00"
,
"18:00-18:30"
,
"18:30-19:00"
,
"19:00-19:30"
,
"19:30-20:00"
,
"20:00-20:30"
,
"20:30-21:00"
,
"21:00-21:30"
,
"21:30-22:00"
,
"22:00-22:30"
,
"22:30-23:00"
,
"23:00-23:30"
,
"23:30-24:00"
};
//前面包含,后面不包含
/**
/**
* 根据输入的时间(时分秒)找到在 time_segment 数组中的下标
* 根据输入的时间(时分秒)找到在 time_segment 数组中的下标
*
*
* @param time 输入的时间,格式为 "HH:mm:ss",例如 "13:11:00"
* @param time
Param
输入的时间,格式为 "HH:mm:ss",例如 "13:11:00"
* @return 对应的 time_segment 数组下标
* @return 对应的 time_segment 数组下标
*/
*/
public
static
int
getTimeSegmentIndex
(
String
time
)
{
public
static
int
getTimeSegmentIndex
(
String
timeParam
)
{
Date
date3
=
CDCUtils
.
roundToHalfHourOrHour
(
DateUtil
.
parse
(
timeParam
));
String
time
=
DateUtil
.
formatTime
(
date3
);
// 提取小时和分钟部分
// 提取小时和分钟部分
String
[]
parts
=
time
.
split
(
":"
);
String
[]
parts
=
time
.
split
(
":"
);
int
hour
=
Integer
.
parseInt
(
parts
[
0
]);
int
hour
=
Integer
.
parseInt
(
parts
[
0
]);
...
@@ -34,4 +49,33 @@ public class CDCUtils {
...
@@ -34,4 +49,33 @@ public class CDCUtils {
// 如果超出范围,返回 -1 表示未找到
// 如果超出范围,返回 -1 表示未找到
return
-
1
;
return
-
1
;
}
}
/**
* 将时间转换为半小时或整小时
* - 分钟小于30分钟的转换成30分钟
* - 分钟大于等于30分钟的小时加一,并将分钟设为0
*
* @param date 原始时间
* @return 转换后的时间
*/
public
static
Date
roundToHalfHourOrHour
(
Date
date
)
{
LocalDateTime
dateTime
=
date
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDateTime
();
int
minute
=
dateTime
.
getMinute
();
int
second
=
dateTime
.
getSecond
();
int
nano
=
dateTime
.
getNano
();
// 如果已经是整点(0分0秒0纳秒)或半点(30分0秒0纳秒),则不转换
if
((
minute
==
0
||
minute
==
30
)
&&
second
==
0
&&
nano
==
0
)
{
return
date
;
}
LocalDateTime
roundedTime
;
if
(
minute
<
30
)
{
// 分钟小于30,设置为30分钟
roundedTime
=
dateTime
.
withMinute
(
30
).
withSecond
(
0
).
withNano
(
0
);
}
else
{
// 分钟大于等于30,进位到下一小时,分钟设为0
roundedTime
=
dateTime
.
plusHours
(
1
).
withMinute
(
0
).
withSecond
(
0
).
withNano
(
0
);
}
return
Date
.
from
(
roundedTime
.
atZone
(
ZoneId
.
systemDefault
()).
toInstant
());
}
}
}
src/test/java/com/ikonke/konkeaialibabamcp/KonkeAiAlibabaMcpApplicationTests.java
View file @
3d841dd5
package
com.ikonke.konkeaialibabamcp
;
package
com.ikonke.konkeaialibabamcp
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.json.JSONObject
;
import
com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService
;
import
com.ikonke.konkeaialibabamcp.utils.CDCUtils
;
import
com.ikonke.konkeaialibabamcp.utils.CcuUtils
;
import
com.ikonke.konkeaialibabamcp.utils.CcuUtils
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
java.util.Date
;
@SpringBootTest
@SpringBootTest
class
KonkeAiAlibabaMcpApplicationTests
{
class
KonkeAiAlibabaMcpApplicationTests
{
@Autowired
private
SpacesService
spacesService
;
public
static
String
sn
=
"00226DA86A12"
;
public
static
String
date
=
"2025-08-13"
;
public
static
String
roomId
=
"7ccc8b95b97b45d190734d186673c7d2"
;
public
static
String
subspaceId
=
null
;
@Test
@Test
void
contextLoads
()
{
void
contextLoads
()
{
System
.
out
.
println
(
CcuUtils
.
getCcuName
(
"CCU_12345"
));
// JSONObject appointmentTimeByRoomId = spacesService.getAppointmentTimeByRoomId(sn, date, roomId, subspaceId);
// System.out.println(appointmentTimeByRoomId);
}
}
}
}
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