在线状态修改2

This commit is contained in:
2025-09-13 15:51:34 +08:00
parent 41eb3d9a33
commit 64c81ac44e
2 changed files with 23 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate;
import com.baomidou.lock.executor.RedissonLockExecutor;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
@ -69,10 +70,16 @@ public class RedisKeyExpirationListener implements MessageListener {
if (lockInfo != null) {
try {
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("device_imei", element);
deviceUpdateWrapper.set("online_status", 0);
deviceMapper.update(deviceUpdateWrapper);
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("device_imei", element);
queryWrapper.eq("online_status", 0);
Long count = deviceMapper.selectCount(queryWrapper);
if(count == 0){
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("device_imei", element);
deviceUpdateWrapper.set("online_status", 0);
deviceMapper.update(deviceUpdateWrapper);
}
} finally {
//释放锁
lockTemplate.releaseLock(lockInfo);

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.global.queue;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.domain.Device;
@ -92,13 +93,17 @@ public class MqttMessageConsumer {
String threadName = Thread.currentThread().getName();
try {
log.info("业务处理线程 {} 开始处理消息: {}", threadName, message);
// 实现具体的业务逻辑
// 例如更新数据库、发送通知等
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("device_imei", message)
.set("online_status", 1);
deviceMapper.update(updateWrapper);
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("device_imei", message);
queryWrapper.eq("online_status", 1);
Long count = deviceMapper.selectCount(queryWrapper);
if(count == 0){
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("device_imei", message)
.set("online_status", 1);
deviceMapper.update(updateWrapper);
}
// 模拟业务处理耗时
// Thread.sleep(200);