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

开始对接建发社区

parent bc7a7251
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
- 访客邀请 - 访客邀请
通过智慧屏/APP/小程序的AI语音交互,可实现访客邀请。访客到达社区后,无感通过社区出入口,联动道闸开启。 通过智慧屏/APP/小程序的AI语音交互,可实现访客邀请。访客到达社区后,无感通过社区出入口,联动道闸开启。
- 智能会所管理 - 智能会所管理
通过智慧屏/APP/小程序的AI语音交互,可实现会所空间的快捷预约管理,提高会所利用率与运维效率,提升业主满意度 通过智慧屏/APP/小程序的AI语音交互,可实现会所空间的快捷预约管理,提高会所利用率与运维效率,提升业主满意度
1、查 小区功能区列表(/third/screen/spaces/rooms) 1、查 小区功能区列表(/third/screen/spaces/rooms)
2、查询可预约时间 2、查询可预约时间
2、预约付钱订单---->成功或失败 2、预约付钱订单---->成功或失败
3、成功--->生产支付二维码-->支付 3、成功--->生产支付二维码-->支付
4、支付成功后---->提交订单(新)/third/screen/spaces/order/submit 4、支付成功后---->提交订单(新)/third/screen/spaces/order/submit
- 机器人联动 - 机器人联动
通过智慧屏/APP/小程序的AI语音交互,可实现配送机器人/收垃圾机器人快捷预约上门服务,实现更加便捷下单,并支持语音对话。 通过智慧屏/APP/小程序的AI语音交互,可实现配送机器人/收垃圾机器人快捷预约上门服务,实现更加便捷下单,并支持语音对话。
- 社区活动推荐 - 社区活动推荐
...@@ -30,3 +30,9 @@ ...@@ -30,3 +30,9 @@
- 设置模式 - 设置模式
- 设置风速 - 设置风速
- -
package com.ikonke.konkeaialibabamcp; package com.ikonke.konkeaialibabamcp;
import com.ikonke.konkeaialibabamcp.aitools.DeviceTools; import com.ikonke.konkeaialibabamcp.aitools.DeviceTools;
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;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@MapperScan("com.ikonke.konkeaialibabamcp.mapper.mysql")
@SpringBootApplication @SpringBootApplication
public class KonkeAiAlibabaMcpApplication { public class KonkeAiAlibabaMcpApplication {
......
package com.ikonke.konkeaialibabamcp.config;
import cn.hutool.json.JSONNull;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.boot.jackson.JsonComponent;
import java.io.IOException;
@JsonComponent
public class JsonNullSerizlizer extends JsonSerializer<JSONNull> {
@Override
public void serialize(JSONNull jsonNull, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeNull();
}
}
package com.ikonke.konkeaialibabamcp.controller;
import cn.hutool.json.JSONArray;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils;
import com.ikonke.konkeaialibabamcp.service.cdc.spaces.SpacesService;
import com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@Slf4j
@RestController
@RequestMapping("/cdc")
public class CDCController {
@Autowired
private ICDCTokenService tokenService;
@Autowired
private SpacesService spacesService;
@GetMapping("/synCDCToken")
public boolean synCDCToken(@RequestParam(name = "token") String token,
@RequestParam(name = "sn") String sn,
@RequestParam(name = "ccuName") String ccuName){
log.info("synCDCToken..同步CDCToken..token:{},sn:{},ccuName:{}",token,sn,ccuName);
CDCToken bySn = tokenService.findBySn(sn);
if(bySn==null){
bySn = new CDCToken();
bySn.setSn(sn);
bySn.setAccessToken(token);
bySn.setState(CDCToken.STATE_ENABLED);
bySn.setCcuId(ccuName);
bySn.setCreateTime(LocalDateTime.now());
tokenService.save(bySn);
}else{
CdcHttpUtils.CDCTokenCache.remove(sn);
bySn.setAccessToken(token);
bySn.setRefreshToken(bySn.getAccessToken());
bySn.setState(CDCToken.STATE_ENABLED);
bySn.setCreateTime(LocalDateTime.now());
bySn.setCcuId(ccuName);
tokenService.updateById(bySn);
}
return true;
}
@GetMapping("/getSpacesList")
public JSONArray getSpacesList(@RequestParam(name = "sn") String sn){
log.info("getSpacesList..获取空间列表..sn:{}",sn);
return spacesService.findAll(sn);
}
}
package com.ikonke.konkeaialibabamcp.entity.mysql;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@TableName("`cdc_token`")
public class CDCToken implements Serializable {
@Serial
private static final long serialVersionUID = -1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("sn")
private String sn;
@TableField("ccuId")
private String ccuId;
@TableField("accessToken")
private String accessToken;
@TableField("refreshToken")
private String refreshToken;
@TableField("createTime")
private LocalDateTime createTime;
@TableField("state")
private Integer state;
public static final Integer STATE_DISABLED = 0; // 不可用
public static final Integer STATE_ENABLED = 1; // 可用
}
package com.ikonke.konkeaialibabamcp.mapper.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface CDCTokenMapper extends BaseMapper<CDCToken> {
@Select("SELECT * FROM cdc_token WHERE sn = #{sn}")
CDCToken findBySn(@Param("sn") String sn);
@Select("SELECT * FROM cdc_token WHERE sn = #{sn} and `state` = #{state}")
CDCToken findBySnAndState(@Param("sn") String sn, @Param("state") Integer state);
}
...@@ -3,6 +3,7 @@ package com.ikonke.konkeaialibabamcp.mapper.mysql; ...@@ -3,6 +3,7 @@ package com.ikonke.konkeaialibabamcp.mapper.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ikonke.konkeaialibabamcp.entity.mysql.SynDevice; import com.ikonke.konkeaialibabamcp.entity.mysql.SynDevice;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
...@@ -10,9 +11,10 @@ import java.util.List; ...@@ -10,9 +11,10 @@ import java.util.List;
@Mapper @Mapper
public interface SynDeviceMapper extends BaseMapper<SynDevice> { public interface SynDeviceMapper extends BaseMapper<SynDevice> {
List<SynDevice> findByCcu(String ccuName); @Select("SELECT * FROM syn_device WHERE ccuId = #{ccuId}")
List<SynDevice> findByCcu(@Param("ccuId")String ccuId);
@Select("SELECT * FROM syn_device WHERE deviceName LIKE CONCAT('%',#{deviceName},'%') AND roomName LIKE CONCAT('%',#{roomName},'%')") @Select("SELECT * FROM syn_device WHERE deviceName LIKE CONCAT('%',#{deviceName},'%') AND roomName LIKE CONCAT('%',#{roomName},'%')")
List<SynDevice> findByDeviceNameAndRoomName(String deviceName, String roomName); List<SynDevice> findByDeviceNameAndRoomName(@Param("deviceName")String deviceName, @Param("roomName")String roomName);
} }
package com.ikonke.konkeaialibabamcp.service.cdc;
import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ikonke.konkeaialibabamcp.entity.cdc.UserEntity;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class CdcHttpUtils {
public static Cache<String, String> CDCTokenCache = CacheUtil.newLRUCache(1024);
@Value("${cdc.getOwnerUrl}")
private String getOwnerUrl;
@Value("${cdc.timeout}")
private Integer timeout;
@Autowired
private ICDCTokenService tokenService;
/**
* 获取用户信息
*
*/
public UserEntity getOwner(CDCToken bySn){
String body = HttpRequest.get(getOwnerUrl)
.header("X-token", bySn.getAccessToken())
.header("gateway-id", bySn.getSn())
.timeout(timeout)
.execute().body();
if(CDCTokenCache.get(bySn.getSn())!=null){
String s = CDCTokenCache.get(bySn.getSn());
return JSONUtil.toBean(s, UserEntity.class);
}else{
JSONObject jsonObject = JSONUtil.parseObj(body);
if(jsonObject.getInt("code") == 200){
UserEntity userEntity = JSONUtil.toBean(jsonObject.getJSONObject("data"), UserEntity.class);
CDCTokenCache.put(bySn.getSn(),jsonObject.getJSONObject("data").toString());
return userEntity;
}else{
return null;
}
}
}
/**
* get请求
*/
public String get(String url, String sn) {
long start = System.currentTimeMillis();
log.info("建发get请求:url:{},sn:{}",url, sn);
CDCToken bySn = tokenService.findBySn(sn);
UserEntity userEntity = getOwner(bySn);
String body = HttpRequest.get(url)
.header("X-token",bySn.getAccessToken())
.header("gateway-id",sn)
.header("space-yr",userEntity.communityId)
.header("communityId",userEntity.communityId)
.header("space-phone",userEntity.phoneNum)
.header("gateway",sn)
.header("roomId",userEntity.roomInfo.roomId)
.header("easId",userEntity.easId)
.timeout(20000)//超时,毫秒
.execute().body();
log.info("建发get请求结果:url:{},sn:{},body:{},耗时:{}",url, sn,body,System.currentTimeMillis()-start);
return body;
}
public String post(String url, String sn,String body) {
long start = System.currentTimeMillis();
log.info("建发post请求:url:{},sn:{},body:{}",url, sn,body);
CDCToken bySn = tokenService.findBySn(sn);
UserEntity userEntity = getOwner(bySn);
String result = HttpRequest.post(url)
.header("X-token",bySn.getAccessToken())
.header("gateway-id",sn)
.header("space-yr",userEntity.communityId)
.header("communityId",userEntity.communityId)
.header("space-phone",userEntity.phoneNum)
.header("gateway",sn)
.header("roomId",userEntity.roomInfo.roomId)
.header("easId",userEntity.easId)
.body(body)
.timeout(20000)
.execute().body();
log.info("建发post请求结果:url:{},sn:{},body:{},耗时:{}",url, sn,result,System.currentTimeMillis()-start);
return result;
}
}
package com.ikonke.konkeaialibabamcp.service.cdc.spaces;
import cn.hutool.core.exceptions.StatefulException;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ikonke.konkeaialibabamcp.service.cdc.CdcHttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class SpacesService {
@Value("${cdc.url}")
private String cdcUrl;
@Value("${cdc.getListSpacesRoomUrl}")
private String getListSpacesRoomUrl;
@Value("${cdc.getSpacesRoomDetailUrl}")
private String getSpacesRoomDetailUrl;
@Value("${cdc.getSpacesRoomBookingUrl}")
private String getSpacesRoomBookingUrl;
@Autowired
private CdcHttpUtils cdcHttpUtils;
// 查询所有空间
public JSONArray findAll(String sn) {
// 小区功能区列表
String s = cdcHttpUtils.get(getListSpacesRoomUrl, sn);
JSONObject spacesJson = new JSONObject(s);
if(spacesJson.getInt("code") != 200){
throw new StatefulException(51, "查询会所空间列表失败");
}else{
JSONArray data = spacesJson.getJSONArray("data");
JSONArray spacesList = data.getJSONArray(1);
JSONArray response = new JSONArray();
for( int i = 0; i < spacesList.size(); i++){
JSONObject response_spaces = new JSONObject();
JSONObject jsonObject = spacesList.getJSONObject(i);
String status = jsonObject.getStr("status");//0=正常;1=维护中(任何时段都不可预定)
String name = jsonObject.getStr("name");//空间名
String type = jsonObject.getStr("type");//1=共享型,2=独占式,3=仅展示,4=跳转小程序
String id = jsonObject.getStr("id");
Integer main_userCount = jsonObject.getInt("userCount");//当前里面的用户数,每日凌晨改成0
if(main_userCount==null){
main_userCount = 0;
}
String subspaceType = jsonObject.getStr("subspaceType");//0:单独空间 1:内分子空间
response_spaces.set("场所ID",id);
response_spaces.set("场所名称",name);
response_spaces.set("当前场所里面的用户数",main_userCount);
if("0".equals(status) && ("1".equals(type) || "2".equals(type)) && "1".equals(subspaceType)){
//查详情-子空间
String s1 = cdcHttpUtils.get(getSpacesRoomDetailUrl + id, sn);
JSONObject spacesRoomDetailJson = JSONUtil.parseObj(s1);
if(spacesRoomDetailJson.getInt("code") == 200){
JSONObject result = spacesRoomDetailJson.getJSONObject("data");
Integer userCount = result.getInt("userCount");//当前里面的用户数,每日凌晨改成0
if(userCount == null){
userCount = 0;
}
Integer maxUser = result.getInt("maxUser");//推荐使用最多人数
JSONArray subspacePd = result.getJSONArray("subspacePd");//子空间
JSONArray child = new JSONArray();
for( int j = 0; j < subspacePd.size(); j++){
JSONObject jsonObject1 = subspacePd.getJSONObject(j);
String subspacePdName = jsonObject1.getStr("name");
String subspacePdId = jsonObject1.getStr("id");
JSONObject childJsonObject = new JSONObject();
childJsonObject.set("房间名称", subspacePdName);
childJsonObject.set("房间ID", subspacePdId);
childJsonObject.set("当前房间里面的用户数", userCount);
child.set(childJsonObject);
}
response_spaces.set("subspacePd", child);
}
}
response.set(response_spaces);
}
return response;
}
}
}
package com.ikonke.konkeaialibabamcp.service.mysqlservice;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
public interface ICDCTokenService extends IService<CDCToken> {
CDCToken findBySn(String sn);
CDCToken findBySn(String sn,Integer state);
}
package com.ikonke.konkeaialibabamcp.service.mysqlservice.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikonke.konkeaialibabamcp.entity.mysql.CDCToken;
import com.ikonke.konkeaialibabamcp.mapper.mysql.CDCTokenMapper;
import com.ikonke.konkeaialibabamcp.service.mysqlservice.ICDCTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ICDCTokenServiceImpl extends ServiceImpl<CDCTokenMapper, CDCToken> implements ICDCTokenService {
@Autowired
private CDCTokenMapper cdcTokenMapper;
@Override
public CDCToken findBySn(String sn) {
return baseMapper.findBySn(sn);
}
@Override
public CDCToken findBySn(String sn,Integer state) {
return baseMapper.findBySnAndState(sn, state);
}
}
...@@ -27,6 +27,10 @@ spring: ...@@ -27,6 +27,10 @@ spring:
prompt: true prompt: true
completion: true completion: true
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
type-aliases-package: com.ikonke.konkeaialibabamcp.entity.mysql
konke: konke:
weather: weather:
clientId: da4c19db2be64671 clientId: da4c19db2be64671
...@@ -34,3 +38,11 @@ konke: ...@@ -34,3 +38,11 @@ konke:
appId: 10001304 appId: 10001304
appKey: 0c350d82-aa95-46e1-91b8-b8d508b5226a appKey: 0c350d82-aa95-46e1-91b8-b8d508b5226a
baseUrl: http://172.17.12.6:10000 baseUrl: http://172.17.12.6:10000
cdc:
timeout: 20000
url: http://community.jfzhtest.com/prod-api
getOwnerUrl: ${cdc.url}/system/screen/owner/info
getListSpacesRoomUrl: ${cdc.url}/third/screen/spaces/rooms
getSpacesRoomDetailUrl: ${cdc.url}/third/screen/spaces/room/
getSpacesRoomBookingUrl: ${cdc.url}/third/screen/spaces/room/times
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