Compare commits
3 Commits
840c4fd68f
...
9f0155a6e3
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f0155a6e3 | |||
| 6c99cef65d | |||
| dc0fe96652 |
@ -1,11 +1,16 @@
|
|||||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||||
|
import com.fuyuanshen.common.core.utils.date.DurationUtils;
|
||||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
import com.fuyuanshen.equipment.domain.Device;
|
import com.fuyuanshen.equipment.domain.Device;
|
||||||
|
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
||||||
import com.fuyuanshen.equipment.service.DeviceService;
|
import com.fuyuanshen.equipment.service.DeviceService;
|
||||||
|
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
|
||||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||||
@ -16,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||||
@ -31,6 +37,8 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
|||||||
public class BjqModeRule implements MqttMessageRule {
|
public class BjqModeRule implements MqttMessageRule {
|
||||||
|
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
|
private final IDeviceAlarmService deviceAlarmService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandType() {
|
public String getCommandType() {
|
||||||
@ -69,6 +77,7 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
if (RedisUtils.getCacheObject(deviceRedisKey) != null) {
|
if (RedisUtils.getCacheObject(deviceRedisKey) != null) {
|
||||||
RedisUtils.deleteObject(deviceRedisKey);
|
RedisUtils.deleteObject(deviceRedisKey);
|
||||||
}
|
}
|
||||||
|
cancelAlarm(context.getDeviceImei());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 发送设备状态和位置信息到Redis
|
// 发送设备状态和位置信息到Redis
|
||||||
@ -107,5 +116,29 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解除告警
|
||||||
|
*
|
||||||
|
* @param deviceImei 设备IMEI
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void cancelAlarm(String deviceImei) {
|
||||||
|
DeviceAlarmVo deviceAlarmVo = deviceAlarmService.queryLatestByDeviceImei(deviceImei);
|
||||||
|
DeviceAlarmBo deviceAlarmBo = new DeviceAlarmBo();
|
||||||
|
if (deviceAlarmVo != null) {
|
||||||
|
if (deviceAlarmVo.getFinishTime() == null) {
|
||||||
|
BeanUtil.copyProperties(deviceAlarmVo, deviceAlarmBo);
|
||||||
|
deviceAlarmBo.setFinishTime(new Date());
|
||||||
|
String durationBetween = DurationUtils.getDurationBetween(deviceAlarmVo.getStartTime(), deviceAlarmBo.getFinishTime());
|
||||||
|
deviceAlarmBo.setDurationTime(durationBetween);
|
||||||
|
// 0已处理,1未处理
|
||||||
|
deviceAlarmBo.setTreatmentState(0);
|
||||||
|
// 告警状态,0 解除告警, 1 告警中
|
||||||
|
deviceAlarmBo.setAlarmState(0);
|
||||||
|
deviceAlarmService.updateByBo(deviceAlarmBo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,6 +163,8 @@ public class Device extends TenantEntity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 在线状态(0离线,1在线,2异常)
|
* 在线状态(0离线,1在线,2异常)
|
||||||
|
* online_status
|
||||||
*/
|
*/
|
||||||
private Integer onlineStatus;
|
private Integer onlineStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,8 @@ public class DeviceQueryCriteria extends BaseEntity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备在线状态
|
* 设备在线状态
|
||||||
* 0:离线;1:在线
|
* 0:离线;1:在线;2:故障
|
||||||
|
* online_status
|
||||||
*/
|
*/
|
||||||
private Integer onlineStatus;
|
private Integer onlineStatus;
|
||||||
|
|
||||||
|
|||||||
@ -342,6 +342,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
|
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id);
|
DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id);
|
||||||
|
if (deviceAssignment == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Device device = deviceMapper.selectById(deviceAssignment.getDeviceId());
|
Device device = deviceMapper.selectById(deviceAssignment.getDeviceId());
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(deviceAssignment.getAssigneeName())) {
|
if (StringUtils.isNotEmpty(deviceAssignment.getAssigneeName())) {
|
||||||
@ -834,5 +837,4 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,9 @@
|
|||||||
<if test="criteria.deviceStatus != null">
|
<if test="criteria.deviceStatus != null">
|
||||||
and da.active = #{criteria.deviceStatus}
|
and da.active = #{criteria.deviceStatus}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="criteria.onlineStatus != null">
|
||||||
|
and d.online_status = #{criteria.onlineStatus}
|
||||||
|
</if>
|
||||||
<if test="criteria.groupId != null">
|
<if test="criteria.groupId != null">
|
||||||
and d.group_id = #{criteria.groupId}
|
and d.group_id = #{criteria.groupId}
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user