设备通道逻辑修改

This commit is contained in:
lxj
2025-07-28 20:27:21 +08:00
parent 5274fb8d64
commit ad567ec13a
8 changed files with 178 additions and 28 deletions

View File

@@ -78,8 +78,8 @@ public class SisDeviceManageController extends BaseController {
@Log(title = "设备管理", businessType = BusinessType.INSERT) @Log(title = "设备管理", businessType = BusinessType.INSERT)
@RepeatSubmit() @RepeatSubmit()
@PostMapping() @PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody SisDeviceManageBo bo) { public R<Boolean> add(@Validated(AddGroup.class) @RequestBody SisDeviceManageBo bo) {
return toAjax(sisDeviceManageService.insertByBo(bo)); return R.ok("设备添加成功", sisDeviceManageService.insertByBo(bo));
} }
/** /**

View File

@@ -1,6 +1,8 @@
package org.dromara.sis.controller.zkmedia; package org.dromara.sis.controller.zkmedia;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.MD5;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.sis.domain.enums.FactoryNoEnum; import org.dromara.sis.domain.enums.FactoryNoEnum;
@@ -48,8 +50,9 @@ public class ZKLmediaController {
public R<AddStreamProxyResp> alarm(@RequestBody @Validated AddStreamProxy data) { public R<AddStreamProxyResp> alarm(@RequestBody @Validated AddStreamProxy data) {
StartStreamProxy proxy = new StartStreamProxy(); StartStreamProxy proxy = new StartStreamProxy();
proxy.setApp("realtime"); proxy.setApp("realtime");
String s = IdUtil.fastSimpleUUID(); // 实时流不用每次都去拉流,流不存在的情况下在拉取
proxy.setStream(s); String streanStr = data.getVideoIp() + "_" + data.getChannelId();
proxy.setStream(SecureUtil.md5(streanStr));
if (FactoryNoEnum.HIK.getCode().equals(data.getFactoryNo())) { if (FactoryNoEnum.HIK.getCode().equals(data.getFactoryNo())) {
proxy.setUrl(String.format(HIK_REALTIME_RTSP_TEMPLATE, data.getAccount(), data.getPwd(), data.getVideoIp(), data.getVideoPort(), data.getChannelId())); proxy.setUrl(String.format(HIK_REALTIME_RTSP_TEMPLATE, data.getAccount(), data.getPwd(), data.getVideoIp(), data.getVideoPort(), data.getChannelId()));
} else if (FactoryNoEnum.DAHUA.getCode().equals(data.getFactoryNo())) { } else if (FactoryNoEnum.DAHUA.getCode().equals(data.getFactoryNo())) {

View File

@@ -74,5 +74,38 @@ public class SisDeviceChannel extends TenantEntity {
*/ */
private String channelNo; private String channelNo;
/**
* nvr 设备id
*/
private Long nvrId;
/**
* nvr 设备厂商编号
*/
private String nvrFactoryNo;
/**
* nvr设备ip
*/
private String nvrIp;
/**
* nvr 端口
*/
private Integer nvrPort;
/**
* nvr 账号
*/
private String nvrAccount;
/**
* nvr 密码
*/
private String nvrPwd;
/**
* nvr 通道编号
*/
private String nvrChannelNo;
} }

View File

