zhaowenyu
2025-12-03 b5b95f50e7905e9424628254b3cba7b92aa77cde
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceServiceImpl.java
@@ -360,10 +360,11 @@
    //region 单独写一个方法做权限验证,由于有好多定时任务也在实时获取设备列表,原方法不适用再添加权限注解
    @Override
    public List<DeviceDTO> getDockList() {
    public List<DeviceDTO> getDockList(String nickname) {
        List<DeviceDTO> devicesList = this.getDockListByParams(
                DeviceQueryParam.builder()
                        .domains(List.of(DeviceDomainEnum.GATEWAY.getVal(), DeviceDomainEnum.DOCK.getVal()))
                        .nickname(nickname)
                        .build());
        // 在獲取设备列表时,顺便获取直播地址
        for(DeviceDTO devices : devicesList){
@@ -424,6 +425,7 @@
                                })
                                .eq(param.getBoundStatus() != null, DeviceEntity::getBoundStatus,
                                        param.getBoundStatus())
                                .like(param.getNickname()!=null, DeviceEntity::getNickname, "%" + param.getNickname() + "%")
                                .orderBy(param.isOrderBy(),
                                        param.isAsc(), DeviceEntity::getId))
                .stream()
@@ -431,6 +433,90 @@
                .collect(Collectors.toList());
    }
    //endregion
    // region 多路直播列表,按nickname筛选
//    /**
//     * 多路直播列表,按nickname筛选
//     * */
//    @Override
//    public List<DeviceDTO> getDockCameraList(String nickname) {
//
//        List<DeviceDTO> devicesList = this.getDockListByParams(
//                DeviceQueryParam.builder()
//                        .domains(List.of(DeviceDomainEnum.GATEWAY.getVal(), DeviceDomainEnum.DOCK.getVal()))
//                        .nickname(nickname)
//                        .build());
//
//        // 在獲取设备列表时,顺便获取直播地址
//        for(DeviceDTO devices : devicesList){
//            _liveStreamHandler.StartLiveStreaming(devices.getDeviceSn());
//            _liveStreamHandler.StartLiveStreaming(devices.getChildDeviceSn());
//            ArdCamera ardCamera = new ArdCamera();
//            ardCamera.setDockId(devices.getId());
//            List<ArdCamera> ardCameraList = _cameraService.selectArdCameraList(ardCamera);
//            for(ArdCamera ardCamera1 : ardCameraList){
//                for(ArdChannel ardChannel : ardCamera1.getChannelList()) {
//                    if(ardChannel.getChanNo() == 1) {
//                        // 修改列表中外接相机地址
//                        updateCameraWebrtcUrl(devices.getDeviceSn(), ardChannel.getArdVtdu().getWebrtcUrl());
//                    }
//                }
//            }
//        }
//
//        devicesList.stream()
//                .filter(gateway -> DeviceDomainEnum.DOCK.getVal() == gateway.getDomain() ||
//                        RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + gateway.getDeviceSn()))
//                .forEach(this::spliceDeviceTopoPer);
//
//        return devicesList;
//    }
//    @Override
//    public void spliceDeviceTopoCamera(DeviceDTO gateway) {
//        gateway.setStatus(RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + gateway.getDeviceSn()));
//        // sub device
//        if (!StringUtils.hasText(gateway.getChildDeviceSn())) {
//            return;
//        }
//        DeviceDTO subDevice =
//                getDevicesByParams(DeviceQueryParam.builder().deviceSn(gateway.getChildDeviceSn()).build()).get(0);
//        subDevice.setStatus(RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + subDevice.getDeviceSn()));
//        gateway.setChildren(subDevice);
//    }
//    /**
//     * 按nickname筛选列表
//     * */
//    @Override
//    public List<DeviceDTO> getDockCameraListByParams(DeviceQueryParam param) {
//        return mapper.selectListPer(
//                        new LambdaQueryWrapper<DeviceEntity>()
//                                .eq(StringUtils.hasText(param.getDeviceSn()),
//                                        DeviceEntity::getDeviceSn, param.getDeviceSn())
//                                .eq(param.getDeviceType() != null,
//                                        DeviceEntity::getDeviceType, param.getDeviceType())
//                                .eq(param.getSubType() != null,
//                                        DeviceEntity::getSubType, param.getSubType())
//                                .eq(StringUtils.hasText(param.getChildSn()),
//                                        DeviceEntity::getChildSn, param.getChildSn())
//                                .and(!CollectionUtils.isEmpty(param.getDomains()), wrapper -> {
//                                    for (Integer domain : param.getDomains()) {
//                                        wrapper.eq(DeviceEntity::getDomain, domain).or();
//                                    }
//                                })
//                                .eq(param.getBoundStatus() != null, DeviceEntity::getBoundStatus,
//                                        param.getBoundStatus())
//                                .like(param.getNickname()!=null, DeviceEntity::getNickname, "%" + param.getNickname() + "%")
//                                .orderBy(param.isOrderBy(),
//                                        param.isAsc(), DeviceEntity::getId))
//                .stream()
//                .map(this::deviceEntityConvertToDTO)
//                .collect(Collectors.toList());
//    }
    // endregion
    @Override
    public Optional<TopologyDeviceDTO> getDeviceTopoForPilot(String sn) {
@@ -1088,14 +1174,14 @@
                        .data(Map.of(MapKeyConst.DEVICES, deviceOtaFirmwares))
                        .build());
        if (serviceReply.getResult() != ResponseResult.CODE_SUCCESS) {
            return ResponseResult.error(serviceReply.getResult(), "Firmware Error Code: " + serviceReply.getResult());
            String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
            return ResponseResult.error(serviceReply.getResult(), errorMsg);
        }
        // Record the device state that needs to be updated.
        deviceOtaFirmwares.forEach(deviceOta -> RedisOpsUtils.setWithExpire(
                RedisConst.FIRMWARE_UPGRADING_PREFIX + deviceOta.getSn(),
                bid,
                RedisConst.DEVICE_ALIVE_SECOND * RedisConst.DEVICE_ALIVE_SECOND));
                bid,RedisConst.DEVICE_ALIVE_SECOND * RedisConst.DEVICE_ALIVE_SECOND));
        return ResponseResult.success();
    }
@@ -1103,7 +1189,7 @@
    public void devicePropertySet(String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param) {
        boolean dockOnline = this.checkDeviceOnline(dockSn);
        if (!dockOnline) {
            throw new RuntimeException("Dock is offline.");
            throw new RuntimeException(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
        }
        DeviceDTO deviceDTO = (DeviceDTO) RedisOpsUtils.get(RedisConst.DEVICE_ONLINE_PREFIX + dockSn);
        boolean deviceOnline = this.checkDeviceOnline(deviceDTO.getChildDeviceSn());