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

建发:共享空间优惠券

parent aa750d05
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
通过智慧屏/APP/小程序的AI语音交互,可实现会所空间的快捷预约管理,提高会所利用率与运维效率,提升业主满意度 通过智慧屏/APP/小程序的AI语音交互,可实现会所空间的快捷预约管理,提高会所利用率与运维效率,提升业主满意度
1、查 小区功能区列表(/third/screen/spaces/rooms) 1、查 小区功能区列表(/third/screen/spaces/rooms)
2、查询可预约时间 2、查询可预约时间
2、预约付钱订单---->成功或失败 3、预约必须一个小时起,不能隔天
3、成功--->生产支付二维码-->支付 3、预约订单,如果有优惠卷可抵消预约的时间,直接使用/third/screen/spaces/order/submit
4、支付成功后---->提交订单(新)/third/screen/spaces/order/submit 4、优惠卷和金钱必须二选一,若价格为0,也必须使用优惠券
5、如果价格不为0,需要支付,先使用/third/mini/record-->支付二维码--->再使用/third/screen/spaces/order/submit
5、
- 机器人联动 - 机器人联动
通过智慧屏/APP/小程序的AI语音交互,可实现配送机器人/收垃圾机器人快捷预约上门服务,实现更加便捷下单,并支持语音对话。 通过智慧屏/APP/小程序的AI语音交互,可实现配送机器人/收垃圾机器人快捷预约上门服务,实现更加便捷下单,并支持语音对话。
- 社区活动推荐 - 社区活动推荐
......
package com.ikonke.konkeaialibabamcp; package com.ikonke.konkeaialibabamcp;
import com.ikonke.konkeaialibabamcp.aitools.CDCSpacesTools;
import com.ikonke.konkeaialibabamcp.aitools.DeviceTools; import com.ikonke.konkeaialibabamcp.aitools.DeviceTools;
import com.ikonke.konkeaialibabamcp.aitools.WeatherTools;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.ai.tool.ToolCallbackProvider; import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider; import org.springframework.ai.tool.method.MethodToolCallbackProvider;
...@@ -17,8 +19,10 @@ public class KonkeAiAlibabaMcpApplication { ...@@ -17,8 +19,10 @@ public class KonkeAiAlibabaMcpApplication {
} }
@Bean @Bean
public ToolCallbackProvider tools(DeviceTools deviceTools) { public ToolCallbackProvider tools(DeviceTools deviceTools, WeatherTools weatherTools, CDCSpacesTools cdcSpacesTools) {
return MethodToolCallbackProvider.builder().toolObjects(deviceTools).build(); return MethodToolCallbackProvider.builder()
.toolObjects(deviceTools, weatherTools, cdcSpacesTools)
.build();
} }
} }
package com.ikonke.konkeaialibabamcp.aitools;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService;
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 CDCSpacesTools {
private final SpacesService spacesService;
public CDCSpacesTools(SpacesService spacesService) {
this.spacesService = spacesService;
}
@Tool(description = "根据房间ID和日期查询该日期可预约情况")
public JSONObject getAppointmentTimeByRoomId(@ToolParam(description = "设备的sn号,如:00226DA86A12")String sn,
@ToolParam(description = "查询的日志,如:2025-08-12")String date,
@ToolParam(description = "查询的房间ID")String roomId,
@ToolParam(description = "查询的房间的子空间ID,可省略")String subspaceId){
log.info("getAppointmentTimeByRoomId..获取预约时间..sn:{},time:{},roomId:{},roomSubspaceId:{}",sn,date,roomId,subspaceId);
return spacesService.getAppointmentTimeByRoomId(sn,date,roomId,subspaceId);
}
@Tool(description = "获取该房间ID下可使用的优惠卷")
public JSONArray getUserCoupons(@ToolParam(description = "设备的sn号,如:00226DA86A12")String sn,
@ToolParam(description = "查询的房间ID")String roomId){
log.info("getUserCoupons..获取用户优惠券..sn:{},roomId:{}",sn,roomId);
return spacesService.getUserCoupons(sn,roomId);
}
@Tool(description = "使用优惠卷预订房间")
public boolean bookingOrder(@ToolParam(description = "设备的sn号,如:00226DA86A12")String sn,
@ToolParam(description = "使用的开始时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 09:00:00")String beginTime,
@ToolParam(description = "使用的结束时间,必须是30分钟的倍数且不能隔天预约,如:2025-08-12 10:30:00")String endTime,
@ToolParam(description = "预约的房间ID")String roomId,
@ToolParam(description = "预约的房间下的子空间ID")String subspaceId,
@ToolParam(description = "使用的人数,必须大于1")int userQuantity,
@ToolParam(description = "使用的优惠券ID,不能为空")String couponId){
log.info("bookingOrder..预约订单..sn:{},beginTime:{},endTime:{},roomId:{},roomSubspaceId:{},userQuantity:{},couponId:{}",
sn,beginTime,endTime,roomId,subspaceId,userQuantity,couponId);
return spacesService.bookingOrder(sn,beginTime,endTime,roomId,subspaceId,userQuantity,couponId);
}
}
...@@ -6,7 +6,6 @@ import com.ikonke.konkeaialibabamcp.service.SycDeviceService; ...@@ -6,7 +6,6 @@ import com.ikonke.konkeaialibabamcp.service.SycDeviceService;
import com.ikonke.konkeaialibabamcp.service.mongdbservice.DeviceStatusService; import com.ikonke.konkeaialibabamcp.service.mongdbservice.DeviceStatusService;
import com.ikonke.konkeaialibabamcp.utils.CcuUtils; import com.ikonke.konkeaialibabamcp.utils.CcuUtils;
import com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils; import com.ikonke.konkeaialibabamcp.utils.KonkeIotUtils;
import com.ikonke.konkeaialibabamcp.utils.WeatherUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool; import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam; import org.springframework.ai.tool.annotation.ToolParam;
...@@ -19,12 +18,11 @@ public class DeviceTools { ...@@ -19,12 +18,11 @@ public class DeviceTools {
private final DeviceStatusService deviceStatusUtil; private final DeviceStatusService deviceStatusUtil;
private final KonkeIotUtils konkeIotServer; private final KonkeIotUtils konkeIotServer;
private final SycDeviceService sycDeviceService; private final SycDeviceService sycDeviceService;
private final WeatherUtils weatherUtils;
public DeviceTools(DeviceStatusService deviceStatusUtil, KonkeIotUtils konkeIotServer, SycDeviceService sycDeviceService, WeatherUtils weatherUtils){ public DeviceTools(DeviceStatusService deviceStatusUtil, KonkeIotUtils konkeIotServer, SycDeviceService sycDeviceService){
this.deviceStatusUtil = deviceStatusUtil; this.deviceStatusUtil = deviceStatusUtil;
this.konkeIotServer = konkeIotServer; this.konkeIotServer = konkeIotServer;
this.sycDeviceService = sycDeviceService; this.sycDeviceService = sycDeviceService;
this.weatherUtils = weatherUtils;
} }
@Tool(description = "根据主机号和设备ID查询设备状态信息.") @Tool(description = "根据主机号和设备ID查询设备状态信息.")
...@@ -58,20 +56,6 @@ public class DeviceTools { ...@@ -58,20 +56,6 @@ public class DeviceTools {
@Tool(description = "根据城市名查询当前的天气")
public String getWeatherNow(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询当前的天气....city:{}",city);
return weatherUtils.getWeatherNow(city);
}
@Tool(description = "根据城市名查询未来24小时的天气")
public String getWeatherHourly(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询未来24小时的天气...city:{}",city);
return weatherUtils.getWeatherHourly(city);
}
@Tool(description = "根据城市名查询未来7天的天气")
public String getWeatherDaily(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询未来7天的天气....city:{}",city);
return weatherUtils.getWeatherDaily(city);
}
} }
package com.ikonke.konkeaialibabamcp.aitools;
import com.ikonke.konkeaialibabamcp.utils.WeatherUtils;
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 WeatherTools {
private final WeatherUtils weatherUtils;
public WeatherTools(WeatherUtils weatherUtils) {
this.weatherUtils = weatherUtils;
}
@Tool(description = "根据城市名查询当前的天气")
public String getWeatherNow(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询当前的天气....city:{}",city);
return weatherUtils.getWeatherNow(city);
}
@Tool(description = "根据城市名查询未来24小时的天气")
public String getWeatherHourly(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询未来24小时的天气...city:{}",city);
return weatherUtils.getWeatherHourly(city);
}
@Tool(description = "根据城市名查询未来7天的天气")
public String getWeatherDaily(@ToolParam(description = "城市,如:成都、西安")String city){
log.info("根据城市名查询未来7天的天气....city:{}",city);
return weatherUtils.getWeatherDaily(city);
}
}
...@@ -2,10 +2,12 @@ package com.ikonke.konkeaialibabamcp.controller; ...@@ -2,10 +2,12 @@ package com.ikonke.konkeaialibabamcp.controller;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken; import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils; import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils;
import com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService; import com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService;
import com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService; import com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService;
import com.ikonke.konkeaialibabamcp.utils.CcuUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -36,9 +38,14 @@ public class CDCController { ...@@ -36,9 +38,14 @@ public class CDCController {
bySn.setSn(sn); bySn.setSn(sn);
bySn.setAccessToken(token); bySn.setAccessToken(token);
bySn.setState(CDCToken.STATE_ENABLED); bySn.setState(CDCToken.STATE_ENABLED);
bySn.setCcuId(ccuName); bySn.setCcuId(CcuUtils.getCcuName(ccuName));
bySn.setCreateTime(LocalDateTime.now()); bySn.setCreateTime(LocalDateTime.now());
tokenService.save(bySn); tokenService.save(bySn);
}else{
if(bySn.getAccessToken().equals(token)
&& bySn.getSn().equals(sn)
&& bySn.getCcuId().equals(CcuUtils.getCcuName(ccuName))){
return true;
}else{ }else{
CdcHttpUtils.CDCTokenCache.remove(sn); CdcHttpUtils.CDCTokenCache.remove(sn);
...@@ -46,16 +53,32 @@ public class CDCController { ...@@ -46,16 +53,32 @@ public class CDCController {
bySn.setRefreshToken(bySn.getAccessToken()); bySn.setRefreshToken(bySn.getAccessToken());
bySn.setState(CDCToken.STATE_ENABLED); bySn.setState(CDCToken.STATE_ENABLED);
bySn.setCreateTime(LocalDateTime.now()); bySn.setCreateTime(LocalDateTime.now());
bySn.setCcuId(ccuName); bySn.setCcuId(CcuUtils.getCcuName(ccuName));
tokenService.updateById(bySn); tokenService.updateById(bySn);
} }
}
return true; return true;
} }
@GetMapping("/getSpacesList") @GetMapping("/getSpacesList")
public JSONArray getSpacesList(@RequestParam(name = "sn") String sn){ public JSONArray getSpacesList(@RequestParam(name = "sn") String sn){
log.info("getSpacesList..获取空间列表..sn:{}",sn); log.info("getSpacesList..获取空间列表..sn:{}",sn);
return spacesService.findAll(sn); JSONArray all = spacesService.findAll(sn);
if(!all.isEmpty()){
return all;
}else{
return null;
}
}
@GetMapping("/getAppointmentTimeByRoomId")
public JSONObject getAppointmentTimeByRoomId(@RequestParam(name = "sn")String sn,
@RequestParam(name = "time")String time,
@RequestParam(name = "roomId")String roomId,
@RequestParam(name = "roomSubspaceId",required = false)String roomSubspaceId){
log.info("getAppointmentTimeByRoomId..获取预约时间..sn:{},time:{},roomId:{},roomSubspaceId:{}",sn,time,roomId,roomSubspaceId);
return spacesService.getAppointmentTimeByRoomId(sn,time,roomId,roomSubspaceId);
} }
} }
package com.ikonke.konkeaialibabamcp.service.cdc.spaces; package com.ikonke.konkeaialibabamcp.service.cdc.spaces;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.StatefulException; import cn.hutool.core.exceptions.StatefulException;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils; import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils;
import com.ikonke.konkeaialibabamcp.utils.CDCUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j @Slf4j
@Component @Component
public class SpacesService { public class SpacesService {
...@@ -22,6 +30,25 @@ public class SpacesService { ...@@ -22,6 +30,25 @@ public class SpacesService {
private String getSpacesRoomDetailUrl; private String getSpacesRoomDetailUrl;
@Value("${cdc.getSpacesRoomBookingUrl}") @Value("${cdc.getSpacesRoomBookingUrl}")
private String getSpacesRoomBookingUrl; private String getSpacesRoomBookingUrl;
@Value("${cdc.bookingSpacesRoomUrl}")
private String bookingSpacesRoomUrl;
@Value("${cdc.spacesRoomOrderUrl}")
private String spacesRoomOrderUrl;
// 获取可领取的优惠卷
@Value("${cdc.spacesCoupons.getSpacesCouponsListUrl}")
private String getSpacesCouponsListUrl;
// 领取单张优惠卷
@Value("${cdc.spacesCoupons.receiveSpacesCouponsUrl}")
private String receiveSpacesCouponsUrl;
// 获取用户已经领取的优惠卷
@Value("${cdc.spacesCoupons.getUserCouponsUrl}")
private String getUserCouponsUrl;
// 一键领取优惠卷
@Value("${cdc.spacesCoupons.oneClickClaimCouponUrl}")
private String oneClickClaimCouponUrl;
@Autowired @Autowired
private CdcHttpUtils cdcHttpUtils; private CdcHttpUtils cdcHttpUtils;
...@@ -36,9 +63,9 @@ public class SpacesService { ...@@ -36,9 +63,9 @@ public class SpacesService {
}else{ }else{
JSONArray data = spacesJson.getJSONArray("data"); JSONArray data = spacesJson.getJSONArray("data");
JSONArray spacesList = data.getJSONArray(1); JSONArray spacesList = data.getJSONArray(1);
JSONArray response = new JSONArray(); JSONArray response = new JSONArray();
for( int i = 0; i < spacesList.size(); i++){ for( int i = 0; i < spacesList.size(); i++){
JSONObject response_spaces = new JSONObject();
JSONObject jsonObject = spacesList.getJSONObject(i); JSONObject jsonObject = spacesList.getJSONObject(i);
String status = jsonObject.getStr("status");//0=正常;1=维护中(任何时段都不可预定) String status = jsonObject.getStr("status");//0=正常;1=维护中(任何时段都不可预定)
String name = jsonObject.getStr("name");//空间名 String name = jsonObject.getStr("name");//空间名
...@@ -50,21 +77,23 @@ public class SpacesService { ...@@ -50,21 +77,23 @@ public class SpacesService {
} }
String subspaceType = jsonObject.getStr("subspaceType");//0:单独空间 1:内分子空间 String subspaceType = jsonObject.getStr("subspaceType");//0:单独空间 1:内分子空间
response_spaces.set("场所ID",id); if("0".equals(status)){
response_spaces.set("场所名称",name); JSONObject response_spaces = new JSONObject();
response_spaces.set("当前场所里面的用户数",main_userCount); response_spaces.set("roomId",id);
response_spaces.set("roomName",name);
response_spaces.set("peopleInUseNumber",main_userCount);
Double price = 0.0;
if("0".equals(status) && ("1".equals(type) || "2".equals(type)) && "1".equals(subspaceType)){ //查详情-子空间-正常
//查详情-子空间
String s1 = cdcHttpUtils.get(getSpacesRoomDetailUrl + id, sn); String s1 = cdcHttpUtils.get(getSpacesRoomDetailUrl + id, sn);
JSONObject spacesRoomDetailJson = JSONUtil.parseObj(s1); JSONObject spacesRoomDetailJson = JSONUtil.parseObj(s1);
if(spacesRoomDetailJson.getInt("code") == 200){ if(spacesRoomDetailJson.getInt("code") == 200){
JSONObject result = spacesRoomDetailJson.getJSONObject("data"); JSONObject result = spacesRoomDetailJson.getJSONObject("data");
Integer userCount = result.getInt("userCount");//当前里面的用户数,每日凌晨改成0
if(userCount == null){ price = result.getDouble("price");
userCount = 0; response_spaces.set("price",price);
}
Integer maxUser = result.getInt("maxUser");//推荐使用最多人数 if(result.containsKey("subspacePd") && StrUtil.isNotBlank(result.getStr("subspacePd"))){
JSONArray subspacePd = result.getJSONArray("subspacePd");//子空间 JSONArray subspacePd = result.getJSONArray("subspacePd");//子空间
JSONArray child = new JSONArray(); JSONArray child = new JSONArray();
for( int j = 0; j < subspacePd.size(); j++){ for( int j = 0; j < subspacePd.size(); j++){
...@@ -73,20 +102,221 @@ public class SpacesService { ...@@ -73,20 +102,221 @@ public class SpacesService {
String subspacePdId = jsonObject1.getStr("id"); String subspacePdId = jsonObject1.getStr("id");
JSONObject childJsonObject = new JSONObject(); JSONObject childJsonObject = new JSONObject();
childJsonObject.set("房间名称", subspacePdName); childJsonObject.set("subspaceName", subspacePdName);
childJsonObject.set("房间ID", subspacePdId); childJsonObject.set("subspaceId", subspacePdId);
childJsonObject.set("当前房间里面的用户数", userCount);
child.set(childJsonObject); child.set(childJsonObject);
} }
response_spaces.set("subspacePd", child); response_spaces.set("subspaces", child);
} }
} }
response.set(response_spaces); response.set(response_spaces);
} }
}
return response;
}
}
/**
* 查询预约时间
*/
public JSONObject getAppointmentTimeByRoomId(String sn,String paramTime,String roomId,String roomSubspaceIds) {
// 查询预约时间
JSONObject response = new JSONObject();
try {
Date date = DateUtil.parse(paramTime);
String time = DateUtil.formatDate(date);
response.set("roomId",roomId);
response.set("date",time);
JSONObject param = new JSONObject();
param.set("time", time);
param.set("id", roomId);
if(StrUtil.isNotBlank(roomSubspaceIds)){
response.set("subspaceIds", roomSubspaceIds);
List<String> roomSubspaceIdsList = new ArrayList<>();
String[] split = roomSubspaceIds.split(",");
for(String roomSubspaceId : split){
roomSubspaceIdsList.add(roomSubspaceId.trim());
}
param.set("roomSubspaceIds", roomSubspaceIdsList);
}
String post = cdcHttpUtils.post(getSpacesRoomBookingUrl, sn, param.toString());
JSONObject jsonObject = new JSONObject(post);
if(jsonObject.getInt("code") == 200){
JSONObject dataJson = jsonObject.getJSONObject("data");
JSONObject firstDayJson = dataJson.getJSONObject("firstDay");
JSONArray info = firstDayJson.getJSONArray("info");
JSONArray response_time = new JSONArray();
for( int j = 0; 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);
}
response.set("time", response_time);
}else{
response.set("time", "不可预约");
}
}catch (Exception e) {
e.printStackTrace();
throw new StatefulException(52, "查询会所预约情况失败");
}
return response;
}
/**
*
* 预约订单,不使用钱 使用了优惠卷
*/
public boolean bookingOrder(String sn,String beginTime,String endTime,String roomId,String subspaceId,int userQuantity,String couponId){
Date begin_time = DateUtil.parse(beginTime);
Date end_time = DateUtil.parse(endTime);
if(begin_time.getTime() >= end_time.getTime()){
throw new StatefulException(53, "开始时间不能大于结束时间");
}
if(!DateUtil.formatDate(begin_time).equals(DateUtil.formatDate(end_time))){
throw new StatefulException(54, "不能跨天预约");
}
if(begin_time.getTime() < System.currentTimeMillis()){
throw new StatefulException(55, "不能预约历史时间");
}
if(DateUtil.between(new Date(), end_time, DateUnit.DAY) > 7){
throw new StatefulException(56, "不能预约超过7天");
}
int begin_num = CDCUtils.getTimeSegmentIndex(DateUtil.formatTime(begin_time));
int end_num = CDCUtils.getTimeSegmentIndex(DateUtil.formatTime(end_time));
String use_time = DateUtil.formatDate(begin_time);
JSONObject param = new JSONObject();
param.set("roomId", roomId);
if(StrUtil.isNotBlank(subspaceId)){
param.set("roomSubspaceId", subspaceId);
}
param.set("useTime", use_time);
param.set("useEndTime", use_time);
param.set("beginTime", begin_num);
param.set("endTime", end_num);
param.set("orderNum", userQuantity);
param.set("isRenew", 0);
param.set("userCouponsId", couponId);
param.set("payFlag", "false");
String post = cdcHttpUtils.post(spacesRoomOrderUrl, sn, param.toString());
JSONObject jsonObject = new JSONObject(post);
if(jsonObject.getInt("code") == 200){
return true;
}else{
throw new StatefulException(57, "预约失败");
}
}
/**
* 获取可领取的优惠券列表
*/
public JSONArray getSpacesCouponsList(String sn){
String couponsListStr = cdcHttpUtils.get(getSpacesCouponsListUrl, sn);
JSONObject coupons = JSONUtil.parseObj(couponsListStr);
if(coupons.getInt("code") == 200){
JSONArray response = new JSONArray();
JSONArray couponsList = coupons.getJSONArray("rows");
for (int i = 0; i < couponsList.size(); i++){
JSONObject couponsListJson = couponsList.getJSONObject(i);
if(couponsListJson.getInt("userCouponsStatus") == 0){//0=未领取;1=可用 ; 2 =已过期 ;3=未开始
JSONObject response_couponsList = new JSONObject();
response_couponsList.set("couponsId", couponsListJson.getStr("id"));
response_couponsList.set("couponsName", couponsListJson.getStr("name"));
response_couponsList.set("roomId", couponsListJson.getStr("roomId"));
String discountTime = couponsListJson.getStr("discount");//抵用时长(只能是0.5的整数倍)
int time = Integer.parseInt(discountTime) * 30;
response_couponsList.set("deductionTime", time);
response_couponsList.set("startTime", couponsListJson.getStr("startTime"));
response_couponsList.set("endTime", couponsListJson.getStr("endTime"));
response.set(response_couponsList);
}
}
return response; return response;
}
return null;
}
/**
* 领取一张优惠券
*/
public boolean receiveSpacesCoupons(String sn,String couponId){
JSONObject param = new JSONObject();
String post = cdcHttpUtils.post(receiveSpacesCouponsUrl + "/" + couponId, sn, param.toString());
JSONObject jsonObject = JSONUtil.parseObj(post);
if(jsonObject.getInt("code") == 200){
return true;
}
return false;
}
/**
* 一键领取优惠券
*/
public boolean oneClickClaimCoupon(String sn){
JSONObject param = new JSONObject();
String post = cdcHttpUtils.post(oneClickClaimCouponUrl, sn, param.toString());
JSONObject jsonObject = JSONUtil.parseObj(post);
if(jsonObject.getInt("code") == 200){
return true;
}
return false;
} }
/**
* 获取用户已领取的优惠券列表
*/
public JSONArray getUserCoupons(String sn,String roomId){
String url = getUserCouponsUrl+"?status=0";
if(StrUtil.isNotBlank(roomId)){
url = url+"&roomId="+roomId;
} }
String s = cdcHttpUtils.get(url, sn);
JSONObject coupons = JSONUtil.parseObj(s);
JSONArray response = new JSONArray();
if(coupons.getInt("code") == 200){
JSONArray rows = coupons.getJSONArray("rows");
for (int i = 0; i < rows.size(); i++){
JSONObject coup = rows.getJSONObject(i);
JSONObject coupon_json = new JSONObject();
coupon_json.set("couponsId", coup.getStr("id"));
coupon_json.set("couponsName", coup.getStr("name"));
coupon_json.set("roomId", coup.getStr("roomId"));
String discountTime = coup.getStr("discount");//抵用时长(只能是0.5的整数倍)
int time = Integer.parseInt(discountTime) * 30;
coupon_json.set("deductionTime", time);
coupon_json.set("startTime", coup.getStr("startTime"));
coupon_json.set("endTime", coup.getStr("endTime"));
response.set(coupon_json);
}
return response;
}else{
return null;
}
}
} }
package com.ikonke.konkeaialibabamcp.utils;
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",
"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",
"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 数组中的下标
*
* @param time 输入的时间,格式为 "HH:mm:ss",例如 "13:11:00"
* @return 对应的 time_segment 数组下标
*/
public static int getTimeSegmentIndex(String time) {
// 提取小时和分钟部分
String[] parts = time.split(":");
int hour = Integer.parseInt(parts[0]);
int minute = Integer.parseInt(parts[1]);
// 计算从00:00开始的分钟数
int totalMinutes = hour * 60 + minute;
// 每个时间段是30分钟,计算所属时间段的索引
int index = totalMinutes / 30;
// 确保索引在有效范围内
if (index >= 0 && index < time_segment.length) {
return index;
}
// 如果超出范围,返回 -1 表示未找到
return -1;
}
}
...@@ -17,8 +17,6 @@ spring: ...@@ -17,8 +17,6 @@ spring:
name: konke-ai-alibaba-mcp-server name: konke-ai-alibaba-mcp-server
version: 0.0.1 version: 0.0.1
type: ASYNC # Recommended for reactive applications type: ASYNC # Recommended for reactive applications
# ?? sse ????????? /sse
# ???????? ip:port/sse/mcp
sse-endpoint: /sse sse-endpoint: /sse
sse-message-endpoint: /mcp sse-message-endpoint: /mcp
capabilities: capabilities:
...@@ -46,3 +44,10 @@ cdc: ...@@ -46,3 +44,10 @@ cdc:
getListSpacesRoomUrl: ${cdc.url}/third/screen/spaces/rooms getListSpacesRoomUrl: ${cdc.url}/third/screen/spaces/rooms
getSpacesRoomDetailUrl: ${cdc.url}/third/screen/spaces/room/ getSpacesRoomDetailUrl: ${cdc.url}/third/screen/spaces/room/
getSpacesRoomBookingUrl: ${cdc.url}/third/screen/spaces/room/times getSpacesRoomBookingUrl: ${cdc.url}/third/screen/spaces/room/times
bookingSpacesRoomUrl: ${cdc.url}/third/mini/record
spacesRoomOrderUrl: ${cdc.url}/third/screen/spaces/order/submit
spacesCoupons:
getSpacesCouponsListUrl: ${cdc.url}/third/screen/spaces/coupons/all
receiveSpacesCouponsUrl: ${cdc.url}/third/screen/spaces/coupons/
getUserCouponsUrl: ${cdc.url}/third/screen/spaces/coupons/user
oneClickClaimCouponUrl: ${cdc.url}/third/screen/spaces/coupons/once
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