Merge branch 'dyf-device' into 6170
This commit is contained in:
@ -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() {
|
||||||
@ -45,18 +53,18 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
|
|
||||||
String mainLightMode = convertArr[1].toString();
|
String mainLightMode = convertArr[1].toString();
|
||||||
String batteryRemainingTime = convertArr[2].toString();
|
String batteryRemainingTime = convertArr[2].toString();
|
||||||
if(StringUtils.isNotBlank(mainLightMode)){
|
if (StringUtils.isNotBlank(mainLightMode)) {
|
||||||
log.info("设备离线mainLightMode:{}",mainLightMode);
|
log.info("设备离线mainLightMode:{}", mainLightMode);
|
||||||
if("0".equals(mainLightMode)){
|
if ("0".equals(mainLightMode)) {
|
||||||
|
|
||||||
//设备离线
|
// 设备离线
|
||||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0");
|
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0");
|
||||||
|
|
||||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||||
String messageSendingValue = RedisUtils.getCacheObject(sendMessageIng);
|
String messageSendingValue = RedisUtils.getCacheObject(sendMessageIng);
|
||||||
if("1".equals(messageSendingValue)){
|
if ("1".equals(messageSendingValue)) {
|
||||||
//设置为故障状态
|
// 设置为故障状态
|
||||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "2");
|
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "2");
|
||||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq("device_imei", context.getDeviceImei());
|
updateWrapper.eq("device_imei", context.getDeviceImei());
|
||||||
@ -66,14 +74,15 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
|
|
||||||
// 解除告警
|
// 解除告警
|
||||||
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;
|
||||||
if(RedisUtils.getCacheObject(deviceRedisKey) != null){
|
if (RedisUtils.getCacheObject(deviceRedisKey) != null) {
|
||||||
RedisUtils.deleteObject(deviceRedisKey);
|
RedisUtils.deleteObject(deviceRedisKey);
|
||||||
}
|
}
|
||||||
|
cancelAlarm(context.getDeviceImei());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 发送设备状态和位置信息到Redis
|
// 发送设备状态和位置信息到Redis
|
||||||
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
|
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(), mainLightMode);
|
||||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
||||||
|
|
||||||
// 存储到Redis
|
// 存储到Redis
|
||||||
RedisUtils.setCacheObject(deviceRedisKey, batteryRemainingTime);
|
RedisUtils.setCacheObject(deviceRedisKey, batteryRemainingTime);
|
||||||
@ -90,13 +99,13 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
*
|
*
|
||||||
* @param deviceImei 设备IMEI
|
* @param deviceImei 设备IMEI
|
||||||
*/
|
*/
|
||||||
public void syncSendDeviceDataToRedisWithFuture(String deviceImei,Object convertValue) {
|
public void syncSendDeviceDataToRedisWithFuture(String deviceImei, Object convertValue) {
|
||||||
// CompletableFuture.runAsync(() -> {
|
// CompletableFuture.runAsync(() -> {
|
||||||
//
|
//
|
||||||
// });
|
// });
|
||||||
try {
|
try {
|
||||||
// 将设备状态信息存储到Redis中
|
// 将设备状态信息存储到Redis中
|
||||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_LIGHT_MODE_KEY_PREFIX;
|
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_LIGHT_MODE_KEY_PREFIX;
|
||||||
|
|
||||||
// 存储到Redis
|
// 存储到Redis
|
||||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
|
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
|
||||||
@ -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())) {
|
||||||
@ -814,11 +817,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
if (StringUtils.isNotBlank(device.getDeviceImei())) {
|
if (StringUtils.isNotBlank(device.getDeviceImei())) {
|
||||||
DeviceAlarmVo latestAlarm = deviceAlarmMapper.selectLatestByDeviceImei(device.getDeviceImei());
|
DeviceAlarmVo latestAlarm = deviceAlarmMapper.selectLatestByDeviceImei(device.getDeviceImei());
|
||||||
// 判断是否正在告警:未处理的告警(treatmentState=1)且不是电子围栏告警(deviceAction!=3)
|
// 判断是否正在告警:未处理的告警(treatmentState=1)且不是电子围栏告警(deviceAction!=3)
|
||||||
if (latestAlarm != null &&
|
if (latestAlarm != null &&
|
||||||
latestAlarm.getTreatmentState() != null &&
|
latestAlarm.getTreatmentState() != null &&
|
||||||
latestAlarm.getTreatmentState() == 1 &&
|
latestAlarm.getTreatmentState() == 1 &&
|
||||||
latestAlarm.getDeviceAction() != null &&
|
latestAlarm.getDeviceAction() != null &&
|
||||||
latestAlarm.getDeviceAction() != 3) {
|
latestAlarm.getDeviceAction() != 3) {
|
||||||
vo.setIsAlarming(true);
|
vo.setIsAlarming(true);
|
||||||
} else {
|
} else {
|
||||||
vo.setIsAlarming(false);
|
vo.setIsAlarming(false);
|
||||||
@ -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