diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 81d48ddc..8039fbcd 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -360,6 +360,7 @@ public class GenerateServiceImpl extends ServiceImpl i @Override public Long getRankPosition(String uniqueId) { + // rank 从0开始 return redisUtil.getRank(consumptionOrderKey, uniqueId); } @@ -374,8 +375,10 @@ public class GenerateServiceImpl extends ServiceImpl i // 2、判断该请求是否还在排队 Boolean existsInZSet = redisUtil.isElementExistsInZSet(consumptionOrderKey, uniqueId); if (existsInZSet) { - // 排队中,给出当前排序位置 - return new GenerateCollectionVO(getRankPosition(uniqueId) + 1L); + // 排队中,给出当前排序位置,rank从0开始 + Long rankPosition = getRankPosition(uniqueId); + // 有9个消费者,所以当rank>8即当前请求至少排在第九位时,其实际排队位置为9-8+1,当rank <=8,请求均在处理中 + return new GenerateCollectionVO( rankPosition > 8L ? rankPosition - 8 + 1 : 1L); } // 3、判断redis中有没有