设备告警
This commit is contained in:
@ -3,6 +3,7 @@ package com.fuyuanshen;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动程序
|
* 启动程序
|
||||||
@ -10,6 +11,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
public class DromaraApplication {
|
public class DromaraApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -57,13 +57,12 @@ public class BjqAlarmRule implements MqttMessageRule {
|
|||||||
if (StringUtils.isNotBlank(convertValue)) {
|
if (StringUtils.isNotBlank(convertValue)) {
|
||||||
// 将设备状态信息存储到Redis中
|
// 将设备状态信息存储到Redis中
|
||||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
|
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
|
||||||
// 存储到Redis
|
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue);
|
|
||||||
if ("1".equals(convertValue)) {
|
if ("1".equals(convertValue)) {
|
||||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
|
||||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||||
|
// 存储到Redis
|
||||||
|
RedisUtils.setCacheObject(deviceRedisKey, "1");
|
||||||
}else if ("0".equals(convertValue)){
|
}else if ("0".equals(convertValue)){
|
||||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
|
||||||
RedisUtils.deleteObject(sendMessageIng);
|
RedisUtils.deleteObject(sendMessageIng);
|
||||||
RedisUtils.deleteObject(deviceRedisKey);
|
RedisUtils.deleteObject(deviceRedisKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.fuyuanshen.global.queue;// ScheduledTasks.java
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||||
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
|
import com.fuyuanshen.equipment.domain.Device;
|
||||||
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||||
|
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||||
|
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class OnlineStatusTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DeviceMapper deviceMapper;
|
||||||
|
// 使用cron表达式,每分钟的第0秒执行
|
||||||
|
@Scheduled(cron = "0 */3 * * * ?")
|
||||||
|
public void cronTask() {
|
||||||
|
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||||
|
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||||
|
devices.forEach(item -> {
|
||||||
|
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||||
|
String status = RedisUtils.getCacheObject(onlineStatusKey);
|
||||||
|
String onlineStatus = item.getOnlineStatus()==null?"0" : item.getOnlineStatus().toString();
|
||||||
|
if("1".equals(onlineStatus) || "2".equals(onlineStatus)){
|
||||||
|
if(StringUtils.isBlank(status) || "0".equals(status)){
|
||||||
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("id", item.getId());
|
||||||
|
updateWrapper.set("online_status", 0);
|
||||||
|
deviceMapper.update(updateWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user