Compare commits

...

4 Commits

Author SHA1 Message Date
lxj
ef7ca1fa5a 设备通道逻辑修改
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2025-07-30 05:46:35 +08:00
lxj
1b3fd18873 Merge branch 'master' of http://47.109.37.87:3000/by2025/SmartParks 2025-07-30 05:43:08 +08:00
lxj
0efbb1051e Merge branch 'master' of http://47.109.37.87:3000/by2025/SmartParks 2025-07-28 20:27:35 +08:00
lxj
ad567ec13a 设备通道逻辑修改 2025-07-28 20:27:21 +08:00
12 changed files with 224 additions and 71 deletions

View File

@@ -15,6 +15,7 @@ import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType; import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController; import org.dromara.common.web.core.BaseController;
import org.dromara.sis.domain.bo.SisDeviceManageBo; import org.dromara.sis.domain.bo.SisDeviceManageBo;
import org.dromara.sis.domain.vo.SisDeviceManageVo; import org.dromara.sis.domain.vo.SisDeviceManageVo;
@@ -78,8 +79,9 @@ 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)); bo.setTenantId(LoginHelper.getTenantId());
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,6 +74,7 @@ public class ZkMediaHookController {
@PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8") @PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
public HookResult onStreamNotFound(@RequestBody OnStreamNotFoundHookParam param) { public HookResult onStreamNotFound(@RequestBody OnStreamNotFoundHookParam param) {
log.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); log.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
log.info("params={}", JSONObject.toJSONString(param));
return HookResult.SUCCESS(); return HookResult.SUCCESS();
} }

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
@@ -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

@@ -8,7 +8,6 @@ import lombok.EqualsAndHashCode;
import org.dromara.common.core.validate.AddGroup; import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup; import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.sis.domain.SisDeviceManage; import org.dromara.sis.domain.SisDeviceManage;
/** /**
@@ -78,5 +77,6 @@ public class SisDeviceManageBo extends BaseEntity {
*/ */
private Long groupId; private Long groupId;
private String tenantId;
} }

View File

