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