From 2cfe2f7e5c51dc4cb2c312bb8acc4d664779005d Mon Sep 17 00:00:00 2001
From: shimai <shimai@example.com>
Date: Mon, 09 Mar 2026 14:58:05 +0800
Subject: [PATCH] refactor:重构状态等逻辑
---
web-app/src/components/common/OutboundCallWidget.jsx | 35 ++++++++++++++++++++++++++---------
1 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/web-app/src/components/common/OutboundCallWidget.jsx b/web-app/src/components/common/OutboundCallWidget.jsx
index 1a60f0c..c10d531 100644
--- a/web-app/src/components/common/OutboundCallWidget.jsx
+++ b/web-app/src/components/common/OutboundCallWidget.jsx
@@ -6,10 +6,18 @@
const OUTBOUND_JOBS_KEY = 'outbound_call_jobs';
// 活跃状态列表
-const ACTIVE_STATUSES = ['Scheduling', 'InProgress', 'Calling', 'Ringing', 'Answered'];
+const ACTIVE_STATUSES = ['Scheduling', 'Executing', 'Paused', 'Drafted', 'InProgress', 'Calling', 'Ringing', 'Answered'];
// Scheduling 状态 - 此状态变化不需要调用更新API
const SCHEDULING_STATUS = 'Scheduling';
+const BACKEND_STATUSES = ['Scheduling', 'Executing', 'Succeeded', 'Paused', 'Failed', 'Cancelled', 'Drafted'];
+const STATUS_TO_BACKEND = {
+ InProgress: 'Executing',
+ Calling: 'Executing',
+ Ringing: 'Executing',
+ Answered: 'Executing'
+};
+const isActiveStatus = (status) => !status || ACTIVE_STATUSES.includes(status);
/**
* 智能外呼通话显示组件
@@ -139,11 +147,15 @@
const results = await Promise.all(
jobsToUpdate.map(async (job) => {
try {
+ const statusToUpdate = job.backendStatus || job.newStatus;
+ if (!statusToUpdate) {
+ return { success: false, job };
+ }
await OutboundBotAPIService.updateCallStatus({
jobId: job.jobId,
- callStatus: job.newStatus
+ callStatus: statusToUpdate
});
- console.log(`状态更新成功: ${job.jobId} -> ${job.newStatus}`);
+ console.log(`状态更新成功: ${job.jobId} -> ${statusToUpdate}`);
return { success: true, job };
} catch (err) {
console.error(`状态更新失败: ${job.jobId}`, err);
@@ -184,7 +196,7 @@
const now = Date.now();
return jobs.filter(job => {
// 检查是否为活跃状态
- if (ACTIVE_STATUSES.includes(job.callStatus)) {
+ if (isActiveStatus(job.callStatus)) {
// 检查是否超时(2小时)
const elapsed = now - (job.pollStartTime || job.startTime || now);
if (elapsed > 2 * 60 * 60 * 1000) {
@@ -205,7 +217,7 @@
const storedJobs = loadJobsFromStorage();
// 分离成功任务和失败任务
- const successJobs = storedJobs.filter(job => !job.errorCode && ACTIVE_STATUSES.includes(job.callStatus));
+ const successJobs = storedJobs.filter(job => !job.errorCode && isActiveStatus(job.callStatus));
const failedJobs = storedJobs.filter(job => job.errorCode > 0);
if (successJobs.length === 0) {
@@ -234,21 +246,26 @@
if (response?.data) {
const newStatus = response.data.callStatus;
+ if (!newStatus) {
+ return job;
+ }
+ const backendStatus = STATUS_TO_BACKEND[newStatus] || newStatus;
// 如果状态发生变化,更新任务
if (newStatus !== job.callStatus) {
console.log(`任务 ${job.jobId} 状态更新: ${job.callStatus} -> ${newStatus}`);
// 检查是否需要调用后端更新API(排除Scheduling状态)
- if (job.callStatus !== SCHEDULING_STATUS) {
+ if (backendStatus !== SCHEDULING_STATUS && BACKEND_STATUSES.includes(backendStatus)) {
jobsNeedBackendUpdate.push({
...job,
- newStatus
+ newStatus,
+ backendStatus
});
}
// 如果是终态,可以从轮询中移除
- if (!ACTIVE_STATUSES.includes(newStatus)) {
+ if (!isActiveStatus(newStatus)) {
console.log(`任务 ${job.jobId} 达到终态: ${newStatus}`);
return null; // 标记为删除
}
@@ -638,4 +655,4 @@
);
};
-export default OutboundCallWidget;
\ No newline at end of file
+export default OutboundCallWidget;
--
Gitblit v1.8.0