@@ -1,13 +1,14 @@
package org.dromara.sis.domain.bo; package org.dromara.sis.domain.bo;
import org.dromara.sis.domain.SisDeviceChannel;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*; import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.sis.domain.SisDeviceChannel;
/** /**
* 设备通道管理业务对象 sis_device_channel * 设备通道管理业务对象 sis_device_channel
@@ -23,13 +24,13 @@ public class SisDeviceChannelBo extends BaseEntity {
/** /**
* 主键id * 主键id
*/ */
@NotNull(message = "主键id不能为空", groups = { EditGroup.class }) @NotNull(message = "主键id不能为空", groups = {EditGroup.class})
private Long id; private Long id;
/** /**
* 设备id * 设备id
*/ */
@NotNull(message = "设备id不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "设备id不能为空", groups = {AddGroup.class, EditGroup.class})
private Long deviceId; private Long deviceId;
/** /**
@@ -42,31 +43,31 @@ public class SisDeviceChannelBo extends BaseEntity {
/** /**
* 通道分组组id * 通道分组组id
*/ */
@NotNull(message = "通道分组组id不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "通道分组组id不能为空", groups = {AddGroup.class, EditGroup.class})
private Long groupId; private Long groupId;
/** /**
* 设备ip * 设备ip
*/ */
@NotBlank(message = "设备ip不能为空", groups = { AddGroup.class, EditGroup.class }) @NotBlank(message = "设备ip不能为空", groups = {AddGroup.class, EditGroup.class})
private String deviceIp; private String deviceIp;
/** /**
* 设备端口 * 设备端口
*/ */
@NotNull(message = "设备端口不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "设备端口不能为空", groups = {AddGroup.class, EditGroup.class})
private Integer devicePort; private Integer devicePort;
/** /**
* 设备账号 * 设备账号
*/ */
@NotBlank(message = "设备账号不能为空", groups = { AddGroup.class, EditGroup.class }) @NotBlank(message = "设备账号不能为空", groups = {AddGroup.class, EditGroup.class})
private String deviceAccount; private String deviceAccount;
/** /**
* 设备密码 * 设备密码
*/ */
@NotBlank(message = "设备密码不能为空", groups = { AddGroup.class, EditGroup.class }) @NotBlank(message = "设备密码不能为空", groups = {AddGroup.class, EditGroup.class})
private String devicePwd; private String devicePwd;
/** /**
@@ -79,5 +80,41 @@ public class SisDeviceChannelBo extends BaseEntity {
*/ */
private String channelNo; private String channelNo;
/**
* nvr 设备id
*/
private Long nvrId;
/**
* nvr 设备厂商编号
*/
private String nvrFactoryNo;
/**
* nvr设备ip
*/
private String nvrIp;
/**
* nvr 端口
*/
private Integer nvrPort;
/**
* nvr 账号
*/
private String nvrAccount;
/**
* nvr 密码
*/
private String nvrPwd;
/**
* nvr 通道编号
*/
private String nvrChannelNo;
} }

View File

@@ -90,5 +90,38 @@ public class SisDeviceChannelVo implements Serializable {
@ExcelProperty(value = "设备通道编号") @ExcelProperty(value = "设备通道编号")
private String channelNo; private String channelNo;
/**
* nvr 设备id
*/
private Long nvrId;
/**
* nvr 设备厂商编号
*/
private String nvrFactoryNo;
/**
* nvr设备ip
*/
private String nvrIp;
/**
* nvr 端口
*/
private Integer nvrPort;
/**
* nvr 账号
*/
private String nvrAccount;
/**
* nvr 密码
*/
private String nvrPwd;
/**
* nvr 通道编号
*/
private String nvrChannelNo;
} }

View File

@@ -1,6 +1,7 @@
package org.dromara.sis.sdk.hik.model; package org.dromara.sis.sdk.hik.model;
import lombok.Data; import lombok.Data;
import org.dromara.sis.domain.enums.FactoryNoEnum;
import java.util.List; import java.util.List;
@@ -27,6 +28,8 @@ public class DeviceInfo {
*/ */
private Integer dwStartDChan; private Integer dwStartDChan;
private String factoryNo = FactoryNoEnum.HIK.getCode();
private List<DeviceChannelInfo> channelInfo; private List<DeviceChannelInfo> channelInfo;
@Data @Data

View File

@@ -89,9 +89,12 @@ public interface ISisDeviceChannelService {
/** /**
* 通过设备ids 删除设备通道信息 * 通过设备ids 删除设备通道信息
*
* @param deviceIds 设备ids * @param deviceIds 设备ids
* @return 返回删除数量 * @return 返回删除数量
*/ */
Integer deleteByDeviceIds(List<Long> deviceIds); Integer deleteByDeviceIds(List<Long> deviceIds);
SisDeviceChannel queryByChannelIp(String channelIp);
} }

View File

