一、技术架构:四层分布式微服务设计
- 用户端层:采用 Uniapp 跨端框架实现微信小程序/H5/APP 三端统一开发,支持 LBS 定位匹配 3 公里内空闲设备,结合贪心算法按距离 + 评分排序,响应时间从 30 分钟缩短至 2 分钟。
- API 网关层:负责请求路由、流量控制(如 QPS 限流)及 Spring Security 三重认证(手机号 + 微信授权 + 信用分),拦截非法请求。
- 业务微服务层:
- 订单服务:通过 Seata 分布式事务框架处理支付与设备锁定的原子性操作,确保黄金时段 500+ 并发请求下订单成功率 99.9%,采用 Redisson 分布式锁防止设备超卖。
- 设备服务:基于 MQTT 协议与智能洗澡舱、温湿度传感器双向通信,Java 服务端订阅主题
/device/bath/status 实时接收水温、风速数据,延迟<200ms。
- AI 服务:部署 TensorFlow Lite 模型至边缘节点,通过
EmotionRecognitionService 分析宠物表情,焦虑检测(频繁抖毛)时自动调节水温至 28℃并播放α波音乐,皮肤异常检测(红肿/脱毛)时触发健康预警。
- 支撑中间件层:
- Redis 缓存:命中率超 95%,周末高峰期降低数据库查询压力 60%,确保 95% 请求 1.5 秒内完成。
- MongoDB:存储宠物健康档案、服务评价等非结构化数据,支持动态查询。
- RocketMQ 消息队列:解耦订单创建与设备状态更新,异步处理耗时操作。
二、核心功能源码实现
MQTT 通信初始化
public class MqttClientInitializer {
public static MqttClient createClient(String brokerUrl, String clientId) throws MqttException {
MqttClient client = new MqttClient(brokerUrl, clientId);
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
options.setAutomaticReconnect(true);
client.connect(options);
return client;
}
}
AI 情绪识别与控制策略
public {
EmotionResult {
EmotionModel.newInstance();
Tensor<Float> input = TensorImage.fromImage(image);
model.process(input);
model.close();
(result.isAnxious()) {
adjustEnvironment(, );
}
result;
}
}