@@ -9,8 +9,8 @@ import lombok.Getter;
@Getter @Getter
public enum FactoryNoEnum { public enum FactoryNoEnum {
HIK("DS1013"), HIK("1"),
DAHUA("DS1014"); DAHUA("2");
private final String code; private final String code;

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

@@ -7,6 +7,7 @@ import org.dromara.sis.domain.SisDeviceChannel;
import org.dromara.sis.domain.bo.SisDeviceChannelBo; import org.dromara.sis.domain.bo.SisDeviceChannelBo;
import org.dromara.sis.domain.bo.SisDeviceManageBo; import org.dromara.sis.domain.bo.SisDeviceManageBo;
import org.dromara.sis.domain.vo.SisDeviceChannelVo; import org.dromara.sis.domain.vo.SisDeviceChannelVo;
import org.springframework.web.context.request.RequestAttributes;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -85,13 +86,16 @@ public interface ISisDeviceChannelService {
List<TreeNode<Long>> queryTree(); List<TreeNode<Long>> queryTree();
Boolean handleHikDeviceChannel(SisDeviceManageBo bo); void handleHikDeviceChannel(SisDeviceManageBo bo);
/** /**
* 通过设备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,14 +196,18 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
return TreeUtils.build(treeNodes, -1L); return TreeUtils.build(treeNodes, -1L);
} }
@Async
@Override @Override
public Boolean handleHikDeviceChannel(SisDeviceManageBo bo) { public void handleHikDeviceChannel(SisDeviceManageBo bo) {
// 调用hik sdk登录 // 调用hik sdk登录
boolean isLogin = HikApiService.getInstance().login(bo.getDeviceIp(), bo.getDevicePort().shortValue(), bo.getDeviceAccount(), bo.getDevicePwd()); boolean isLogin = HikApiService.getInstance().login(bo.getDeviceIp(), bo.getDevicePort().shortValue(), bo.getDeviceAccount(), bo.getDevicePwd());
if (!isLogin) { if (!isLogin) {
throw new RuntimeException("海康设备添加失败."); throw new RuntimeException("海康设备添加失败.");
} }
if (DeviceTypeEnum.IPC.getType().equals(bo.getDeviceType())) { if (DeviceTypeEnum.IPC.getType().equals(bo.getDeviceType())) {
// 校验设备通道是否存在,如果存在则放弃添加
SisDeviceChannel channel1 = this.queryByChannelIp(bo.getDeviceIp());
if (channel1 != null) {
// 写入设备通道信息 // 写入设备通道信息
SisDeviceChannel channel = new SisDeviceChannel(); SisDeviceChannel channel = new SisDeviceChannel();
channel.setDeviceId(bo.getId()); channel.setDeviceId(bo.getId());
@@ -214,34 +220,75 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
channel.setDevicePwd(bo.getDevicePwd()); channel.setDevicePwd(bo.getDevicePwd());
channel.setDeviceMac(bo.getDeviceMac()); channel.setDeviceMac(bo.getDeviceMac());
channel.setChannelNo(HikSdkConstans.DEFAULT_CHANNEL); channel.setChannelNo(HikSdkConstans.DEFAULT_CHANNEL);
this.insert(channel); channel.setTenantId(bo.getTenantId());
return true; Boolean insert = this.insert(channel);
log.info("设备[{}]通道添加完成,result={}", bo.getDeviceIp(), insert);
} else {
log.info("设备通道[{}]已存在,放弃添加通道信息", bo.getDeviceIp());
}
} 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(); // 校验通道信息是否存在
SisDeviceChannel channel = queryByChannelIp(item.getChannelIp());
boolean isUpdate = true;
if (channel == null) {
channel = new SisDeviceChannel();
isUpdate = false;
}
// 通道设备信息
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.setNvrChannelNo(item.getChannelId() + HikSdkConstans.DEFAULT_CHANNEL_PREFX);
// 系统设备信息
channel.setDeviceMac(bo.getDeviceMac());
// 将设备id 更改为nvr的设备id
channel.setDeviceId(bo.getId()); channel.setDeviceId(bo.getId());
channel.setGroupId(bo.getGroupId()); channel.setGroupId(bo.getGroupId());
channel.setDeviceIp(bo.getDeviceIp());
channel.setDevicePort(HikSdkConstans.DEFAULT_RTSP_PORT);
channel.setFactoryNo(bo.getFactoryNo());
channel.setDeviceAccount(bo.getDeviceAccount());
channel.setDevicePwd(bo.getDevicePwd());
channel.setDeviceMac(bo.getDeviceMac());
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); channel.setTenantId(bo.getTenantId());
}); if (isUpdate) {
this.baseMapper.insertBatch(channels); updateChannels.add(channel);
} else {
insertChannels.add(channel);
}
});
// 更新通道信息
if (CollUtil.isNotEmpty(updateChannels)) {
this.baseMapper.updateBatchById(updateChannels);
}
// 写入新的通道信息
if (CollUtil.isNotEmpty(insertChannels)) {
this.baseMapper.insertBatch(insertChannels);
}
} }
return true;
} else { } else {
log.info("未知的设备类型,不处理。"); log.info("未知的设备类型,不处理。");
} }
return false; }
@Override
public SisDeviceChannel queryByChannelIp(String channelIp) {
LambdaQueryWrapper<SisDeviceChannel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SisDeviceChannel::getDeviceIp, channelIp);
return baseMapper.selectOne(queryWrapper);
} }
@Override @Override
@@ -250,4 +297,5 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
lqw.in(SisDeviceChannel::getDeviceId, deviceIds); lqw.in(SisDeviceChannel::getDeviceId, deviceIds);
return baseMapper.delete(lqw); return baseMapper.delete(lqw);
} }
} }

View File

@@ -23,6 +23,8 @@ import org.dromara.sis.service.ISisDeviceManageService;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.util.*; import java.util.*;
@@ -104,17 +106,12 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
if (flag) { if (flag) {
bo.setId(add.getId()); bo.setId(add.getId());
// 获取设备通道信息 // 获取设备通道信息
handleDeviceChannelInfo(bo);
}
return flag;
}
public void handleDeviceChannelInfo(SisDeviceManageBo bo) {
if (Objects.equals(bo.getFactoryNo(), FactoryNoEnum.HIK.getCode())) { if (Objects.equals(bo.getFactoryNo(), FactoryNoEnum.HIK.getCode())) {
deviceChannelService.handleHikDeviceChannel(bo); deviceChannelService.handleHikDeviceChannel(bo);
} }
} }
return flag;
}
/** /**
* 修改设备管理 * 修改设备管理
@@ -165,24 +162,16 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
*/ */
@Async @Async
public void deleteDeviceRef(List<SisDeviceManage> sisDeviceManages) { public void deleteDeviceRef(List<SisDeviceManage> sisDeviceManages) {
List<Long> deviceIds = new ArrayList<>(sisDeviceManages.size()); List<Long> deviceIds = new ArrayList<>();
Map<String, List<SisDeviceManage>> factoryGroup = new HashMap<>(10); sisDeviceManages.forEach(item -> {
sisDeviceManages.forEach(sisDeviceManage -> { // 删除设备
deviceIds.add(sisDeviceManage.getId()); deviceIds.add(item.getId());
factoryGroup.computeIfAbsent(sisDeviceManage.getFactoryNo(), k -> new ArrayList<>()).add(sisDeviceManage); if (FactoryNoEnum.HIK.getCode().equals(item.getFactoryNo())) {
HikApiService.getInstance().loginOut(item.getDeviceIp());
}
}); });
// 删除设备通道
int num = deviceChannelService.deleteByDeviceIds(deviceIds); int num = deviceChannelService.deleteByDeviceIds(deviceIds);
log.info("删除设备通道完成,num={}", num); log.info("删除设备通道完成,num={}", num);
// 设备sdk注销
for (Map.Entry<String, List<SisDeviceManage>> entry : factoryGroup.entrySet()) {
if (entry.getKey().equals(FactoryNoEnum.HIK.getCode())) {
entry.getValue().forEach(item -> {
HikApiService.getInstance().loginOut(item.getDeviceIp());
});
}
}
} }