zhaowenyu
2025-12-15 581e410b5a9ebfa309c7135698c81a5039eb1a6b
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceHmsServiceImpl.java
@@ -100,11 +100,20 @@
                .forEach(hmsReceiver -> {
                    final DeviceHmsEntity hms = entity.clone();
                    this.fillEntity(hms, hmsReceiver, device);
                    this.fillMessage(hms, hmsReceiver.getArgs());
                    // The same unread hms are no longer incremented.
                    if (hmsMap.contains(hms.getHmsKey())) {
                        // 修改已存在数据的创建时间,先查询到已存在记录,再修改。
                        DeviceHmsEntity exisHms=getDeviceHmsEntity(hms);
                        if (exisHms != null) {
                            LambdaUpdateWrapper<DeviceHmsEntity> updateWrapper = new LambdaUpdateWrapper<>();
                            updateWrapper.set(DeviceHmsEntity::getCreateTime, hms.getCreateTime());
                            updateWrapper.eq(DeviceHmsEntity::getId, exisHms.getId());
                            mapper.update(exisHms, updateWrapper);
                        }
                        return;
                    }
                    this.fillMessage(hms, hmsReceiver.getArgs());
                    unReadList.add(entity2Dto(hms));
                    mapper.insert(hms);
                });
@@ -112,7 +121,12 @@
        if (unReadList.isEmpty()) {
            return;
        }
        RedisOpsUtils.listRPush(key, (Object) unReadList.stream().map(DeviceHmsDTO::getKey).toArray(String[]::new));
        // RedisOpsUtils.listRPush(key, (Object) unReadList.stream().map(DeviceHmsDTO::getKey).toArray(String[]::new));
        // 修正后:直接传入String数组,每个元素单独存
        List<String> newHmsKeys = unReadList.stream()
                .map(DeviceHmsDTO::getKey)
                .collect(Collectors.toList());
        RedisOpsUtils.listRPush(key, newHmsKeys.toArray(new String[0]));
        // push to the web
//        Collection<ConcurrentWebSocketSession> sessions = webSocketManageService.getValueWithWorkspaceAndUserType(
//                device.getWorkspaceId(), UserTypeEnum.WEB.getVal());
@@ -260,9 +274,10 @@
        dto.setInTheSky(receiver.getInTheSky());
        dto.setDeviceType(receiver.getDeviceType());
        if(deviceDTO.getDomain() == DeviceDomainEnum.DOCK.getVal()) {
        // 不知道什么原因,在程序替换jar包重新启动时,报了个空指针异常,排查应该是因为 DeviceDTO对象为空,没有从redis中读取到设备信息。增加判断
        if(deviceDTO !=null && deviceDTO.getDomain() == DeviceDomainEnum.DOCK.getVal()) {
            dto.setHmsKey(HmsEnum.HmsFaqIdEnum.DOCK_TIP.getText() + receiver.getCode());
            log.info("SN:{}的Hms匹配拼接规则值为:{}",deviceDTO.getDeviceSn(), HmsEnum.HmsFaqIdEnum.DOCK_TIP.getText() + receiver.getCode());
//            log.info("SN:{}的Hms匹配拼接规则值为:{}",deviceDTO.getDeviceSn(), HmsEnum.HmsFaqIdEnum.DOCK_TIP.getText() + receiver.getCode());
            return;
        }
//        if (HmsEnum.DomainType.DRONE_NEST.getDomain().equals(receiver.getDomainType())) {
@@ -275,7 +290,7 @@
            key.append(HmsEnum.IN_THE_SKY.getText());
        }
        dto.setHmsKey(key.toString());
        log.info("SN:{}的Hms匹配拼接规则值为:{}",deviceDTO.getDeviceSn(), key.toString());
//        log.info("SN:{}的Hms匹配拼接规则值为:{}",deviceDTO.getDeviceSn(), key.toString());
    }
    /**
@@ -373,4 +388,18 @@
        }
        return list;
    }
    /**
     * 按条件查询返回最新的一条数据
     * */
    public DeviceHmsEntity getDeviceHmsEntity(DeviceHmsEntity deviceHmsEntity) {
        List <DeviceHmsEntity> lstHms = mapper.selectList(new LambdaQueryWrapper<DeviceHmsEntity>()
                        .eq(DeviceHmsEntity::getHmsKey, deviceHmsEntity.getHmsKey())
                        .eq(DeviceHmsEntity::getSn, deviceHmsEntity.getSn())
                        .eq(DeviceHmsEntity::getUpdateTime,0)
                        .orderByDesc(DeviceHmsEntity::getCreateTime)
                        );
        return lstHms.isEmpty() ? null : lstHms.get(0);
    }
}