zhaowenyu
2025-12-09 e8f5e59edd5a50062b2e33c9812f233bb11f70d8
2025-12-09 zwy 整理hms代码,相同告警信息更新创建时间,不重复录入;
1 files modified
32 ■■■■■ changed files
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceHmsServiceImpl.java 32 ●●●●● patch | view | raw | blame | history
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());
@@ -373,4 +387,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);
    }
}