From ef7ca1fa5abbb5f6197ee9c19395f20a29ba2b75 Mon Sep 17 00:00:00 2001 From: lxj <15683799673@163.com> Date: Wed, 30 Jul 2025 05:46:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=80=9A=E9=81=93=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SisDeviceManageController.java | 2 + .../zkmedia/ZkMediaHookController.java | 1 + .../sis/domain/bo/SisDeviceManageBo.java | 2 +- .../sis/domain/enums/FactoryNoEnum.java | 4 +- .../sis/service/ISisDeviceChannelService.java | 3 +- .../impl/SisDeviceChannelServiceImpl.java | 46 +++++++++++-------- .../impl/SisDeviceManageServiceImpl.java | 35 +++++--------- 7 files changed, 48 insertions(+), 45 deletions(-) diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisDeviceManageController.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisDeviceManageController.java index 0f8a3fc..b354758 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisDeviceManageController.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisDeviceManageController.java @@ -15,6 +15,7 @@ import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessType; import org.dromara.common.mybatis.core.page.PageQuery; 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.sis.domain.bo.SisDeviceManageBo; import org.dromara.sis.domain.vo.SisDeviceManageVo; @@ -79,6 +80,7 @@ public class SisDeviceManageController extends BaseController { @RepeatSubmit() @PostMapping() public R add(@Validated(AddGroup.class) @RequestBody SisDeviceManageBo bo) { + bo.setTenantId(LoginHelper.getTenantId()); return R.ok("设备添加成功", sisDeviceManageService.insertByBo(bo)); } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/zkmedia/ZkMediaHookController.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/zkmedia/ZkMediaHookController.java index c88a72e..274fdc2 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/zkmedia/ZkMediaHookController.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/zkmedia/ZkMediaHookController.java @@ -74,6 +74,7 @@ public class ZkMediaHookController { @PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8") public HookResult onStreamNotFound(@RequestBody OnStreamNotFoundHookParam param) { log.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); + log.info("params={}", JSONObject.toJSONString(param)); return HookResult.SUCCESS(); } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisDeviceManageBo.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisDeviceManageBo.java index f5cef48..75f6be2 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisDeviceManageBo.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisDeviceManageBo.java @@ -8,7 +8,6 @@ import lombok.EqualsAndHashCode; 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.common.translation.annotation.Translation; import org.dromara.sis.domain.SisDeviceManage; /** @@ -78,5 +77,6 @@ public class SisDeviceManageBo extends BaseEntity { */ private Long groupId; + private String tenantId; } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/enums/FactoryNoEnum.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/enums/FactoryNoEnum.java index fb0734e..a27ba12 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/enums/FactoryNoEnum.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/enums/FactoryNoEnum.java @@ -9,8 +9,8 @@ import lombok.Getter; @Getter public enum FactoryNoEnum { - HIK("DS1013"), - DAHUA("DS1014"); + HIK("1"), + DAHUA("2"); private final String code; diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisDeviceChannelService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisDeviceChannelService.java index 428104a..c186913 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisDeviceChannelService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisDeviceChannelService.java @@ -7,6 +7,7 @@ import org.dromara.sis.domain.SisDeviceChannel; import org.dromara.sis.domain.bo.SisDeviceChannelBo; import org.dromara.sis.domain.bo.SisDeviceManageBo; import org.dromara.sis.domain.vo.SisDeviceChannelVo; +import org.springframework.web.context.request.RequestAttributes; import java.util.Collection; import java.util.List; @@ -85,7 +86,7 @@ public interface ISisDeviceChannelService { List> queryTree(); - Boolean handleHikDeviceChannel(SisDeviceManageBo bo); + void handleHikDeviceChannel(SisDeviceManageBo bo); /** * 通过设备ids 删除设备通道信息 diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceChannelServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceChannelServiceImpl.java index 4c9cd2a..3c5e2de 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceChannelServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceChannelServiceImpl.java @@ -198,27 +198,34 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService { @Async @Override - public Boolean handleHikDeviceChannel(SisDeviceManageBo bo) { + public void 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())) { - // 写入设备通道信息 - SisDeviceChannel channel = new SisDeviceChannel(); - channel.setDeviceId(bo.getId()); - channel.setChannelName(bo.getDeviceName()); - 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.setChannelNo(HikSdkConstans.DEFAULT_CHANNEL); - this.insert(channel); - return true; + // 校验设备通道是否存在,如果存在则放弃添加 + SisDeviceChannel channel1 = this.queryByChannelIp(bo.getDeviceIp()); + if (channel1 != null) { + // 写入设备通道信息 + SisDeviceChannel channel = new SisDeviceChannel(); + channel.setDeviceId(bo.getId()); + channel.setChannelName(bo.getDeviceName()); + 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.setChannelNo(HikSdkConstans.DEFAULT_CHANNEL); + channel.setTenantId(bo.getTenantId()); + 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())) { DeviceInfo channelInfo = HikApiService.getInstance().getChannelInfo(bo.getDeviceIp()); if (channelInfo != null && CollUtil.isNotEmpty(channelInfo.getChannelInfo())) { @@ -247,12 +254,16 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService { 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.setGroupId(bo.getGroupId()); channel.setChannelName(item.getChannelName()); channel.setChannelNo(item.getChannelId() + HikSdkConstans.DEFAULT_CHANNEL_PREFX); + channel.setTenantId(bo.getTenantId()); if (isUpdate) { updateChannels.add(channel); } else { @@ -265,14 +276,12 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService { } // 写入新的通道信息 if (CollUtil.isNotEmpty(insertChannels)) { - this.baseMapper.insertBatch(updateChannels); + this.baseMapper.insertBatch(insertChannels); } } - return true; } else { log.info("未知的设备类型,不处理。"); } - return false; } @Override @@ -288,4 +297,5 @@ public class SisDeviceChannelServiceImpl implements ISisDeviceChannelService { lqw.in(SisDeviceChannel::getDeviceId, deviceIds); return baseMapper.delete(lqw); } + } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceManageServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceManageServiceImpl.java index c386f46..5b93e49 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceManageServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisDeviceManageServiceImpl.java @@ -23,6 +23,8 @@ import org.dromara.sis.service.ISisDeviceManageService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; import java.util.*; @@ -104,18 +106,13 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService { if (flag) { bo.setId(add.getId()); // 获取设备通道信息 - handleDeviceChannelInfo(bo); + if (Objects.equals(bo.getFactoryNo(), FactoryNoEnum.HIK.getCode())) { + deviceChannelService.handleHikDeviceChannel(bo); + } } return flag; } - public void handleDeviceChannelInfo(SisDeviceManageBo bo) { - if (Objects.equals(bo.getFactoryNo(), FactoryNoEnum.HIK.getCode())) { - deviceChannelService.handleHikDeviceChannel(bo); - } - } - - /** * 修改设备管理 * @@ -165,24 +162,16 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService { */ @Async public void deleteDeviceRef(List sisDeviceManages) { - List deviceIds = new ArrayList<>(sisDeviceManages.size()); - Map> factoryGroup = new HashMap<>(10); - sisDeviceManages.forEach(sisDeviceManage -> { - deviceIds.add(sisDeviceManage.getId()); - factoryGroup.computeIfAbsent(sisDeviceManage.getFactoryNo(), k -> new ArrayList<>()).add(sisDeviceManage); - + List deviceIds = new ArrayList<>(); + sisDeviceManages.forEach(item -> { + // 删除设备 + deviceIds.add(item.getId()); + if (FactoryNoEnum.HIK.getCode().equals(item.getFactoryNo())) { + HikApiService.getInstance().loginOut(item.getDeviceIp()); + } }); - // 删除设备通道 int num = deviceChannelService.deleteByDeviceIds(deviceIds); log.info("删除设备通道完成,num={}", num); - // 设备sdk注销 - for (Map.Entry> entry : factoryGroup.entrySet()) { - if (entry.getKey().equals(FactoryNoEnum.HIK.getCode())) { - entry.getValue().forEach(item -> { - HikApiService.getInstance().loginOut(item.getDeviceIp()); - }); - } - } }