From dab0440128e24d1a3edcf65b1ac34348c4ac0aea Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Sat, 11 Oct 2025 16:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9Abug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/device/DeviceBizService.java | 3 +-- .../common/redis/utils/RedisUtils.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java index d77a9bd..da3c6a5 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java @@ -189,7 +189,6 @@ public class DeviceBizService { if (appDeviceBindRecord != null) { UpdateWrapper deviceUpdateWrapper = new UpdateWrapper<>(); deviceUpdateWrapper.eq("device_id", device.getId()) - .set("binding_status", BindingStatusEnum.BOUND.getCode()) .set("binding_user_id", userId) .set("communication_mode", 0) .set("update_time", new Date()) @@ -384,7 +383,7 @@ public class DeviceBizService { String deviceImei = device.getDeviceImei(); String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history"; - Collection list = RedisUtils.zRangeByScore(a, startTime, endTime); + Collection list = RedisUtils.zRangeByScoreDesc(a, startTime, endTime); if (CollectionUtil.isEmpty(list)) { return null; } diff --git a/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java b/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java index 6357d16..04c15ae 100644 --- a/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java +++ b/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java @@ -394,6 +394,26 @@ public class RedisUtils { return null; } } + /** + * 根据时间范围查询Sorted Set中的元素并降序排列 + * + * @param key 键 + * @param startTime 开始时间戳 + * @param endTime 结束时间戳 + * @return 指定时间范围内的元素集合(降序) + */ + public static Collection zRangeByScoreDesc(String key, Long startTime, Long endTime) { + try { + RScoredSortedSet sortedSet = CLIENT.getScoredSortedSet(key); + // 使用 valueRangeReversed 方法获取降序排列的结果 + return sortedSet.valueRangeReversed(startTime, true, endTime, true); + } catch (Exception e) { + // 记录错误日志(如果项目中有日志工具的话) + // log.error("根据时间范围查询Sorted Set中的元素失败: key={}, startTime={}, endTime={}, error={}", + // key, startTime, endTime, e.getMessage(), e); + return null; + } + } /**