|
|
@@ -125,6 +125,11 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
Object onlineObj = params.get("is_online");
|
|
|
Integer isOnline = parseInteger(onlineObj);
|
|
|
|
|
|
+ if (isOnline == null) {
|
|
|
+ log.warn("设备在线状态为空 - 设备: {}", deviceId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
log.info("设备在线状态通知 - 设备: {}, 在线状态: {}", deviceId, isOnline == 1 ? "在线" : "离线");
|
|
|
|
|
|
String onlineKey = "device:online:" + deviceId;
|
|
|
@@ -142,6 +147,11 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
Object voiceObj = params.get("voice");
|
|
|
Integer voice = parseInteger(voiceObj);
|
|
|
|
|
|
+ if (voice == null) {
|
|
|
+ log.warn("音量值为空 - 设备: {}", deviceId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
log.info("音量调节结果通知 - 设备: {}, 音量值: {}", deviceId, voice);
|
|
|
|
|
|
String voiceKey = "device:voice:" + deviceId;
|
|
|
@@ -298,34 +308,42 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
}
|
|
|
|
|
|
private void saveDeviceStatusToRedis(String deviceId, String activityId, String doorStatus, String openType, String outUserId) {
|
|
|
- String statusKey = DEVICE_STATUS_KEY + deviceId;
|
|
|
- Map<String, String> statusData = new HashMap<>();
|
|
|
- statusData.put("deviceId", deviceId);
|
|
|
- statusData.put("activityId", activityId != null ? activityId : "");
|
|
|
- statusData.put("status", doorStatus);
|
|
|
- statusData.put("openType", openType != null ? openType : "");
|
|
|
- statusData.put("userId", outUserId != null ? outUserId : "");
|
|
|
- statusData.put("doorStatus", DeviceDoorStatus.convertToStatus(doorStatus));
|
|
|
- statusData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
-
|
|
|
- stringRedisTemplate.opsForHash().putAll(statusKey, statusData);
|
|
|
- stringRedisTemplate.expire(statusKey, 30, TimeUnit.MINUTES);
|
|
|
+ try {
|
|
|
+ String statusKey = DEVICE_STATUS_KEY + deviceId;
|
|
|
+ Map<String, String> statusData = new HashMap<>();
|
|
|
+ statusData.put("deviceId", deviceId != null ? deviceId : "");
|
|
|
+ statusData.put("activityId", activityId != null ? activityId : "");
|
|
|
+ statusData.put("status", doorStatus != null ? doorStatus : "");
|
|
|
+ statusData.put("openType", openType != null ? openType : "");
|
|
|
+ statusData.put("userId", outUserId != null ? outUserId : "");
|
|
|
+ statusData.put("doorStatus", doorStatus != null ? DeviceDoorStatus.convertToStatus(doorStatus) : "");
|
|
|
+ statusData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+
|
|
|
+ stringRedisTemplate.opsForHash().putAll(statusKey, statusData);
|
|
|
+ stringRedisTemplate.expire(statusKey, 30, TimeUnit.MINUTES);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存设备状态到Redis失败 - deviceId: {}", deviceId, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void saveRecognizeResultToRedis(String activityId, Map<String, Object> params) {
|
|
|
- String resultKey = RECOGNIZE_RESULT_KEY + activityId;
|
|
|
- Map<String, String> recognizeData = new HashMap<>();
|
|
|
- recognizeData.put("activityId", activityId != null ? activityId : "");
|
|
|
- recognizeData.put("deviceId", (String) params.get("device_id"));
|
|
|
- recognizeData.put("userId", (String) params.get("out_user_id"));
|
|
|
- recognizeData.put("nobuy", params.get("nobuy") != null ? String.valueOf(params.get("nobuy")) : "0");
|
|
|
- recognizeData.put("result", (String) params.get("result"));
|
|
|
- recognizeData.put("skuList", (String) params.get("sku_list"));
|
|
|
- recognizeData.put("resourceInfo", (String) params.get("resource_info"));
|
|
|
- recognizeData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
-
|
|
|
- stringRedisTemplate.opsForHash().putAll(resultKey, recognizeData);
|
|
|
- stringRedisTemplate.expire(resultKey, 30, TimeUnit.MINUTES);
|
|
|
+ try {
|
|
|
+ String resultKey = RECOGNIZE_RESULT_KEY + activityId;
|
|
|
+ Map<String, String> recognizeData = new HashMap<>();
|
|
|
+ recognizeData.put("activityId", activityId != null ? activityId : "");
|
|
|
+ recognizeData.put("deviceId", params.get("device_id") != null ? String.valueOf(params.get("device_id")) : "");
|
|
|
+ recognizeData.put("userId", params.get("out_user_id") != null ? String.valueOf(params.get("out_user_id")) : "");
|
|
|
+ recognizeData.put("nobuy", params.get("nobuy") != null ? String.valueOf(params.get("nobuy")) : "0");
|
|
|
+ recognizeData.put("result", params.get("result") != null ? String.valueOf(params.get("result")) : "");
|
|
|
+ recognizeData.put("skuList", params.get("sku_list") != null ? String.valueOf(params.get("sku_list")) : "");
|
|
|
+ recognizeData.put("resourceInfo", params.get("resource_info") != null ? String.valueOf(params.get("resource_info")) : "");
|
|
|
+ recognizeData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+
|
|
|
+ stringRedisTemplate.opsForHash().putAll(resultKey, recognizeData);
|
|
|
+ stringRedisTemplate.expire(resultKey, 30, TimeUnit.MINUTES);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存识别结果到Redis失败 - activityId: {}", activityId, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void saveOrderInfoToRedis(Order order, String activityId) {
|
|
|
@@ -352,18 +370,22 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
}
|
|
|
|
|
|
private void saveOrderInfoToRedis(Order order, String activityId, String orderId, Object orderMoney, String orderDetail) {
|
|
|
- String orderKey = ORDER_INFO_KEY + activityId;
|
|
|
- Map<String, String> orderData = new HashMap<>();
|
|
|
- orderData.put("orderId", orderId != null ? orderId : "");
|
|
|
- orderData.put("activityId", activityId != null ? activityId : "");
|
|
|
- orderData.put("deviceId", order.getDeviceId() != null ? order.getDeviceId() : "");
|
|
|
- orderData.put("userId", order.getUserId() != null ? order.getUserId().toString() : "");
|
|
|
- orderData.put("totalAmount", orderMoney != null ? orderMoney.toString() : "0");
|
|
|
- orderData.put("products", orderDetail != null ? orderDetail : "");
|
|
|
- orderData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
-
|
|
|
- stringRedisTemplate.opsForHash().putAll(orderKey, orderData);
|
|
|
- stringRedisTemplate.expire(orderKey, 30, TimeUnit.MINUTES);
|
|
|
+ try {
|
|
|
+ String orderKey = ORDER_INFO_KEY + activityId;
|
|
|
+ Map<String, String> orderData = new HashMap<>();
|
|
|
+ orderData.put("orderId", orderId != null ? orderId : "");
|
|
|
+ orderData.put("activityId", activityId != null ? activityId : "");
|
|
|
+ orderData.put("deviceId", order.getDeviceId() != null ? order.getDeviceId() : "");
|
|
|
+ orderData.put("userId", order.getUserId() != null ? order.getUserId().toString() : "");
|
|
|
+ orderData.put("totalAmount", orderMoney != null ? orderMoney.toString() : "0");
|
|
|
+ orderData.put("products", orderDetail != null ? orderDetail : "");
|
|
|
+ orderData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+
|
|
|
+ stringRedisTemplate.opsForHash().putAll(orderKey, orderData);
|
|
|
+ stringRedisTemplate.expire(orderKey, 30, TimeUnit.MINUTES);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存订单信息到Redis失败 - activityId: {}", activityId, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void updateDeviceDoorStatus(String deviceId, String doorStatus) {
|