|
@@ -3,14 +3,22 @@ package com.haha.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.haha.common.constant.OrderConstants;
|
|
|
|
|
+import com.haha.entity.Device;
|
|
|
|
|
+import com.haha.entity.Order;
|
|
|
|
|
+import com.haha.mapper.DeviceMapper;
|
|
|
import com.haha.service.HahaCallbackService;
|
|
import com.haha.service.HahaCallbackService;
|
|
|
import com.haha.service.OrderService;
|
|
import com.haha.service.OrderService;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
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.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -18,9 +26,19 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private OrderService orderService;
|
|
private OrderService orderService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
@Value("${haha.api.app-secret}")
|
|
@Value("${haha.api.app-secret}")
|
|
|
private String appSecret;
|
|
private String appSecret;
|
|
|
|
|
+
|
|
|
|
|
+ private static final String DEVICE_STATUS_KEY = "haha:device:status:";
|
|
|
|
|
+ private static final String RECOGNIZE_RESULT_KEY = "haha:recognize:result:";
|
|
|
|
|
+ private static final String ORDER_INFO_KEY = "haha:order:info:";
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void handleMessage(Map<String, Object> params) {
|
|
public void handleMessage(Map<String, Object> params) {
|
|
@@ -55,27 +73,44 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void handleDeviceStatus(Map<String, Object> params) {
|
|
public void handleDeviceStatus(Map<String, Object> params) {
|
|
|
try {
|
|
try {
|
|
|
String deviceId = (String) params.get("device_id");
|
|
String deviceId = (String) params.get("device_id");
|
|
|
String status = (String) params.get("status");
|
|
String status = (String) params.get("status");
|
|
|
String openType = (String) params.get("open_type");
|
|
String openType = (String) params.get("open_type");
|
|
|
|
|
+ String activityId = (String) params.get("activity_id");
|
|
|
|
|
+ String userId = (String) params.get("user_id");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("开关门状态通知 - 设备: {}, 状态: {}, 类型: {}, 活动: {}, 用户: {}",
|
|
|
|
|
+ deviceId, status, openType, activityId, userId);
|
|
|
|
|
|
|
|
- log.info("开关门状态通知 - 设备: {}, 状态: {}, 类型: {}", deviceId, status, openType);
|
|
|
|
|
|
|
+ // 保存设备状态到Redis,供小程序轮询
|
|
|
|
|
+ String statusKey = DEVICE_STATUS_KEY + deviceId;
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(statusKey, JSON.toJSONString(params), 30, TimeUnit.MINUTES);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新设备表中的门状态字段
|
|
|
|
|
+ updateDeviceDoorStatus(deviceId, status);
|
|
|
|
|
|
|
|
switch (status) {
|
|
switch (status) {
|
|
|
case "2": // OPENED
|
|
case "2": // OPENED
|
|
|
log.info("设备 {} 开门成功", deviceId);
|
|
log.info("设备 {} 开门成功", deviceId);
|
|
|
|
|
+ handleDeviceOpened(deviceId, activityId, userId, openType);
|
|
|
break;
|
|
break;
|
|
|
case "3": // CLOSED
|
|
case "3": // CLOSED
|
|
|
log.info("设备 {} 关门成功,等待AI识别", deviceId);
|
|
log.info("设备 {} 关门成功,等待AI识别", deviceId);
|
|
|
|
|
+ handleDeviceClosed(deviceId, activityId, userId);
|
|
|
break;
|
|
break;
|
|
|
case "1": // ERROR
|
|
case "1": // ERROR
|
|
|
log.error("设备 {} 开门失败", deviceId);
|
|
log.error("设备 {} 开门失败", deviceId);
|
|
|
|
|
+ handleDeviceError(deviceId, activityId, userId);
|
|
|
break;
|
|
break;
|
|
|
case "4": // ANOTHER
|
|
case "4": // ANOTHER
|
|
|
log.warn("设备 {} 繁忙", deviceId);
|
|
log.warn("设备 {} 繁忙", deviceId);
|
|
|
|
|
+ handleDeviceBusy(deviceId, activityId, userId);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ log.warn("未知的设备状态: {}", status);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理开关门状态通知逻辑失败", e);
|
|
log.error("处理开关门状态通知逻辑失败", e);
|
|
@@ -90,6 +125,11 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
Integer isOnline = onlineObj instanceof Integer ? (Integer) onlineObj : Integer.valueOf(onlineObj.toString());
|
|
Integer isOnline = onlineObj instanceof Integer ? (Integer) onlineObj : Integer.valueOf(onlineObj.toString());
|
|
|
|
|
|
|
|
log.info("设备在线状态通知 - 设备: {}, 在线状态: {}", deviceId, isOnline == 1 ? "在线" : "离线");
|
|
log.info("设备在线状态通知 - 设备: {}, 在线状态: {}", deviceId, isOnline == 1 ? "在线" : "离线");
|
|
|
|
|
+
|
|
|
|
|
+ // 更新设备在线状态到缓存
|
|
|
|
|
+ String onlineKey = "device:online:" + deviceId;
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(onlineKey, isOnline.toString(), 10, TimeUnit.MINUTES);
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理设备在线状态通知逻辑失败", e);
|
|
log.error("处理设备在线状态通知逻辑失败", e);
|
|
|
}
|
|
}
|
|
@@ -103,6 +143,11 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
Integer voice = voiceObj instanceof Integer ? (Integer) voiceObj : Integer.valueOf(voiceObj.toString());
|
|
Integer voice = voiceObj instanceof Integer ? (Integer) voiceObj : Integer.valueOf(voiceObj.toString());
|
|
|
|
|
|
|
|
log.info("音量调节结果通知 - 设备: {}, 音量值: {}", deviceId, voice);
|
|
log.info("音量调节结果通知 - 设备: {}, 音量值: {}", deviceId, voice);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存音量设置到缓存
|
|
|
|
|
+ String voiceKey = "device:voice:" + deviceId;
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(voiceKey, voice.toString(), 30, TimeUnit.DAYS);
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理音量调节结果通知逻辑失败", e);
|
|
log.error("处理音量调节结果通知逻辑失败", e);
|
|
|
}
|
|
}
|
|
@@ -115,8 +160,16 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
Object statusObj = params.get("status");
|
|
Object statusObj = params.get("status");
|
|
|
Integer status = statusObj instanceof Integer ? (Integer) statusObj : Integer.valueOf(statusObj.toString());
|
|
Integer status = statusObj instanceof Integer ? (Integer) statusObj : Integer.valueOf(statusObj.toString());
|
|
|
String name = (String) params.get("name");
|
|
String name = (String) params.get("name");
|
|
|
|
|
+ String auditRemark = (String) params.get("audit_remark");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("新品审核结果 - ID: {}, 商品名: {}, 状态: {}, 备注: {}", id, name, status, auditRemark);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存审核结果到缓存
|
|
|
|
|
+ String auditKey = "product:audit:" + id;
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(auditKey, JSON.toJSONString(params), 7, TimeUnit.DAYS);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 根据审核状态更新商品信息或通知相关人员
|
|
|
|
|
|
|
|
- log.info("新品审核结果 - ID: {}, 商品名: {}, 状态: {}", id, name, status);
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理新品审核结果通知逻辑失败", e);
|
|
log.error("处理新品审核结果通知逻辑失败", e);
|
|
|
}
|
|
}
|
|
@@ -129,6 +182,13 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
if (listObj instanceof JSONArray) {
|
|
if (listObj instanceof JSONArray) {
|
|
|
JSONArray list = (JSONArray) listObj;
|
|
JSONArray list = (JSONArray) listObj;
|
|
|
log.info("商品合并结果通知 - 合并数量: {}", list.size());
|
|
log.info("商品合并结果通知 - 合并数量: {}", list.size());
|
|
|
|
|
+
|
|
|
|
|
+ // 保存合并结果到缓存
|
|
|
|
|
+ String mergeKey = "product:merge:" + System.currentTimeMillis();
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(mergeKey, list.toJSONString(), 1, TimeUnit.DAYS);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 处理商品合并逻辑,如更新商品关联关系
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理商品合并结果通知逻辑失败", e);
|
|
log.error("处理商品合并结果通知逻辑失败", e);
|
|
@@ -136,20 +196,31 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void handleOrcResult(Map<String, Object> params) {
|
|
public void handleOrcResult(Map<String, Object> params) {
|
|
|
try {
|
|
try {
|
|
|
String activityId = (String) params.get("activity_id");
|
|
String activityId = (String) params.get("activity_id");
|
|
|
String deviceId = (String) params.get("device_id");
|
|
String deviceId = (String) params.get("device_id");
|
|
|
|
|
+ String userId = (String) params.get("user_id");
|
|
|
Object nobuyObj = params.get("nobuy");
|
|
Object nobuyObj = params.get("nobuy");
|
|
|
Integer nobuy = nobuyObj instanceof Integer ? (Integer) nobuyObj : Integer.valueOf(nobuyObj.toString());
|
|
Integer nobuy = nobuyObj instanceof Integer ? (Integer) nobuyObj : Integer.valueOf(nobuyObj.toString());
|
|
|
|
|
+ String resourceInfoStr = (String) params.get("resource_info");
|
|
|
|
|
+ Object confidenceObj = params.get("confidence");
|
|
|
|
|
+ BigDecimal confidence = confidenceObj != null ? new BigDecimal(confidenceObj.toString()) : null;
|
|
|
|
|
+
|
|
|
|
|
+ // 保存识别结果到Redis
|
|
|
|
|
+ String recognizeKey = RECOGNIZE_RESULT_KEY + activityId;
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(recognizeKey, JSON.toJSONString(params), 30, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
if (nobuy == 1) {
|
|
if (nobuy == 1) {
|
|
|
log.info("AI识别结果: 用户未消费 (activityId: {})", activityId);
|
|
log.info("AI识别结果: 用户未消费 (activityId: {})", activityId);
|
|
|
|
|
+ handleNoPurchase(activityId, deviceId, userId);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 解析识别结果
|
|
// 解析识别结果
|
|
|
String resultStr = (String) params.get("result");
|
|
String resultStr = (String) params.get("result");
|
|
|
|
|
+ String skuListStr = (String) params.get("skuList");
|
|
|
JSONObject result = JSON.parseObject(resultStr);
|
|
JSONObject result = JSON.parseObject(resultStr);
|
|
|
JSONArray excepts = result.getJSONArray("excepts");
|
|
JSONArray excepts = result.getJSONArray("excepts");
|
|
|
|
|
|
|
@@ -157,18 +228,193 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
log.warn("识别结果包含异常 (activityId: {}): {}", activityId, excepts.toJSONString());
|
|
log.warn("识别结果包含异常 (activityId: {}): {}", activityId, excepts.toJSONString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- log.info("AI识别结果通知处理完成 - 设备: {}, 活动: {}", deviceId, activityId);
|
|
|
|
|
|
|
+ log.info("AI识别结果通知处理完成 - 设备: {}, 活动: {}, 用户: {}", deviceId, activityId, userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建订单
|
|
|
|
|
+ Order order = orderService.createOrderFromRecognition(
|
|
|
|
|
+ activityId, deviceId, userId, skuListStr, resourceInfoStr, confidence);
|
|
|
|
|
|
|
|
- // TODO: 调用 orderService 计算金额并生成订单
|
|
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ log.info("AI识别订单创建成功 - 订单ID: {}, 金额: {}", order.getId(), order.getTotalAmount());
|
|
|
|
|
+
|
|
|
|
|
+ // 保存订单信息到Redis供小程序查询
|
|
|
|
|
+ saveOrderInfoToRedis(order, activityId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("处理AI识别结果逻辑失败", e);
|
|
log.error("处理AI识别结果逻辑失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理设备开门成功
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleDeviceOpened(String deviceId, String activityId, String userId, String openType) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("处理设备开门成功 - 设备: {}, 活动: {}, 用户: {}, 类型: {}",
|
|
|
|
|
+ deviceId, activityId, userId, openType);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新相关订单状态为进行中
|
|
|
|
|
+ if (activityId != null && userId != null) {
|
|
|
|
|
+ Order order = orderService.lambdaQuery()
|
|
|
|
|
+ .eq(Order::getActivityId, activityId)
|
|
|
|
|
+ .eq(Order::getUserId, Long.parseLong(userId))
|
|
|
|
|
+ .eq(Order::getStatus, OrderConstants.STATUS_PENDING_PAYMENT)
|
|
|
|
|
+ .orderByDesc(Order::getCreateTime)
|
|
|
|
|
+ .last("LIMIT 1")
|
|
|
|
|
+ .one();
|
|
|
|
|
+
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ order.setStatus(OrderConstants.STATUS_PENDING_PAYMENT);
|
|
|
|
|
+ order.setPayStatus(OrderConstants.PAY_STATUS_UNPAID);
|
|
|
|
|
+ orderService.updateById(order);
|
|
|
|
|
+ log.info("更新订单状态为待支付: orderNo={}", order.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理设备开门成功逻辑失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理设备关门
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleDeviceClosed(String deviceId, String activityId, String userId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("处理设备关门 - 设备: {}, 活动: {}, 用户: {}", deviceId, activityId, userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 触发AI识别流程
|
|
|
|
|
+ // 实际的AI识别由哈哈平台处理,我们只需等待ORC_RESULT回调
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理设备关门逻辑失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理设备错误
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleDeviceError(String deviceId, String activityId, String userId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.error("处理设备错误 - 设备: {}, 活动: {}, 用户: {}", deviceId, activityId, userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 取消相关订单
|
|
|
|
|
+ if (activityId != null && userId != null) {
|
|
|
|
|
+ Order order = orderService.lambdaQuery()
|
|
|
|
|
+ .eq(Order::getActivityId, activityId)
|
|
|
|
|
+ .eq(Order::getUserId, Long.parseLong(userId))
|
|
|
|
|
+ .eq(Order::getStatus, OrderConstants.STATUS_PENDING_PAYMENT)
|
|
|
|
|
+ .orderByDesc(Order::getCreateTime)
|
|
|
|
|
+ .last("LIMIT 1")
|
|
|
|
|
+ .one();
|
|
|
|
|
+
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ order.setStatus(OrderConstants.STATUS_CANCELLED);
|
|
|
|
|
+ order.setPayStatus(OrderConstants.PAY_STATUS_UNPAID);
|
|
|
|
|
+ orderService.updateById(order);
|
|
|
|
|
+ log.info("取消订单due to设备错误: orderNo={}", order.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理设备错误逻辑失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理设备繁忙
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleDeviceBusy(String deviceId, String activityId, String userId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.warn("处理设备繁忙 - 设备: {}, 活动: {}, 用户: {}", deviceId, activityId, userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 通知用户设备繁忙,建议重试
|
|
|
|
|
+ // TODO: 发送消息通知给用户
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理设备繁忙逻辑失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理用户未消费情况
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleNoPurchase(String activityId, String deviceId, String userId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("处理用户未消费 - 活动: {}, 设备: {}, 用户: {}", activityId, deviceId, userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 取消相关订单
|
|
|
|
|
+ if (activityId != null && userId != null) {
|
|
|
|
|
+ Order order = orderService.lambdaQuery()
|
|
|
|
|
+ .eq(Order::getActivityId, activityId)
|
|
|
|
|
+ .eq(Order::getUserId, Long.parseLong(userId))
|
|
|
|
|
+ .eq(Order::getStatus, OrderConstants.STATUS_PENDING_PAYMENT)
|
|
|
|
|
+ .orderByDesc(Order::getCreateTime)
|
|
|
|
|
+ .last("LIMIT 1")
|
|
|
|
|
+ .one();
|
|
|
|
|
+
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ order.setStatus(OrderConstants.STATUS_CANCELLED);
|
|
|
|
|
+ order.setPayStatus(OrderConstants.PAY_STATUS_UNPAID);
|
|
|
|
|
+ orderService.updateById(order);
|
|
|
|
|
+ log.info("取消订单due to用户未消费: orderNo={}", order.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理用户未消费逻辑失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存订单信息到Redis供小程序查询
|
|
|
|
|
+ */
|
|
|
|
|
+ private void saveOrderInfoToRedis(Order order, String activityId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String orderKey = ORDER_INFO_KEY + activityId;
|
|
|
|
|
+ JSONObject orderJson = new JSONObject();
|
|
|
|
|
+ orderJson.put("orderId", order.getId());
|
|
|
|
|
+ orderJson.put("orderNo", order.getOrderNo());
|
|
|
|
|
+ orderJson.put("activityId", activityId);
|
|
|
|
|
+ orderJson.put("deviceId", order.getDeviceId());
|
|
|
|
|
+ orderJson.put("userId", order.getUserId());
|
|
|
|
|
+ orderJson.put("totalAmount", order.getTotalAmount());
|
|
|
|
|
+ orderJson.put("items", order.getItems());
|
|
|
|
|
+ orderJson.put("status", order.getStatus());
|
|
|
|
|
+ orderJson.put("payStatus", order.getPayStatus());
|
|
|
|
|
+ orderJson.put("createTime", order.getCreateTime());
|
|
|
|
|
+ orderJson.put("timestamp", System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(orderKey, orderJson.toJSONString(), 30, TimeUnit.MINUTES);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("保存订单信息到Redis失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新设备门状态
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateDeviceDoorStatus(String deviceId, String doorStatus) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Device device = deviceMapper.selectByDeviceId(deviceId);
|
|
|
|
|
+ if (device != null) {
|
|
|
|
|
+ device.setDoorStatus(doorStatus);
|
|
|
|
|
+ deviceMapper.updateById(device);
|
|
|
|
|
+ log.info("更新设备 {} 门状态为: {}", deviceId, doorStatus);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("未找到设备: {}", deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("更新设备门状态失败 - 设备: {}, 状态: {}", deviceId, doorStatus, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean validateSign(Map<String, Object> params) {
|
|
public boolean validateSign(Map<String, Object> params) {
|
|
|
// TODO: 实现具体的签名验证逻辑
|
|
// TODO: 实现具体的签名验证逻辑
|
|
|
|
|
+ // 建议使用HMAC-SHA256算法,结合appSecret进行签名验证
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|