视频监控逻辑完善
This commit is contained in:
parent
800a2de30f
commit
2d1b6d8ff7
@ -3,6 +3,7 @@ package org.dromara.sis.controller.zkmedia;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.sis.domain.enums.FactoryNoEnum;
|
||||
import org.dromara.sis.sdk.zkmedia.MediaServerUtils;
|
||||
import org.dromara.sis.sdk.zkmedia.ZLMediaKitService;
|
||||
import org.dromara.sis.sdk.zkmedia.model.AddStreamProxy;
|
||||
@ -49,9 +50,9 @@ public class ZKLmediaController {
|
||||
proxy.setApp("realtime");
|
||||
String s = IdUtil.fastSimpleUUID();
|
||||
proxy.setStream(s);
|
||||
if ("DS1010".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()));
|
||||
} else if ("DS1014".equals(data.getFactoryNo())) {
|
||||
} else if (FactoryNoEnum.DAHUA.getCode().equals(data.getFactoryNo())) {
|
||||
proxy.setUrl(String.format(DAHUA_REALTIME_RTSP_TEMPLATE, data.getAccount(), data.getPwd(), data.getVideoIp(), data.getVideoPort(), data.getChannelId()));
|
||||
} else {
|
||||
throw new RuntimeException("未知的设备类型!");
|
||||
|
@ -9,7 +9,8 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum FactoryNoEnum {
|
||||
|
||||
HIK("DS1013");
|
||||
HIK("DS1013"),
|
||||
DAHUA("DS1014");
|
||||
|
||||
private final String code;
|
||||
|
||||
|
@ -116,6 +116,7 @@ public class HikApiService {
|
||||
}
|
||||
boolean logout = LoginService.logout(lHandel);
|
||||
if (logout) {
|
||||
log.info("设备[{}]注销完成", deviceIp);
|
||||
CACHE.remove(deviceIp);
|
||||
}
|
||||
return logout;
|
||||
|
@ -7,4 +7,6 @@ public class HikSdkConstans {
|
||||
*/
|
||||
public static final String DEFAULT_CHANNEL = "101";
|
||||
|
||||
public static final Integer DEFAULT_RTSP_PORT = 554;
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ public class AddStreamProxy {
|
||||
@NotBlank
|
||||
private String videoIp;
|
||||
|
||||
@NotNull
|
||||
private Integer videoPort;
|
||||
|
||||
@NotBlank
|
||||
@ -31,6 +30,6 @@ public class AddStreamProxy {
|
||||
|
||||
private String endTime;
|
||||
|
||||
private String stream;
|
||||
private String stream;
|
||||
|
||||
}
|
||||
|
@ -87,5 +87,11 @@ public interface ISisDeviceChannelService {
|
||||
|
||||
Boolean handleHikDeviceChannel(SisDeviceManageBo bo);
|
||||
|
||||
/**
|
||||
* 通过设备ids 删除设备通道信息
|
||||
* @param deviceIds 设备ids
|
||||
* @return 返回删除数量
|
||||
*/
|
||||
Integer deleteByDeviceIds(List<Long> deviceIds);
|
||||
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
|
||||
channel.setChannelName(bo.getDeviceName());
|
||||
channel.setGroupId(bo.getGroupId());
|
||||
channel.setDeviceIp(bo.getDeviceIp());
|
||||
channel.setDevicePort(bo.getDevicePort());
|
||||
channel.setDevicePort(HikSdkConstans.DEFAULT_RTSP_PORT);
|
||||
channel.setFactoryNo(bo.getFactoryNo());
|
||||
channel.setDeviceAccount(bo.getDeviceAccount());
|
||||
channel.setDevicePwd(bo.getDevicePwd());
|
||||
@ -223,4 +223,11 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByDeviceIds(List<Long> deviceIds) {
|
||||
LambdaQueryWrapper<SisDeviceChannel> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.in(SisDeviceChannel::getDeviceId, deviceIds);
|
||||
return baseMapper.delete(lqw);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dromara.sis.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -7,6 +8,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.TreeNode;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
@ -15,15 +17,14 @@ import org.dromara.sis.domain.bo.SisDeviceManageBo;
|
||||
import org.dromara.sis.domain.enums.FactoryNoEnum;
|
||||
import org.dromara.sis.domain.vo.SisDeviceManageVo;
|
||||
import org.dromara.sis.mapper.SisDeviceManageMapper;
|
||||
import org.dromara.sis.sdk.hik.HikApiService;
|
||||
import org.dromara.sis.service.ISisDeviceChannelService;
|
||||
import org.dromara.sis.service.ISisDeviceManageService;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@ -38,7 +39,7 @@ import java.util.Objects;
|
||||
public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
|
||||
private final SisDeviceManageMapper baseMapper;
|
||||
private final ISisDeviceChannelService hikDeviceChannelService;
|
||||
private final ISisDeviceChannelService deviceChannelService;
|
||||
|
||||
/**
|
||||
* 查询设备管理
|
||||
@ -60,7 +61,7 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SisDeviceManageVo> queryPageList(SisDeviceManageBo bo, PageQuery pageQuery) {
|
||||
Page<SisDeviceManageVo> result =baseMapper.selectByPage(pageQuery.build(), bo);
|
||||
Page<SisDeviceManageVo> result = baseMapper.selectByPage(pageQuery.build(), bo);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@ -110,7 +111,7 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
|
||||
public void handleDeviceChannelInfo(SisDeviceManageBo bo) {
|
||||
if (Objects.equals(bo.getFactoryNo(), FactoryNoEnum.HIK.getCode())) {
|
||||
hikDeviceChannelService.handleHikDeviceChannel(bo);
|
||||
deviceChannelService.handleHikDeviceChannel(bo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,14 +143,49 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
// 查询需要删除的设备
|
||||
List<SisDeviceManage> sisDeviceManages = baseMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(sisDeviceManages)) {
|
||||
return true;
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
int i = baseMapper.deleteByIds(ids);
|
||||
boolean flag = i > 0;
|
||||
if (flag) {
|
||||
SisDeviceManageServiceImpl aopProxy = SpringUtils.getAopProxy(this);
|
||||
aopProxy.deleteDeviceRef(sisDeviceManages);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步删除设备的关联关系
|
||||
*/
|
||||
@Async
|
||||
public void deleteDeviceRef(List<SisDeviceManage> sisDeviceManages) {
|
||||
List<Long> deviceIds = new ArrayList<>(sisDeviceManages.size());
|
||||
Map<String, List<SisDeviceManage>> factoryGroup = new HashMap<>(10);
|
||||
sisDeviceManages.forEach(sisDeviceManage -> {
|
||||
deviceIds.add(sisDeviceManage.getId());
|
||||
factoryGroup.computeIfAbsent(sisDeviceManage.getFactoryNo(), k -> new ArrayList<>()).add(sisDeviceManage);
|
||||
|
||||
});
|
||||
// 删除设备通道
|
||||
int num = deviceChannelService.deleteByDeviceIds(deviceIds);
|
||||
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());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SisDeviceManageVo queryVoByDeviceIp(Integer deviceCode) {
|
||||
LambdaQueryWrapper<SisDeviceManage> lqw = Wrappers.lambdaQuery();
|
||||
|
@ -32,3 +32,5 @@ spring:
|
||||
- optional:nacos:application-common.yml
|
||||
- optional:nacos:datasource.yml
|
||||
- optional:nacos:${spring.application.name}.yml
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user