|
@@ -15,6 +15,7 @@ import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
|
|
|
import com.cyksj.service.recharge.DatabaseChannelManager;
|
|
import com.cyksj.service.recharge.DatabaseChannelManager;
|
|
|
import com.cyksj.service.recharge.GptProxyRechargeService;
|
|
import com.cyksj.service.recharge.GptProxyRechargeService;
|
|
|
import com.cyksj.service.recharge.InternalTaskManager;
|
|
import com.cyksj.service.recharge.InternalTaskManager;
|
|
|
|
|
+import com.cyksj.service.recharge.ChannelCardKeyManager;
|
|
|
import com.cyksj.service.recharge.channel.RechargeChannel;
|
|
import com.cyksj.service.recharge.channel.RechargeChannel;
|
|
|
import com.cyksj.service.recharge.dto.TaskResult;
|
|
import com.cyksj.service.recharge.dto.TaskResult;
|
|
|
import com.cyksj.service.recharge.dto.TokenParseResult;
|
|
import com.cyksj.service.recharge.dto.TokenParseResult;
|
|
@@ -49,6 +50,7 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
// 新增的多渠道管理组件
|
|
// 新增的多渠道管理组件
|
|
|
private final DatabaseChannelManager channelManager;
|
|
private final DatabaseChannelManager channelManager;
|
|
|
private final InternalTaskManager taskManager;
|
|
private final InternalTaskManager taskManager;
|
|
|
|
|
+ private final ChannelCardKeyManager cardKeyManager;
|
|
|
private final MultiChannelRechargeExecutor rechargeExecutor;
|
|
private final MultiChannelRechargeExecutor rechargeExecutor;
|
|
|
|
|
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
@@ -266,17 +268,31 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
taskManager.updateTaskStatus(internalTaskId, "failed", null, "所有渠道均充值失败: " + result);
|
|
taskManager.updateTaskStatus(internalTaskId, "failed", null, "所有渠道均充值失败: " + result);
|
|
|
resetGroupsRelationRechargeStatusByInternalTask(internalTaskId, status, result);
|
|
resetGroupsRelationRechargeStatusByInternalTask(internalTaskId, status, result);
|
|
|
} else {
|
|
} else {
|
|
|
- // 还有其他渠道可以尝试,将任务状态重置为pending,等待定时任务重试
|
|
|
|
|
- log.info("当前渠道失败但可重试,将任务重置为pending等待重试: {}", nextChannel.getChannelName());
|
|
|
|
|
|
|
+ // 还有其他渠道可以尝试,立即在业务系统内触发重试(而非等待定时任务)
|
|
|
|
|
+ log.info("当前渠道失败但可重试,立即重试下一个渠道: {}", nextChannel.getChannelName());
|
|
|
// 记录当前渠道的失败日志
|
|
// 记录当前渠道的失败日志
|
|
|
GptTaskExecutionLog lastLog = taskManager.getLastExecutionLog(internalTaskId);
|
|
GptTaskExecutionLog lastLog = taskManager.getLastExecutionLog(internalTaskId);
|
|
|
if (lastLog != null) {
|
|
if (lastLog != null) {
|
|
|
taskManager.logChannelExecution(internalTaskId, lastLog.getChannelCode(),
|
|
taskManager.logChannelExecution(internalTaskId, lastLog.getChannelCode(),
|
|
|
lastLog.getExternalTaskId(), lastLog.getCardKey(), "failed", result, true, null);
|
|
lastLog.getExternalTaskId(), lastLog.getCardKey(), "failed", result, true, null);
|
|
|
|
|
+
|
|
|
|
|
+ // 释放当前渠道的卡密
|
|
|
|
|
+ if (lastLog.getCardKey() != null) {
|
|
|
|
|
+ cardKeyManager.releaseCardKey(lastLog.getCardKey());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 重置任务状态为pending,让定时任务处理重试
|
|
|
|
|
- taskManager.updateTaskStatus(internalTaskId, "pending", null, "等待重试其他渠道");
|
|
|
|
|
|
|
+ // 立即异步触发下一个渠道的重试(业务系统内重试)
|
|
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("异步触发多渠道重试: {}", internalTaskId);
|
|
|
|
|
+ rechargeExecutor.executeRechargeTask(internalTaskId,
|
|
|
|
|
+ taskManager.getInternalTask(internalTaskId).getAccessToken(), null, null);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("异步重试失败: {}", e.getMessage(), e);
|
|
|
|
|
+ taskManager.updateTaskStatus(internalTaskId, "failed", null, "重试异常: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|