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 d77a9bdb..da3c6a50 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 6357d167..04c15ae2 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; + } + } /**