diff --git a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusService.java b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusService.java index ad2c298b..b3b3896d 100644 --- a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusService.java +++ b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusService.java @@ -24,250 +24,202 @@ import java.util.List; */ public interface BadgeDeviceStatusService { - // ==================== 状态管理 ==================== + // ==================== 状态管理 ==================== - /** - * 更新工牌设备状态 - *
- * 状态转换会记录状态变更时间和操作原因 - * - * @param deviceId 设备ID - * @param status 目标状态 - * @param operatorId 操作人ID(可为null,表示系统操作) - * @param reason 状态变更原因 - */ - void updateBadgeStatus(Long deviceId, BadgeDeviceStatusEnum status, Long operatorId, String reason); + /** + * 更新工牌设备状态 + *
+ * 状态转换会记录状态变更时间和操作原因
+ *
+ * @param deviceId 设备ID
+ * @param status 目标状态
+ * @param operatorId 操作人ID(可为null,表示系统操作)
+ * @param reason 状态变更原因
+ */
+ void updateBadgeStatus(Long deviceId, BadgeDeviceStatusEnum status, Long operatorId, String reason);
- /**
- * 批量更新工牌设备状态
- *
- * @param deviceIds 设备ID列表
- * @param status 目标状态
- * @param operatorId 操作人ID
- * @param reason 状态变更原因
- */
- void batchUpdateBadgeStatus(List
- * 只返回非 OFFLINE 状态的设备
- *
- * @param areaId 区域ID
- * @return 设备状态DTO列表
- */
- List
+ * 只返回非 OFFLINE 状态的设备
+ *
+ * @param areaId 区域ID
+ * @return 设备状态DTO列表
+ */
+ List
- * 更新最后心跳时间和电量:
- *
+ * 用于处理 IoT 设备状态变更事件和定时对账:
+ *
- * 用于处理 IoT 设备状态变更事件和定时对账:
- *
- * 与 handleHeartbeat 区别:
- * - handleHeartbeat:处理位置上报心跳,包含电量等详细信息
- * - updateBadgeOnlineStatus:仅处理在线/离线状态变更
- *
- * @param deviceId 设备ID
- * @param deviceCode 设备编码
- * @param areaId 区域ID(可为null)
- * @param status 目标状态(IDLE 或 OFFLINE)
- * @param reason 状态变更原因
- */
- void updateBadgeOnlineStatus(Long deviceId, String deviceCode, Long areaId,
- BadgeDeviceStatusEnum status, String reason);
+ /**
+ * 检查工牌设备是否在线(非OFFLINE状态)
+ *
+ * @param deviceId 设备ID
+ * @return 是否在线
+ */
+ boolean isBadgeOnline(Long deviceId);
- // ==================== 在线状态检查 ====================
+ // ==================== 工单关联 ====================
- /**
- * 检查工牌设备是否在线(非OFFLINE状态)
- *
- * @param deviceId 设备ID
- * @return 是否在线
- */
- boolean isBadgeOnline(Long deviceId);
+ /**
+ * 设置当前工单
+ *
+ * @param deviceId 设备ID
+ * @param orderId 工单ID
+ */
+ void setCurrentOrder(Long deviceId, Long orderId);
- /**
- * 检查工牌设备心跳是否超时
- *
- * @param deviceId 设备ID
- * @param thresholdMinutes 超时阈值(分钟)
- * @return 是否超时
- */
- boolean isHeartbeatTimeout(Long deviceId, int thresholdMinutes);
+ /**
+ * 设置当前工单详细信息(原子操作,并发安全)
+ *
+ * 一次性设置工单ID、工单状态、区域ID、信标MAC
+ * 使用 Redis Hash 的 hset() 操作,保证原子性
+ *
+ * @param deviceId 设备ID
+ * @param orderId 工单ID
+ * @param orderStatus 工单状态(DISPATCHED/ARRIVED/PAUSED)
+ * @param areaId 区域ID
+ * @param beaconMac 信标MAC地址(可为null)
+ */
+ void setCurrentOrderInfo(Long deviceId, Long orderId, String orderStatus, Long areaId, String beaconMac);
- /**
- * 检查心跳超时并将超时设备设为OFFLINE
- *
- * 定时任务调用,默认超时时间为30分钟
- */
- void checkAndMarkOfflineDevices();
+ /**
+ * 更新工单状态
+ *
+ * @param deviceId 设备ID
+ * @param orderStatus 工单状态
+ */
+ void updateOrderStatus(Long deviceId, String orderStatus);
- // ==================== 工单关联 ====================
+ /**
+ * 清除当前工单(包括工单ID、工单状态、信标MAC)
+ *
+ * @param deviceId 设备ID
+ */
+ void clearCurrentOrder(Long deviceId);
- /**
- * 设置当前工单
- *
- * @param deviceId 设备ID
- * @param orderId 工单ID
- */
- void setCurrentOrder(Long deviceId, Long orderId);
+ /**
+ * 获取当前有工单的设备列表
+ *
+ * @return 有工单的设备列表
+ */
+ List
- * 一次性设置工单ID、工单状态、区域ID、信标MAC
- * 使用 Redis Hash 的 hset() 操作,保证原子性
- *
- * @param deviceId 设备ID
- * @param orderId 工单ID
- * @param orderStatus 工单状态(DISPATCHED/ARRIVED/PAUSED)
- * @param areaId 区域ID
- * @param beaconMac 信标MAC地址(可为null)
- */
- void setCurrentOrderInfo(Long deviceId, Long orderId, String orderStatus, Long areaId, String beaconMac);
+ // ==================== 区域管理 ====================
- /**
- * 更新工单状态
- *
- * @param deviceId 设备ID
- * @param orderStatus 工单状态
- */
- void updateOrderStatus(Long deviceId, String orderStatus);
+ /**
+ * 更新工牌设备所在区域
+ *
+ * @param deviceId 设备ID
+ * @param areaId 区域ID
+ * @param areaName 区域名称
+ */
+ void updateBadgeArea(Long deviceId, Long areaId, String areaName);
- /**
- * 清除当前工单(包括工单ID、工单状态、信标MAC)
- *
- * @param deviceId 设备ID
- */
- void clearCurrentOrder(Long deviceId);
+ /**
+ * 初始化区域设备索引
+ *
+ * 从 ops_area_device_relation 表加载 BADGE 类型的设备,
+ * 建立区域到设备的索引关系
+ */
+ void initAreaDeviceIndex();
- /**
- * 获取当前有工单的设备列表
- *
- * @return 有工单的设备列表
- */
- List
+ * 重新从数据库加载区域设备关系
+ */
+ void refreshAreaDeviceIndex();
- // ==================== 区域管理 ====================
+ /**
+ * 将设备添加到区域索引
+ *
+ * @param deviceId 设备ID
+ * @param areaId 区域ID
+ */
+ void addToAreaIndex(Long deviceId, Long areaId);
- /**
- * 更新工牌设备所在区域
- *
- * @param deviceId 设备ID
- * @param areaId 区域ID
- * @param areaName 区域名称
- */
- void updateBadgeArea(Long deviceId, Long areaId, String areaName);
+ /**
+ * 从区域索引移除设备
+ *
+ * @param deviceId 设备ID
+ * @param areaId 区域ID
+ */
+ void removeFromAreaIndex(Long deviceId, Long areaId);
- /**
- * 初始化区域设备索引
- *
- * 从 ops_area_device_relation 表加载 BADGE 类型的设备,
- * 建立区域到设备的索引关系
- */
- void initAreaDeviceIndex();
+ // ==================== 设备管理 ====================
- /**
- * 刷新区域设备索引
- *
- * 重新从数据库加载区域设备关系
- */
- void refreshAreaDeviceIndex();
+ /**
+ * 删除工牌设备状态
+ *
+ * @param deviceId 设备ID
+ */
+ void deleteBadgeStatus(Long deviceId);
- /**
- * 将设备添加到区域索引
- *
- * @param deviceId 设备ID
- * @param areaId 区域ID
- */
- void addToAreaIndex(Long deviceId, Long areaId);
-
- /**
- * 从区域索引移除设备
- *
- * @param deviceId 设备ID
- * @param areaId 区域ID
- */
- void removeFromAreaIndex(Long deviceId, Long areaId);
-
- // ==================== 设备管理 ====================
-
- /**
- * 删除工牌设备状态
- *
- * @param deviceId 设备ID
- */
- void deleteBadgeStatus(Long deviceId);
-
- /**
- * 清理所有离线设备的状态
- */
- void clearOfflineBadges();
+ /**
+ * 清理所有离线设备的状态
+ */
+ void clearOfflineBadges();
}
diff --git a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusServiceImpl.java b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusServiceImpl.java
index 92717d0c..fe433d7d 100644
--- a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusServiceImpl.java
+++ b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/badge/BadgeDeviceStatusServiceImpl.java
@@ -7,7 +7,7 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.scheduling.annotation.Scheduled;
+
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@@ -245,80 +245,7 @@ public class BadgeDeviceStatusServiceImpl implements BadgeDeviceStatusService, I
}
}
- // ==================== 心跳处理 ====================
-
- @Override
- public void handleHeartbeat(Long deviceId, String deviceCode, Integer batteryLevel) {
- handleHeartbeatWithArea(deviceId, deviceCode, batteryLevel, null, null);
- }
-
- @Override
- public void handleHeartbeatWithArea(Long deviceId, String deviceCode, Integer batteryLevel,
- Long areaId, String areaName) {
- if (deviceId == null) {
- return;
- }
-
- try {
- String key = BADGE_STATUS_KEY_PREFIX + deviceId;
- Long now = System.currentTimeMillis();
-
- // 获取当前状态
- Map
- *
- *
- * @param deviceId 设备ID
- * @param deviceCode 设备编码
- * @param batteryLevel 电量(0-100)
- */
- void handleHeartbeat(Long deviceId, String deviceCode, Integer batteryLevel);
+ /**
+ * 更新工牌设备在线状态
+ *
+ *
+ *
+ * @param deviceId 设备ID
+ * @param deviceCode 设备编码
+ * @param areaId 区域ID(可为null)
+ * @param status 目标状态(IDLE 或 OFFLINE)
+ * @param reason 状态变更原因
+ */
+ void updateBadgeOnlineStatus(Long deviceId, String deviceCode, Long areaId,
+ BadgeDeviceStatusEnum status, String reason);
- /**
- * 处理工牌设备心跳(带区域信息)
- *
- * @param deviceId 设备ID
- * @param deviceCode 设备编码
- * @param batteryLevel 电量(0-100)
- * @param areaId 当前所在区域ID
- * @param areaName 当前所在区域名称
- */
- void handleHeartbeatWithArea(Long deviceId, String deviceCode, Integer batteryLevel,
- Long areaId, String areaName);
+ // ==================== 在线状态检查 ====================
- /**
- * 更新工牌设备在线状态
- *
- *
- *