自动关上锁
parent
3774c4dc4d
commit
05039238cc
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue