From 1598fa353f56357e6cf6afc06faf1d634db86cbd Mon Sep 17 00:00:00 2001 From: yml Date: Sat, 21 Nov 2026 22:58:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(douyu):=20=E5=A2=9E=E5=8A=A0=E4=BE=9B?= =?UTF-8?q?=E7=BB=99=E7=9B=AE=E6=A0=87=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/斗鱼/斗鱼账号平台最终实施设计.md | 5 +- web/frontend/src/api/douyu.ts | 9 + web/frontend/src/api/types.ts | 27 ++ .../AccountPlatformStatusPanel.tsx | 308 ++++++++++++++---- 4 files changed, 290 insertions(+), 59 deletions(-) diff --git a/docs/斗鱼/斗鱼账号平台最终实施设计.md b/docs/斗鱼/斗鱼账号平台最终实施设计.md index 7b2acb7..5cc1645 100644 --- a/docs/斗鱼/斗鱼账号平台最终实施设计.md +++ b/docs/斗鱼/斗鱼账号平台最终实施设计.md @@ -11,14 +11,14 @@ 更新时间:2026-11-21 -整体完成度约 **72%**。 +整体完成度约 **73%**。 | 阶段 | 完成度 | 已落地 | 主要缺口 | | --- | ---: | --- | --- | | 阶段 0:止乱 | 100% | 登录批次上限、任务槽隔离、连接及时释放 | 无 | | 阶段 1:同步基础 | 95% | 新表、迁移、storehome 网关、全量快照、同步运行记录、内部工作队列执行器、session/points/gold/elite/esports/role/exchange 同步状态 | 少量旁路查询仍需继续收口 | | 阶段 2:账号与 CK | 90% | CK 周期字段、invalid 分流、登录流水、日/小时/分类/单账号预算、login_relogin 队列真实消费与退避回队、预算配置 API | 更精细的动态预算计算 | -| 阶段 3:商品与供给 | 90% | 全量商品能力、限时窗口、原始响应、供给库存和目标缺口、定向补货入队、供给目标配置 API、默认目标、统一平台状态快照、供给看板、阈值告警 | 供给目标管理 UI、趋势统计 | +| 阶段 3:商品与供给 | 95% | 全量商品能力、限时窗口、原始响应、供给库存和目标缺口、定向补货入队、供给目标配置 API 与管理 UI、默认目标、统一平台状态快照、供给看板、阈值告警 | 趋势统计 | | 阶段 4:安全恢复自动化 | 50% | account_sync_queue 与供给补货作业默认小批量开启,自动重登消费工作队列,硬失败率熔断,登录预算在线配置且熔断阈值实时生效 | 灰度批次自动扩缩和长期趋势告警 | | 阶段 5:清理旧逻辑 | 20% | 履约补货不再直接发官网请求 | 旧资料刷新、旁路查询和旧候选兜底仍需逐步下线 | @@ -610,3 +610,4 @@ Runner 启动前必须有预算 token;没有 token 时留在工作队列。 | --- | --- | | 2026-11-21 | 建立斗鱼账号平台最终实施蓝图 | | 2026-11-21 | 增加保守默认供给目标、账号平台供给看板和库存/CK/工作队列阈值告警 | +| 2026-11-21 | 增加供给目标管理 UI,支持新增、编辑、启停和调整安全库存 | diff --git a/web/frontend/src/api/douyu.ts b/web/frontend/src/api/douyu.ts index 2537d8b..98441c1 100644 --- a/web/frontend/src/api/douyu.ts +++ b/web/frontend/src/api/douyu.ts @@ -5,6 +5,9 @@ import type { DouyuExchangeResultImage, DouyuGoodsItem, DouyuRechargeChannel, + DouyuSupplyTarget, + DouyuSupplyTargetUpdate, + DouyuSupplyTargetUpsert, DouyuTaskAccountItem, DouyuTaskBatchRequest, DouyuTaskBatchResult, @@ -19,6 +22,12 @@ export const douyuApi = { taskTypes: () => api.get, Record>('/douyu/task-types'), getAccountPlatformStatus: () => api.get('/douyu/account-platform-status'), + listSupplyTargets: () => + api.get('/douyu/supply-targets'), + createSupplyTarget: (data: DouyuSupplyTargetUpsert) => + api.post('/douyu/supply-targets', data), + updateSupplyTarget: (targetId: number, data: DouyuSupplyTargetUpdate) => + api.put(`/douyu/supply-targets/${targetId}`, data), listAccounts: (params?: { search?: string; tag?: string; ids?: string }) => api.get('/douyu/accounts', { params }), listAccountsPaged: (params: PageParams & { ids?: string; tag?: string }) => diff --git a/web/frontend/src/api/types.ts b/web/frontend/src/api/types.ts index ab1ec8d..8a98493 100644 --- a/web/frontend/src/api/types.ts +++ b/web/frontend/src/api/types.ts @@ -745,6 +745,33 @@ export interface DouyuSupplyTargetStatus { needs_replenishment: boolean; } +export interface DouyuSupplyTarget extends DouyuSupplyTargetStatus { + platform: string; + enabled: boolean; + updated_by: number | null; + updated_at: string | null; +} + +export interface DouyuSupplyTargetUpsert { + platform?: 'douyu'; + scope: string; + commodity_id: string; + value_class: 'high_value' | 'ordinary'; + target_covered: number; + target_available: number; + target_allocatable: number; + safety_buffer: number; + enabled: boolean; +} + +export interface DouyuSupplyTargetUpdate { + target_covered: number; + target_available: number; + target_allocatable: number; + safety_buffer: number; + enabled: boolean; +} + export interface DouyuPlatformAlert { code: string; severity: 'critical' | 'warning' | 'info'; diff --git a/web/frontend/src/pages/douyu-tasks/AccountPlatformStatusPanel.tsx b/web/frontend/src/pages/douyu-tasks/AccountPlatformStatusPanel.tsx index c11dc28..3e5357b 100644 --- a/web/frontend/src/pages/douyu-tasks/AccountPlatformStatusPanel.tsx +++ b/web/frontend/src/pages/douyu-tasks/AccountPlatformStatusPanel.tsx @@ -5,20 +5,28 @@ import { Card, Col, Empty, + Form, + Input, + InputNumber, + Modal, Row, + Select, Space, Statistic, + Switch, Table, Tag, Typography, } from 'antd'; import type { TableProps } from 'antd'; -import { ReloadOutlined } from '@ant-design/icons'; +import { EditOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons'; import { douyuApi, type DouyuAccountPlatformStatus, - type DouyuSupplyTargetStatus, + type DouyuSupplyTarget, } from '../../api/modules'; +import { usePermissions } from '../../hooks/usePermissions'; +import { message } from '../../utils/antdMessage'; import { getErrorMessage } from '../../utils/error'; import { formatTime } from '../../utils/time'; @@ -34,22 +42,52 @@ function targetTotal(actual: number, target: number, buffer: number) { return `${actual}/${effectiveTarget || '-'}`; } +interface TargetFormValues { + scope: string; + commodity_id?: string; + value_class: 'high_value' | 'ordinary'; + target_covered: number; + target_available: number; + target_allocatable: number; + safety_buffer: number; + enabled: boolean; +} + export default function AccountPlatformStatusPanel() { + const { can } = usePermissions(); + const canManage = can('douyu:config'); + const [form] = Form.useForm(); const [status, setStatus] = useState(null); + const [targets, setTargets] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); + const [modalOpen, setModalOpen] = useState(false); + const [saving, setSaving] = useState(false); + const [editing, setEditing] = useState(null); const load = useCallback(async () => { setLoading(true); setError(''); try { - setStatus(await douyuApi.getAccountPlatformStatus()); + const platformStatus = await douyuApi.getAccountPlatformStatus(); + if (canManage) { + setTargets(await douyuApi.listSupplyTargets()); + } else { + setTargets(platformStatus.supply_targets.map((row) => ({ + ...row, + platform: 'douyu', + enabled: true, + updated_by: null, + updated_at: null, + }))); + } + setStatus(platformStatus); } catch (loadError: unknown) { setError(getErrorMessage(loadError)); } finally { setLoading(false); } - }, []); + }, [canManage]); useEffect(() => { void load(); @@ -63,7 +101,69 @@ export default function AccountPlatformStatusPanel() { [status?.work_queue], ); - const columns: TableProps['columns'] = [ + const openCreate = () => { + setEditing(null); + form.setFieldsValue({ + scope: 'elite', + commodity_id: '', + value_class: 'high_value', + target_covered: 30, + target_available: 20, + target_allocatable: 10, + safety_buffer: 3, + enabled: true, + }); + setModalOpen(true); + }; + + const openEdit = (target: DouyuSupplyTarget) => { + setEditing(target); + form.setFieldsValue({ + scope: target.scope, + commodity_id: target.commodity_id, + value_class: target.value_class, + target_covered: target.target_covered, + target_available: target.target_available, + target_allocatable: target.target_allocatable, + safety_buffer: target.safety_buffer, + enabled: target.enabled, + }); + setModalOpen(true); + }; + + const saveTarget = async () => { + const values = await form.validateFields(); + setSaving(true); + try { + const payload = { + target_covered: Number(values.target_covered || 0), + target_available: Number(values.target_available || 0), + target_allocatable: Number(values.target_allocatable || 0), + safety_buffer: Number(values.safety_buffer || 0), + enabled: Boolean(values.enabled), + }; + if (editing) { + await douyuApi.updateSupplyTarget(editing.target_id, payload); + } else { + await douyuApi.createSupplyTarget({ + platform: 'douyu', + scope: values.scope, + commodity_id: (values.commodity_id || '').trim(), + value_class: values.value_class, + ...payload, + }); + } + message.success(editing ? '供给目标已更新' : '供给目标已创建'); + setModalOpen(false); + await load(); + } catch (saveError: unknown) { + message.error(getErrorMessage(saveError)); + } finally { + setSaving(false); + } + }; + + const columns: TableProps['columns'] = [ { title: '分类', width: 130, @@ -100,69 +200,163 @@ export default function AccountPlatformStatusPanel() { row.available_shortage, row.allocatable_shortage, ); - return shortage > 0 ? {shortage} : 0; + return shortage > 0 + ? {shortage} + : 0; }, }, { title: '状态', - width: 100, + width: 110, render: (_, row) => ( - row.needs_replenishment - ? 需补货 - : 达标 + !row.enabled + ? 已停用 + : row.needs_replenishment + ? 需补货 + : 达标 ), }, + ...(canManage ? [{ + title: '操作', + width: 80, + render: (_: unknown, row: DouyuSupplyTarget) => ( + + ), + }] : []), ]; return ( - - - {status?.checked_at ? formatTime(status.checked_at) : '-'} - - - - )} - > - {error ? : null} - - - - - - + <> + + + {status?.checked_at ? formatTime(status.checked_at) : '-'} + + {canManage ? ( + + ) : null} + + + )} + > + {error ? : null} + + + + + + - {status?.alerts.length ? ( - - {status.alerts.map((alert) => ( - - ))} - - ) : null} + {status?.alerts.length ? ( + + {status.alerts.map((alert) => ( + + ))} + + ) : null} - - ), - }} - /> - +
+ ), + }} + /> + + + void saveTarget()} + onCancel={() => setModalOpen(false)} + okText="保存" + cancelText="取消" + destroyOnHidden + > +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); }