mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-13 20:11:29 +00:00
fix: 解决不登陆无法问答问题;修复余额不足后流不关闭问题;
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.ruoyi.common.core.config;
|
package org.ruoyi.common.core.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||||
import org.ruoyi.common.core.config.properties.ThreadPoolProperties;
|
import org.ruoyi.common.core.config.properties.ThreadPoolProperties;
|
||||||
import org.ruoyi.common.core.utils.Threads;
|
import org.ruoyi.common.core.utils.Threads;
|
||||||
@@ -18,6 +19,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
**/
|
**/
|
||||||
|
@Slf4j
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@EnableConfigurationProperties(ThreadPoolProperties.class)
|
@EnableConfigurationProperties(ThreadPoolProperties.class)
|
||||||
public class ThreadPoolConfig {
|
public class ThreadPoolConfig {
|
||||||
@@ -43,7 +45,8 @@ public class ThreadPoolConfig {
|
|||||||
* 执行周期性或定时任务
|
* 执行周期性或定时任务
|
||||||
*/
|
*/
|
||||||
@Bean(name = "scheduledExecutorService")
|
@Bean(name = "scheduledExecutorService")
|
||||||
protected ScheduledExecutorService scheduledExecutorService() {
|
public ScheduledExecutorService scheduledExecutorService() {
|
||||||
|
log.info("====创建定时任务线程池====");
|
||||||
return new ScheduledThreadPoolExecutor(core,
|
return new ScheduledThreadPoolExecutor(core,
|
||||||
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||||
|
|||||||
@@ -435,8 +435,8 @@ public class ChatCostServiceImpl implements IChatCostService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean checkBalanceSufficient(ChatRequest chatRequest) {
|
public boolean checkBalanceSufficient(ChatRequest chatRequest) {
|
||||||
if (chatRequest.getUserId() == null) {
|
if (chatRequest.getUserId() == null) {
|
||||||
log.warn("checkBalanceSufficient->用户ID为空,视为余额不足");
|
log.warn("当前未登录");
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -34,7 +34,16 @@ public class BillingChatServiceProxy implements IChatService {
|
|||||||
String errorMsg = "余额不足,无法使用AI服务,请充值后再试";
|
String errorMsg = "余额不足,无法使用AI服务,请充值后再试";
|
||||||
log.warn("余额不足阻止AI回复,用户ID: {}, 模型: {}",
|
log.warn("余额不足阻止AI回复,用户ID: {}, 模型: {}",
|
||||||
chatRequest.getUserId(), chatRequest.getModel());
|
chatRequest.getUserId(), chatRequest.getModel());
|
||||||
throw new RuntimeException(errorMsg);
|
try {
|
||||||
|
emitter.send(errorMsg);
|
||||||
|
emitter.complete();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("推送流异常,用户ID: {}, 模型: {}",
|
||||||
|
chatRequest.getUserId(), chatRequest.getModel());
|
||||||
|
emitter.complete();
|
||||||
|
throw new RuntimeException(errorMsg);
|
||||||
|
}
|
||||||
|
return emitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("余额检查通过,开始AI回复,用户ID: {}, 模型: {}",
|
log.debug("余额检查通过,开始AI回复,用户ID: {}, 模型: {}",
|
||||||
|
|||||||
Reference in New Issue
Block a user