@@ -1,6 +1,7 @@
package org.dromara.sis.service.impl; package org.dromara.sis.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -24,6 +25,7 @@ import org.dromara.sis.sdk.hik.HikSdkConstans;
import org.dromara.sis.sdk.hik.model.DeviceInfo; import org.dromara.sis.sdk.hik.model.DeviceInfo;
import org.dromara.sis.service.ISisDeviceChannelService; import org.dromara.sis.service.ISisDeviceChannelService;
import org.dromara.sis.service.ISisDeviceGroupService; import org.dromara.sis.service.ISisDeviceGroupService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@@ -194,6 +196,7 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
return TreeUtils.build(treeNodes, -1L); return TreeUtils.build(treeNodes, -1L);
} }
@Async
@Override @Override
public Boolean handleHikDeviceChannel(SisDeviceManageBo bo) { public Boolean handleHikDeviceChannel(SisDeviceManageBo bo) {
// 调用hik sdk登录 // 调用hik sdk登录
@@ -219,23 +222,51 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
} else if (DeviceTypeEnum.NVR.getType().equals(bo.getDeviceType()) || DeviceTypeEnum.DVR.getType().equals(bo.getDeviceType())) { } else if (DeviceTypeEnum.NVR.getType().equals(bo.getDeviceType()) || DeviceTypeEnum.DVR.getType().equals(bo.getDeviceType())) {
DeviceInfo channelInfo = HikApiService.getInstance().getChannelInfo(bo.getDeviceIp()); DeviceInfo channelInfo = HikApiService.getInstance().getChannelInfo(bo.getDeviceIp());
if (channelInfo != null && CollUtil.isNotEmpty(channelInfo.getChannelInfo())) { if (channelInfo != null && CollUtil.isNotEmpty(channelInfo.getChannelInfo())) {
List<SisDeviceChannel> channels = new ArrayList<>(channelInfo.getChannelInfo().size()); List<SisDeviceChannel> insertChannels = new ArrayList<>(channelInfo.getChannelInfo().size());
List<SisDeviceChannel> updateChannels = new ArrayList<>(channelInfo.getChannelInfo().size());
channelInfo.getChannelInfo().forEach(item -> { channelInfo.getChannelInfo().forEach(item -> {
SisDeviceChannel channel = new SisDeviceChannel(); // 校验通道信息是否存在
channel.setDeviceId(bo.getId()); SisDeviceChannel channel = queryByChannelIp(item.getChannelIp());
channel.setGroupId(bo.getGroupId()); boolean isUpdate = true;
channel.setDeviceIp(bo.getDeviceIp()); if (channel == null) {
channel.setDevicePort(HikSdkConstans.DEFAULT_RTSP_PORT); channel = new SisDeviceChannel();
channel.setFactoryNo(bo.getFactoryNo()); isUpdate = false;
channel.setDeviceAccount(bo.getDeviceAccount()); }
channel.setDevicePwd(bo.getDevicePwd()); // 通道设备信息
channel.setDeviceMac(bo.getDeviceMac()); channel.setDeviceIp(item.getChannelIp());
channel.setDevicePort(Integer.valueOf(item.getChannelPort()));
channel.setDeviceAccount(item.getChannelAccount());
channel.setFactoryNo(channelInfo.getFactoryNo());
if (StrUtil.isNotEmpty(item.getChannelPwd())) {
channel.setDevicePwd(item.getChannelPwd());
}
// nvr 设备信息
channel.setNvrId(bo.getId());
channel.setNvrIp(bo.getDeviceIp());
channel.setNvrPort(HikSdkConstans.DEFAULT_RTSP_PORT);
channel.setNvrAccount(bo.getDeviceAccount());
channel.setNvrPwd(bo.getDevicePwd());
channel.setNvrFactoryNo(bo.getFactoryNo());
// 系统设备信息
channel.setDeviceMac(bo.getDeviceMac());
channel.setGroupId(bo.getGroupId());
channel.setChannelName(item.getChannelName()); channel.setChannelName(item.getChannelName());
channel.setChannelNo(item.getChannelId() + HikSdkConstans.DEFAULT_CHANNEL_PREFX); channel.setChannelNo(item.getChannelId() + HikSdkConstans.DEFAULT_CHANNEL_PREFX);
channels.add(channel); if (isUpdate) {
updateChannels.add(channel);
} else {
insertChannels.add(channel);
}
}); });
this.baseMapper.insertBatch(channels); // 更新通道信息
if (CollUtil.isNotEmpty(updateChannels)) {
this.baseMapper.updateBatchById(updateChannels);
}
// 写入新的通道信息
if (CollUtil.isNotEmpty(insertChannels)) {
this.baseMapper.insertBatch(updateChannels);
}
} }
return true; return true;
} else { } else {
@@ -244,6 +275,13 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
return false; return false;
} }
@Override
public SisDeviceChannel queryByChannelIp(String channelIp) {
LambdaQueryWrapper<SisDeviceChannel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SisDeviceChannel::getDeviceIp, channelIp);
return baseMapper.selectOne(queryWrapper);
}
@Override @Override
public Integer deleteByDeviceIds(List<Long> deviceIds) { public Integer deleteByDeviceIds(List<Long> deviceIds) {
LambdaQueryWrapper<SisDeviceChannel> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SisDeviceChannel> lqw = new LambdaQueryWrapper<>();