|
|
@@ -64,7 +64,7 @@ public class CallbackController {
|
|
|
|
|
|
@Autowired
|
|
|
private OrderService orderService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private DeviceService deviceService;
|
|
|
|
|
|
@@ -162,43 +162,31 @@ public class CallbackController {
|
|
|
try {
|
|
|
String activityId = (String) params.get("activity_id");
|
|
|
String deviceId = (String) params.get("device_id");
|
|
|
- String status = (String) params.get("status");
|
|
|
+ String doorStatus = (String) params.get("status");
|
|
|
String openType = (String) params.get("open_type");
|
|
|
String outUserId = (String) params.get("out_user_id");
|
|
|
|
|
|
log.info("开关门状态通知 - 设备: {}, 状态: {}, 类型: {}, 用户: {}",
|
|
|
- deviceId, status, openType, outUserId);
|
|
|
+ deviceId, doorStatus, openType, outUserId);
|
|
|
|
|
|
// 保存设备状态到Redis,供小程序轮询查询
|
|
|
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", status);
|
|
|
+ statusData.put("status", doorStatus);
|
|
|
statusData.put("openType", openType != null ? openType : "");
|
|
|
statusData.put("userId", outUserId != null ? outUserId : "");
|
|
|
- statusData.put("doorStatus", DeviceDoorStatus.convertToStatus(status));
|
|
|
+ statusData.put("doorStatus", DeviceDoorStatus.convertToStatus(doorStatus));
|
|
|
statusData.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
|
|
|
redisTemplate.opsForHash().putAll(statusKey, statusData);
|
|
|
redisTemplate.expire(statusKey, 30, TimeUnit.MINUTES);
|
|
|
-
|
|
|
- // 同步更新数据库中的门状态
|
|
|
- try {
|
|
|
- String doorStatus = DeviceDoorStatus.convertToStatus(status);
|
|
|
- boolean updated = deviceService.updateDeviceDoorStatus(deviceId, doorStatus);
|
|
|
- if (updated) {
|
|
|
- log.info("数据库门状态更新成功 - 设备: {}, 状态: {}", deviceId, doorStatus);
|
|
|
- } else {
|
|
|
- log.warn("数据库门状态更新失败 - 设备: {}, 状态: {}", deviceId, doorStatus);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("更新数据库门状态异常 - 设备: {}", deviceId, e);
|
|
|
- }
|
|
|
|
|
|
- DeviceDoorStatus doorStatus = DeviceDoorStatus.fromCode(status);
|
|
|
- if (doorStatus != null) {
|
|
|
- switch (doorStatus) {
|
|
|
+
|
|
|
+ DeviceDoorStatus doorStatusEnum = DeviceDoorStatus.fromCode(doorStatus);
|
|
|
+ if (doorStatusEnum != null) {
|
|
|
+ switch (doorStatusEnum) {
|
|
|
case OPENED:
|
|
|
log.info("设备 {} 开门成功", deviceId);
|
|
|
break;
|
|
|
@@ -214,6 +202,18 @@ public class CallbackController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 同步更新数据库中的门状态
|
|
|
+ try {
|
|
|
+ boolean updated = deviceService.updateDeviceDoorStatus(deviceId, doorStatus);
|
|
|
+ if (updated) {
|
|
|
+ log.info("数据库门状态更新成功 - 设备: {}, 状态: {}", deviceId, doorStatus);
|
|
|
+ } else {
|
|
|
+ log.warn("数据库门状态更新失败 - 设备: {}, 状态: {}", deviceId, doorStatus);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新数据库门状态异常 - 设备: {}", deviceId, e);
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理开关门状态通知失败", e);
|
|
|
}
|