自动关上锁

feasure
xce 2026-01-19 00:51:07 +08:00
parent 3774c4dc4d
commit 05039238cc
1 changed files with 9 additions and 0 deletions

View File

@ -561,6 +561,15 @@ public class MqttMessageHandler implements SmartLifecycle {
}
if (current != null && current == 1) {
// 新增:自动关也走分布式锁(避免与前端并发控制同一功能导致乱序/互相覆盖)
String lockKey = "lock:" + deviceId + ":" + funcType;
Boolean lockSuccess = stringRedisTemplate.opsForValue().setIfAbsent(
lockKey, "autooff", 15, TimeUnit.SECONDS
);
if (lockSuccess == null || !lockSuccess) {
log.info("【自动关任务】{}功能忙锁占用跳过自动关闭deviceId={}, funcType={}", funcType, deviceId, funcType);
return;
}
JSONObject down = new JSONObject();
down.put(funcType, 0);