|
|
@ -222,20 +222,18 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void rateLimitRequestHandler() { |
|
|
|
public void rateLimitRequestHandler() { |
|
|
|
ZoneId chinaZoneId = ZoneId.of("Asia/Shanghai"); |
|
|
|
LocalDateTime endTime = LocalDateTime.now(); |
|
|
|
LocalDateTime startTime = LocalDateTime.now().minusSeconds(openAiConfigProperties.getDuration()); |
|
|
|
LocalDateTime startTime = endTime.minusSeconds(openAiConfigProperties.getDuration()); |
|
|
|
long startTimestamp = startTime.atZone(chinaZoneId).toEpochSecond(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询当前用户在指定范围内的发送消息
|
|
|
|
// 查询当前用户在指定范围内的发送消息
|
|
|
|
long maxCount = super.count(Wrappers.<ImContent>lambdaQuery() |
|
|
|
long maxCount = super.count(Wrappers.<ImContent>lambdaQuery() |
|
|
|
.eq(ImContent::getSendUserId, SecurityUtils.getCasUser().getId()) |
|
|
|
.eq(ImContent::getSendUserId, SecurityUtils.getCasUser().getId()) |
|
|
|
.between(ImContent::getSendTime, startTimestamp, LocalDateTime.now().atZone(chinaZoneId).toEpochSecond())); |
|
|
|
.between(ImContent::getSendTime, startTime, endTime)); |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否大于发送次数
|
|
|
|
// 检查是否大于发送次数
|
|
|
|
if (StrUtil.equals(SecurityUtils.<KiccUser>getUser().getSubscriber(), SubscriberEnum.NON.getValue()) && maxCount > openAiConfigProperties.getNonMaxCount()) { |
|
|
|
if (StrUtil.equals(SecurityUtils.<KiccUser>getUser().getSubscriber(), SubscriberEnum.NON.getValue()) && maxCount > openAiConfigProperties.getNonMaxCount()) { |
|
|
|
throw new CheckedException("普通订阅用户已超出当前最大速率限制,请过一会在试试!"); |
|
|
|
throw new CheckedException("普通订阅用户已超出当前最大速率限制,请过一会在试试!"); |
|
|
|
} |
|
|
|
} else if (StrUtil.equals(SecurityUtils.<KiccUser>getUser().getSubscriber(), SubscriberEnum.BASIC.getValue()) && maxCount > openAiConfigProperties.getBasicMaxCount()) { |
|
|
|
if (StrUtil.equals(SecurityUtils.<KiccUser>getUser().getSubscriber(), SubscriberEnum.BASIC.getValue()) && maxCount > openAiConfigProperties.getBasicMaxCount()) { |
|
|
|
|
|
|
|
throw new CheckedException("基础订阅用户已超出当前最大速率限制,请过一会在试试!"); |
|
|
|
throw new CheckedException("基础订阅用户已超出当前最大速率限制,请过一会在试试!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|