流媒体服务接口逻辑更改

This commit is contained in:
lxj 2025-07-25 21:32:43 +08:00
parent 9ac415d6fc
commit d3517de7b6
9 changed files with 198 additions and 43 deletions

View File

@ -1,6 +1,9 @@
package org.dromara.sis.sdk.hik;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sis.sdk.hik.model.DeviceInfo;
import org.dromara.sis.sdk.hik.service.CamearService;
import org.dromara.sis.sdk.hik.service.DoorService;
import org.dromara.sis.sdk.hik.service.LoginService;
import org.dromara.sis.sdk.hik.service.SdkBaseServer;
@ -139,10 +142,29 @@ public class HikApiService {
* @param deviceIp 设备ip
* @return 范湖通道信息
*/
public Object getChannelInfo(String deviceIp) {
return null;
public DeviceInfo getChannelInfo(String deviceIp) {
Integer lHandel = CACHE.get(deviceIp);
return CamearService.getDeviceChannelInfo(lHandel);
}
public static void main(String[] args) {
// String ip ="192.168.10.253";
// short port = 8000;
// String user = "admin";
// String wd ="ncqzfdl123";
String ip = "192.168.24.251";
short port = 8000;
String user = "admin";
String wd = "hik12345+";
SdkBaseServer.initSdk();
getInstance().login(ip, port, user, wd);
Integer lHandel = CACHE.get(ip);
DeviceInfo deviceChannelInfo = CamearService.getDeviceChannelInfo(lHandel);
System.out.println(JSONObject.toJSONString(deviceChannelInfo));
}
}

View File

@ -9,4 +9,6 @@ public class HikSdkConstans {
public static final Integer DEFAULT_RTSP_PORT = 554;
public static final String DEFAULT_CHANNEL_PREFX = "01";
}

View File

@ -1,31 +1,28 @@
package org.dromara.sis.sdk.hik;
import com.sun.jna.Structure;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import com.sun.jna.Structure;
public class SDK_Structure extends Structure
{
protected List<String> getFieldOrder()
{
List<String> fieldOrderList = new ArrayList<String>();
for (Class<?> cls = getClass();!cls.equals(SDK_Structure.class);cls = cls.getSuperclass())
{
Field[] fields = cls.getDeclaredFields();
int modifiers;
for (Field field : fields)
{
modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers))
{
continue;
}
fieldOrderList.add(field.getName());
}
}
//System.out.println(fieldOrderList);
return fieldOrderList;
}
public class SDK_Structure extends Structure {
protected List<String> getFieldOrder() {
List<String> fieldOrderList = new ArrayList<String>();
for (Class<?> cls = getClass(); !cls.equals(SDK_Structure.class); cls = cls.getSuperclass()) {
Field[] fields = cls.getDeclaredFields();
int modifiers;
for (Field field : fields) {
modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
continue;
}
fieldOrderList.add(field.getName());
}
}
//System.out.println(fieldOrderList);
return fieldOrderList;
}
}

View File

@ -0,0 +1,71 @@
package org.dromara.sis.sdk.hik.model;
import lombok.Data;
import java.util.List;
@Data
public class DeviceInfo {
/**
* 设备支持的总组数
*/
private Integer dwGroupNum;
/**
* 最大模拟通道个数
*/
private Integer dwAChanNum;
/**
* 数字通道个数
*/
private Integer dwDChanNum;
/**
* 起始数字通道
*/
private Integer dwStartDChan;
private List<DeviceChannelInfo> channelInfo;
@Data
public static class DeviceChannelInfo {
/**
* 通道id
*/
private Integer channelId;
/**
* 通道名称
*/
private String channelName;
/**
* 通道设备ip
*/
private String channelIp;
/**
* 通道设备端口
*/
private Short channelPort;
/**
* 通道账号
*/
private String channelAccount;
/**
* 通道密码
*/
private String channelPwd;
/**
* 通过状态
*/
private Integer channelStatus;
}
}

View File

