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

建发:共享空间优惠券预约 mcp 接口优化 4

parent 800f4f2f
......@@ -344,10 +344,12 @@ public class SpacesService {
}
//自动查找优惠券
String couponId = null;
String couponName = null;
JSONArray userSpacesCouponsByBooking = this.getUserSpacesCouponsByTime(sn, roomId, beginTime, endTime);
if(userSpacesCouponsByBooking!=null && !userSpacesCouponsByBooking.isEmpty()){
JSONObject jsonObject1 = userSpacesCouponsByBooking.getJSONObject(0);
couponId = jsonObject1.getStr("couponsId");
couponName = jsonObject1.getStr("couponsName");
}
if(StrUtil.isBlank(couponId)){
throw new StatefulException(535, "未找到合适的优惠券,暂不支持没有优惠券的预约");
......@@ -374,7 +376,7 @@ public class SpacesService {
String spacesRoomOrder_post = cdcHttpUtils.post(spacesRoomOrderUrl, sn, param.toString());
JSONObject spacesRoomOrder = new JSONObject(spacesRoomOrder_post);
if(spacesRoomOrder.getInt("code") == 200){
return "预约成功,预约订单号:"+spacesRoomOrder.getStr("data");
return "已使用优惠券:"+couponName+"成功预约,预约订单号:"+spacesRoomOrder.getStr("data");
}else{
throw new StatefulException(539, "预约失败");
}
......@@ -499,6 +501,12 @@ public class SpacesService {
if(DateUtil.between(new Date(), end_time, DateUnit.DAY) > 7){
throw new StatefulException(533, "不能预约超过7天");
}
Boolean is_all_day = false;
if((DateUtil.between(end_time, DateUtil.endOfDay(begin_time), DateUnit.SECOND) == 0)
&& (DateUtil.between(begin_time, DateUtil.beginOfDay(begin_time), DateUnit.SECOND) == 0)){
// 一整天 00:00:00 - 23:59:59 表示用户想查这天有没有可用的优惠券而不是要预约一整天,预约时间必须是 00:00-30:00
is_all_day = true;
}
//校验优惠券
String s = cdcHttpUtils.get(getUserCouponsUrl+"?status=0&roomId="+roomId, sn);
......@@ -516,7 +524,7 @@ public class SpacesService {
String discountTime = coup.getStr("discount");//抵用时长(只能是0.5的整数倍)
int time = Integer.parseInt(discountTime) * 30;
if(begin_time.getTime() >= coup_start_time.getTime() && end_time.getTime() <= coup_end_time.getTime()){
if(DateUtil.between(begin_time, end_time, DateUnit.MINUTE) <= time){
if(DateUtil.between(begin_time, end_time, DateUnit.MINUTE) <= time || is_all_day){
//可用优惠券
JSONObject coupon_json = new JSONObject();
coupon_json.set("couponsId", coup.getStr("id"));
......
package com.ikonke.konkeaialibabamcp;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
......@@ -20,20 +21,32 @@ class KonkeAiAlibabaMcpApplicationTests {
public static String sn = "00226DA86A12";
public static String date = "2025-08-13";
public static String roomId = "a550c009a8c041c2ba3fa22490583770";
public static String roomId = "123309ac482d469c8608ce95e51da65a";
public static String subspaceId = null;
@Test
void contextLoads() {
// JSONObject appointmentTimeByRoomId = spacesService.getAppointmentTimeByRoomId(sn, date, roomId, subspaceId);
// System.out.println(appointmentTimeByRoomId);
// JSONArray userSpacesCouponsByBooking = spacesService.getUserSpacesCouponsByTime(sn, roomId, "2025-08-14 18:00:00", "2025-08-14 21:00:00");
// mcp调用--->getUserSpacesCouponsByTime..获取用户当前预约可用的优惠券..sn:00226DA86A12,roomId:123309ac482d469c8608ce95e51da65a,beginTime:2025-08-15 00:00:00,endTime:2025-08-15 23:59:59
// JSONArray userSpacesCouponsByBooking = spacesService.getUserSpacesCouponsByTime(sn, roomId, "2025-08-15 00:00:00", "2025-08-15 23:59:59");
// System.out.println(userSpacesCouponsByBooking);
// Date begin_time = DateUtil.parse("2025-08-15 00:00:00");
// Date end_time = DateUtil.parse("2025-08-15 23:59:59");
// long time = DateUtil.beginOfDay(begin_time).getTime();
// long time1 = DateUtil.endOfDay(begin_time).getTime();
// System.out.println(time);
// System.out.println(begin_time.getTime());
// System.out.println(time1);
// System.out.println(end_time.toInstant());
// System.out.println(DateUtil.between(end_time, DateUtil.endOfDay(begin_time), DateUnit.SECOND));
// boolean b = spacesService.bookingOrder2(sn, "2025-08-14 18:00:00", "2025-08-14 21:00:00", "a550c009a8c041c2ba3fa22490583770", null, 1);
// System.out.println(b);
}
}
......@@ -33,6 +33,7 @@
当用户提出在某个时间段要预约您管理的某个场所或房间时,调用mcp函数bookingSpaces进行预约,请按照函数的回复更合理的回复用户
## 注意:
- 需要用户提供预约时间、预约的场所、预约的人数
- 预约时间的分钟必须是00或30,秒钟必须是 00,比如:2025-08-15 08:00:00,2025-08-15 16:30:00
- 预约开始时间和预约结束时间不能是过去时间
- 预约结束时间必须大于预约开始时间且要大于1小时
- 预约结束时间和预约开始时间必须是同一天
......
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