This commit is contained in:
dy
2025-09-15 22:31:28 +08:00
9 changed files with 74 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
package org.dromara.sis.api;
import org.dromara.sis.api.domain.DeviceStateInfo;
import org.dromara.sis.api.domain.RemoteSdkChannel;
import org.dromara.sis.api.domain.RemoteSisDeviceManage;
@@ -15,6 +16,15 @@ public interface RemoteHikSdkService {
*/
Boolean deviceLogin(RemoteSisDeviceManage item);
/**
* 海康sdk 登录操作
*
* @param item 登录参数
* @return 是否登录成功
*/
DeviceStateInfo checkState(RemoteSisDeviceManage item);
/**
* 获取nvr设备通道信息
*

View File

@@ -0,0 +1,26 @@
package org.dromara.sis.api.domain;
import lombok.Data;
import java.util.Date;
@Data
public class DeviceStateInfo {
/**
* 设备是否在线 0 在线1离线
*/
private Integer online;
/**
* 最新的心跳时间
*/
private Date heartbeat;
/**
* 设备状态吗
*/
private Integer deviceState;
}

View File

@@ -263,7 +263,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
boolean isDaytime = hour > 8 && hour <= 20;
BigDecimal threshold = isDaytime ? info.getDayWarning() : info.getNightWarning();
// 如果阈值为0则不处理阈值不为0且读数大于阈值自动上报
if (threshold.compareTo(BigDecimal.ZERO) != 0 && record.getCurrentReading().compareTo(threshold) > 0) {
if (threshold.compareTo(BigDecimal.ZERO) != 0 && (record.getCurrentReading().subtract(record.getPreviousReading())).compareTo(threshold) > 0) {
// 根据仪表类型设置工单名称和类型
String orderName = "能耗异常";
Long orderType = 0L;

View File

@@ -2,6 +2,7 @@ package org.dromara.sis.domain.bo.alarm;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.sis.domain.enums.EventSmallTypeEnum;
/**
* 任务指派参数
@@ -62,4 +63,7 @@ public class AlarmAssignmentBo {
* 任务指派操作人员部门id
*/
private Long modifyDeptId;
private EventSmallTypeEnum smallType;
}

View File

@@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.sis.api.RemoteHikSdkService;
import org.dromara.sis.api.domain.DeviceStateInfo;
import org.dromara.sis.api.domain.RemoteSdkChannel;
import org.dromara.sis.api.domain.RemoteSisDeviceManage;
import org.dromara.sis.domain.covert.CommonBeanCovert;
@@ -28,6 +29,14 @@ public class RemoteSdkServiceImpl implements RemoteHikSdkService {
return hikApiService.login(item.getDeviceIp(), item.getDevicePort().shortValue(), item.getDeviceAccount(), item.getDevicePwd(), item.getDeviceType());
}
@Override
public DeviceStateInfo checkState(RemoteSisDeviceManage item) {
if (item == null) {
throw new RuntimeException("设备信息为null");
}
return hikApiService.checkState(item.getDeviceIp(), item.getDevicePort().shortValue(), item.getDeviceAccount(), item.getDevicePwd(), item.getDeviceType());
}
@Override
public List<RemoteSdkChannel> getDeviceChannel(String deviceIp) {
DeviceInfo channelInfo = hikApiService.getChannelInfo(deviceIp);

View File

@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sis.api.domain.DeviceStateInfo;
import org.dromara.sis.config.HikEqpConfig;
import org.dromara.sis.sdk.zkmedia.model.R;
import org.springframework.stereotype.Component;
@@ -23,6 +24,7 @@ public class HikApiService {
private HikEqpConfig hikEqpConfig;
private static final String LOGIN_URI = "login";
private static final String CHECK_STATE_URI = "check/state";
private static final String LOGOUT_URI = "logout";
private static final String CHANNEL_LIST = "channel/list";
private static final String FACE_UPLOAD = "flib/add";
@@ -69,6 +71,17 @@ public class HikApiService {
return request(LOGIN_URI, params.toJSONString(), Boolean.class);
}
public DeviceStateInfo checkState(String ip, short port, String user, String psw, Integer deviceType) {
JSONObject params = new JSONObject();
params.put("deviceIp", ip);
params.put("devicePort", port);
params.put("deviceAccount", user);
params.put("devicePassword", psw);
params.put("deviceType", deviceType);
return request(CHECK_STATE_URI, params.toJSONString(), DeviceStateInfo.class);
}
public Boolean loginOut(String deviceIp) {
JSONObject params = new JSONObject();
params.put("deviceIp", deviceIp);

View File

@@ -233,7 +233,7 @@ public class EventAlarmReportServiceImpl implements IEventAlarmReportService {
ls.add(bigImg);
// 生成告警记录
SisAlarmEvents alarmRecord = alarmEventsService.createAlarmRecord(deviceIp, level, smallType, desc, ls);
autoAssign(alarmRecord.getId(), deviceIp);
autoAssign(alarmRecord.getId(), deviceIp, smallType);
}
/**
@@ -246,11 +246,11 @@ public class EventAlarmReportServiceImpl implements IEventAlarmReportService {
private void handleAlarm(String deviceIp, byte[] img, Integer level, EventSmallTypeEnum smallType, String desc) {
// 生成告警记录
SisAlarmEvents alarmRecord = alarmEventsService.createAlarmRecord(deviceIp, level, smallType, desc, List.of(img));
autoAssign(alarmRecord.getId(), deviceIp);
autoAssign(alarmRecord.getId(), deviceIp, smallType);
}
private void autoAssign(Long alarmId, String deviceIp) {
private void autoAssign(Long alarmId, String deviceIp, EventSmallTypeEnum smallType) {
SaTokenContextMockUtil.setMockContext(() -> {
// 如果当前设备区域存在排班人员,那么惊醒自动指派操作
List<RemoteAttendanceUserGroupVo> userGroupVos = remoteAttendanceService.queryAttendByCurrDateAndDeviceIp(new Date(), deviceIp);
@@ -277,6 +277,7 @@ public class EventAlarmReportServiceImpl implements IEventAlarmReportService {
bo.setSolveDeptId(userInfo.getDeptId());
bo.setSolvePhone(userInfo.getPhonenumber());
bo.setSolveEmail(userInfo.getEmail());
bo.setSmallType(smallType);
bo.setRemark("系统自动指派");
alarmEventsService.taskAssignment(bo);
});

View File

@@ -330,7 +330,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
log.info("事件处理信息写入完成,result= {}", insert);
// 进行消息推送
String title = "视频预警";
String content = "您有一条" + sisAlarmEvents.getSolveName() + "预警数据";
String content = "您有一条" + bo.getSmallType().getDesc() + "预警数据";
webSocketMessageService.pushMobileMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, title, content, JSONObject.toJSONString(sisAlarmEvents));
return true;
}

View File

@@ -13,6 +13,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.sis.api.RemoteDeviceService;
import org.dromara.sis.api.RemoteHikSdkService;
import org.dromara.sis.api.domain.DeviceStateInfo;
import org.dromara.sis.api.domain.RemoteSdkChannel;
import org.dromara.sis.api.domain.RemoteSisDeviceChannel;
import org.dromara.sis.api.domain.RemoteSisDeviceManage;
@@ -170,18 +171,17 @@ public class HikDeviceCheckStateTask {
public void updateDeviceStatus(RemoteSisDeviceManage item) {
log.info("开始同步设备状态,params={}", item);
// 调用设备登录验证次设备在线
Boolean isLogin = remoteHikSdkService.deviceLogin(item);
int onLineState = isLogin ? 1 : 0;
if (!Objects.equals(item.getDeviceStatus(), onLineState)) {
SnailJobLog.REMOTE.info("设备[{}]在线状态变更,开始更新状态。 old={}new ={} ", item.getDeviceIp(), item.getDeviceStatus(), onLineState);
item.setDeviceStatus(onLineState);
DeviceStateInfo stateInfo = remoteHikSdkService.checkState(item);
if (!Objects.equals(item.getDeviceStatus(), stateInfo.getDeviceState())) {
SnailJobLog.REMOTE.info("设备[{}]在线状态变更,开始更新状态。 old={}new ={} ", item.getDeviceIp(), item.getDeviceStatus(), stateInfo.getDeviceState());
item.setDeviceStatus(stateInfo.getDeviceState());
Boolean result = remoteDeviceService.updateDeviceState(item);
SnailJobLog.REMOTE.info("设备[{}]在线状态变更,状态更新完成。 result={} ", item.getDeviceIp(), result);
// 监测当前设备是否存在通道,如果有则跟新通道信息
List<RemoteSisDeviceChannel> ls = remoteDeviceService.queryDeviceChannels(item.getDeviceIp());
if (CollUtil.isNotEmpty(ls)) {
Boolean r1 = remoteDeviceService.updateDeviceChannelState(item.getDeviceIp(), onLineState);
Boolean r1 = remoteDeviceService.updateDeviceChannelState(item.getDeviceIp(), stateInfo.getDeviceState());
SnailJobLog.REMOTE.info("设备通道[{}]在线状态变更,状态更新完成。 result={} ", item.getDeviceIp(), r1);
}
}