@ -1,9 +1,14 @@
package org.dromara.sis.sdk.hik.service;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sis.sdk.hik.HCNetSDK;
import org.dromara.sis.sdk.hik.model.DeviceInfo;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import static org.dromara.sis.sdk.hik.HCNetSDK.NET_DVR_GET_IPPARACFG_V40;
@ -15,7 +20,7 @@ public class CamearService extends SdkBaseServer {
*
* @return
*/
public static Object getDeviceChannelInfo(int lUserID) {
public static DeviceInfo getDeviceChannelInfo(int lUserID) {
HCNetSDK.NET_DVR_IPPARACFG_V40 lpOutBuffer = new HCNetSDK.NET_DVR_IPPARACFG_V40();
lpOutBuffer.read();
lpOutBuffer.dwSize = lpOutBuffer.size();
@ -24,7 +29,48 @@ public class CamearService extends SdkBaseServer {
if (success) {
lpOutBuffer.read();
}
return null;
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDwGroupNum(lpOutBuffer.dwGroupNum);
deviceInfo.setDwAChanNum(lpOutBuffer.dwAChanNum);
deviceInfo.setDwDChanNum(lpOutBuffer.dwDChanNum);
deviceInfo.setDwStartDChan(lpOutBuffer.dwStartDChan);
List<DeviceInfo.DeviceChannelInfo> channelInfo = new ArrayList<>(64);
deviceInfo.setChannelInfo(channelInfo);
int num = 0;
for (int i = 0; i < lpOutBuffer.dwDChanNum; i++) {
HCNetSDK.NET_DVR_PICCFG_V30 dvrPiccfgV30 = new HCNetSDK.NET_DVR_PICCFG_V30();
dvrPiccfgV30.dwSize = dvrPiccfgV30.size();
IntByReference lpBytesReturned = new IntByReference(0);
int channelNum = i + lpOutBuffer.dwStartDChan;
getHcNetSDK().NET_DVR_GetDVRConfig(lUserID, HCNetSDK.NET_DVR_GET_PICCFG_V30, channelNum, dvrPiccfgV30.getPointer(), dvrPiccfgV30.dwSize, lpBytesReturned);
dvrPiccfgV30.read();
if (dvrPiccfgV30.dwSize == 0) {
// 代表此通道不存在数据那次此次不操作
log.info("通道[{}],无数据,不处理", channelNum);
} else {
String channelName = new String(dvrPiccfgV30.sChanName, Charset.forName("GBK")).trim();
HCNetSDK.NET_DVR_IPDEVINFO_V31 netDvrIpdevinfoV31 = lpOutBuffer.struIPDevInfo[num];
String sUserName = new String(netDvrIpdevinfoV31.sUserName, StandardCharsets.UTF_8).trim();
String sPassword = new String(netDvrIpdevinfoV31.sPassword, StandardCharsets.UTF_8).trim();
String ip = new String(netDvrIpdevinfoV31.struIP.sIpV4, StandardCharsets.UTF_8).trim();
short wDVRPort = netDvrIpdevinfoV31.wDVRPort;
DeviceInfo.DeviceChannelInfo deviceChannelInfo = new DeviceInfo.DeviceChannelInfo();
deviceChannelInfo.setChannelId( channelNum);
deviceChannelInfo.setChannelName(channelName);
deviceChannelInfo.setChannelIp(ip);
deviceChannelInfo.setChannelPort(wDVRPort);
deviceChannelInfo.setChannelAccount(sUserName);
deviceChannelInfo.setChannelPwd(sPassword);
deviceChannelInfo.setChannelStatus(0);
channelInfo.add(deviceChannelInfo);
num++;
}
}
return deviceInfo;
}
}

View File

@ -136,6 +136,4 @@ public class SdkBaseServer {
hcNetSDK.NET_DVR_Cleanup();
}
}
}

View File

@ -199,7 +199,6 @@ public class ZLMediaKitServiceImpl implements ZLMediaKitService {
return null;
}
@Override
public Boolean delFFmpegSource(String key) {
Map<String, Object> commonParams = getCommonParams();

View File

@ -21,6 +21,7 @@ import org.dromara.sis.domain.vo.SisDeviceGroupVo;
import org.dromara.sis.mapper.SisDeviceChannelMapper;
import org.dromara.sis.sdk.hik.HikApiService;
import org.dromara.sis.sdk.hik.HikSdkConstans;
import org.dromara.sis.sdk.hik.model.DeviceInfo;
import org.dromara.sis.service.ISisDeviceChannelService;
import org.dromara.sis.service.ISisDeviceGroupService;
import org.springframework.stereotype.Service;
@ -195,13 +196,12 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
@Override
public Boolean handleHikDeviceChannel(SisDeviceManageBo bo) {
// 调用hik sdk登录
boolean isLogin = HikApiService.getInstance().login(bo.getDeviceIp(), bo.getDevicePort().shortValue(), bo.getDeviceAccount(), bo.getDevicePwd());
if (!isLogin) {
throw new RuntimeException("海康设备添加失败.");
}
if (DeviceTypeEnum.IPC.getType().equals(bo.getDeviceType())) {
// 只需要验证hik设备能能否登录即可
// 调用hik sdk登录
boolean isLogin = HikApiService.getInstance().login(bo.getDeviceIp(), bo.getDevicePort().shortValue(), bo.getDeviceAccount(), bo.getDevicePwd());
if (!isLogin) {
throw new RuntimeException("海康设备添加失败.");
}
// 写入设备通道信息
SisDeviceChannel channel = new SisDeviceChannel();
channel.setDeviceId(bo.getId());
@ -216,10 +216,30 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
channel.setChannelNo(HikSdkConstans.DEFAULT_CHANNEL);
this.insert(channel);
return true;
} else if (DeviceTypeEnum.NVR.getType().equals(bo.getDeviceType())) {
//TODO
} else if (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());
if (channelInfo != null && CollUtil.isNotEmpty(channelInfo.getChannelInfo())) {
List<SisDeviceChannel> channels = new ArrayList<>(channelInfo.getChannelInfo().size());
channelInfo.getChannelInfo().forEach(item -> {
SisDeviceChannel channel = new SisDeviceChannel();
channel.setDeviceId(bo.getId());
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.setChannelNo(item.getChannelId() + HikSdkConstans.DEFAULT_CHANNEL_PREFX);
channels.add(channel);
});
this.baseMapper.insertBatch(channels);
}
return true;
} else {
log.info("未知的设备类型,不处理。");
}
return false;
}

View File

@ -15,7 +15,7 @@
<module>ruoyi-resource</module>
<module>ruoyi-workflow</module>
<module>Property</module>
<!-- <module>Sis</module>-->
<module>Sis</module>
</modules>
<artifactId>ruoyi-modules</artifactId>