perf(fulfillment): 修复 Outbox 状态版本去重、跨进程实时推送与数据库默认配置
This commit is contained in:
@@ -813,6 +813,8 @@ export interface DouyuSupplyTargetStatus {
|
||||
available_shortage: number;
|
||||
allocatable_shortage: number;
|
||||
needs_replenishment: boolean;
|
||||
checked_at?: string | null;
|
||||
is_stale?: boolean;
|
||||
}
|
||||
|
||||
export interface DouyuSupplyTargetConfig {
|
||||
@@ -951,7 +953,9 @@ export interface DouyuPlatformTrendsResponse {
|
||||
}
|
||||
|
||||
export interface DouyuAccountPlatformSupply {
|
||||
checked_at: string;
|
||||
checked_at: string | null;
|
||||
is_stale?: boolean;
|
||||
max_age_seconds?: number;
|
||||
supply_targets: DouyuSupplyTargetStatus[];
|
||||
alerts: DouyuPlatformAlert[];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { getErrorMessage } from '../utils/error';
|
||||
import { message } from '../utils/antdMessage';
|
||||
import { formatTime } from '../utils/time';
|
||||
import { getUser } from '../store/auth';
|
||||
import { useCollabRealtime } from '../hooks/useCollabRealtime';
|
||||
import { usePermissions } from '../hooks/usePermissions';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
@@ -699,16 +700,42 @@ export default function PlatformFulfillmentPage() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const [realtimePending, setRealtimePending] = useState(false);
|
||||
|
||||
const { connected: realtimeConnected } = useCollabRealtime({
|
||||
enabled: true,
|
||||
path: '/api/platform-fulfillment/ws',
|
||||
onInvalidate: () => {
|
||||
setRealtimePending(true);
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
void loadTasks();
|
||||
}, [loadTasks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!realtimePending) return undefined;
|
||||
const timer = window.setTimeout(() => {
|
||||
setRealtimePending(false);
|
||||
if (document.visibilityState === 'visible') {
|
||||
void loadTasks(true);
|
||||
if (selectedId) void loadDetail(selectedId, true);
|
||||
}
|
||||
}, 300);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [realtimePending, loadTasks, loadDetail, selectedId]);
|
||||
|
||||
// 实时通道正常时仅做 60s 跨进程兜底;断线时降级为 15s 轮询,取消 10s/5s 高频轮询。
|
||||
useEffect(() => {
|
||||
const intervalMs = realtimeConnected ? 60_000 : 15_000;
|
||||
const timer = window.setInterval(() => {
|
||||
if (document.visibilityState === 'visible') void loadTasks(true);
|
||||
}, 10000);
|
||||
if (document.visibilityState !== 'visible') return;
|
||||
void loadTasks(true);
|
||||
if (selectedId) void loadDetail(selectedId, true);
|
||||
}, intervalMs);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [loadTasks]);
|
||||
}, [realtimeConnected, loadTasks, loadDetail, selectedId]);
|
||||
|
||||
useEffect(() => {
|
||||
void platformFulfillmentApi
|
||||
@@ -721,14 +748,6 @@ export default function PlatformFulfillmentPage() {
|
||||
if (selectedId) void loadDetail(selectedId);
|
||||
}, [loadDetail, selectedId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedId) return;
|
||||
const timer = window.setInterval(() => {
|
||||
if (document.visibilityState === 'visible') void loadDetail(selectedId, true);
|
||||
}, 5000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [loadDetail, selectedId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!douyuActionBatchId) return;
|
||||
let stopped = false;
|
||||
|
||||
@@ -161,6 +161,8 @@ export default function AccountPlatformStatusPanel() {
|
||||
const [targetConfigs, setTargetConfigs] = useState<DouyuSupplyTargetConfig[]>([]);
|
||||
const [supplyTargets, setSupplyTargets] = useState<DouyuSupplyTargetStatus[]>([]);
|
||||
const [supplyAlerts, setSupplyAlerts] = useState<DouyuPlatformAlert[]>([]);
|
||||
const [supplyCheckedAt, setSupplyCheckedAt] = useState<string | null>(null);
|
||||
const [supplyIsStale, setSupplyIsStale] = useState(false);
|
||||
const [trends, setTrends] = useState<DouyuPlatformTrends | null>(null);
|
||||
const [trendAlerts, setTrendAlerts] = useState<DouyuPlatformAlert[]>([]);
|
||||
const [statusLoading, setStatusLoading] = useState(false);
|
||||
@@ -209,6 +211,8 @@ export default function AccountPlatformStatusPanel() {
|
||||
const response = await douyuApi.getAccountPlatformSupply();
|
||||
setSupplyTargets(response.supply_targets);
|
||||
setSupplyAlerts(response.alerts);
|
||||
setSupplyCheckedAt(response.checked_at ?? null);
|
||||
setSupplyIsStale(Boolean(response.is_stale));
|
||||
} catch (loadError: unknown) {
|
||||
setSupplyAlerts([{
|
||||
code: 'account_supply_load_failed',
|
||||
@@ -691,7 +695,15 @@ export default function AccountPlatformStatusPanel() {
|
||||
/>
|
||||
|
||||
<Space orientation="vertical" size={2} style={{ width: '100%', marginTop: 20 }}>
|
||||
<Text strong>账号供给目标</Text>
|
||||
<Space size={8} wrap>
|
||||
<Text strong>账号供给目标</Text>
|
||||
{supplyCheckedAt ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
快照时间:{formatTime(supplyCheckedAt)}
|
||||
</Text>
|
||||
) : null}
|
||||
{supplyIsStale ? <Tag color="warning">快照已陈旧</Tag> : null}
|
||||
</Space>
|
||||
<Text type="secondary">按高价值、普通账号和商品维度维护可兑换与可分配库存</Text>
|
||||
</Space>
|
||||
<Table
|
||||
|
||||
Reference in New Issue
Block a user