feat(account-check): 增加履约账号 CK 保护目标

This commit is contained in:
yml
2026-11-22 09:57:03 +08:00
parent 492288e84f
commit f2041f2444
10 changed files with 1151 additions and 23 deletions
+10
View File
@@ -1,5 +1,7 @@
import api from './client';
import type {
DouyuAccountProtectionTarget,
DouyuAccountProtectionTargetUpdate,
DouyuAccountPlatformStatus,
DouyuConfig,
DouyuExchangeResultImage,
@@ -22,6 +24,14 @@ export const douyuApi = {
taskTypes: () => api.get<Record<string, string>, Record<string, string>>('/douyu/task-types'),
getAccountPlatformStatus: () =>
api.get<DouyuAccountPlatformStatus, DouyuAccountPlatformStatus>('/douyu/account-platform-status'),
updateAccountProtectionTarget: (
groupKey: DouyuAccountProtectionTarget['group_key'],
data: DouyuAccountProtectionTargetUpdate,
) =>
api.put<DouyuAccountProtectionTarget, DouyuAccountProtectionTarget>(
`/douyu/account-protection-targets/${groupKey}`,
data,
),
listSupplyTargets: () =>
api.get<DouyuSupplyTarget[], DouyuSupplyTarget[]>('/douyu/supply-targets'),
createSupplyTarget: (data: DouyuSupplyTargetUpsert) =>
+28
View File
@@ -772,6 +772,32 @@ export interface DouyuSupplyTargetUpdate {
enabled: boolean;
}
export interface DouyuAccountProtectionTarget {
group_key: 'presale_bound' | 'collab_bound';
label: string;
description: string;
enabled: boolean;
target_count: number;
probe_interval_minutes: number;
auto_relogin: boolean;
bound_count: number;
ck_valid: number;
ck_invalid: number;
ck_error: number;
ck_unchecked: number;
without_cookie: number;
target_shortage: number;
probe_due_count: number;
needs_attention: boolean;
}
export interface DouyuAccountProtectionTargetUpdate {
enabled: boolean;
target_count: number;
probe_interval_minutes: number;
auto_relogin: boolean;
}
export interface DouyuPlatformAlert {
code: string;
severity: 'critical' | 'warning' | 'info';
@@ -781,6 +807,7 @@ export interface DouyuPlatformAlert {
value_class?: string;
shortage?: number;
count?: number;
group_key?: string;
}
export interface DouyuQueryTrendDay {
@@ -852,6 +879,7 @@ export interface DouyuAccountPlatformStatus {
fresh_available: number;
fresh_limited: number;
};
protection_targets: DouyuAccountProtectionTarget[];
supply_targets: DouyuSupplyTargetStatus[];
alerts: DouyuPlatformAlert[];
trends: DouyuPlatformTrends;
@@ -20,9 +20,15 @@ import {
Typography,
} from 'antd';
import type { TableProps } from 'antd';
import { EditOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
import {
EditOutlined,
PlusOutlined,
ReloadOutlined,
SafetyCertificateOutlined,
} from '@ant-design/icons';
import {
douyuApi,
type DouyuAccountProtectionTarget,
type DouyuAccountPlatformStatus,
type DouyuSupplyTarget,
} from '../../api/modules';
@@ -54,6 +60,13 @@ interface TargetFormValues {
enabled: boolean;
}
interface ProtectionFormValues {
enabled: boolean;
target_count: number;
probe_interval_minutes: number;
auto_relogin: boolean;
}
interface TrendRow {
date: string;
queryTotal: number;
@@ -68,6 +81,7 @@ export default function AccountPlatformStatusPanel() {
const { can } = usePermissions();
const canManage = can('douyu:config');
const [form] = Form.useForm<TargetFormValues>();
const [protectionForm] = Form.useForm<ProtectionFormValues>();
const [status, setStatus] = useState<DouyuAccountPlatformStatus | null>(null);
const [targets, setTargets] = useState<DouyuSupplyTarget[]>([]);
const [loading, setLoading] = useState(false);
@@ -75,6 +89,10 @@ export default function AccountPlatformStatusPanel() {
const [modalOpen, setModalOpen] = useState(false);
const [saving, setSaving] = useState(false);
const [editing, setEditing] = useState<DouyuSupplyTarget | null>(null);
const [protectionModalOpen, setProtectionModalOpen] = useState(false);
const [protectionSaving, setProtectionSaving] = useState(false);
const [editingProtection, setEditingProtection] =
useState<DouyuAccountProtectionTarget | null>(null);
const load = useCallback(async () => {
setLoading(true);
@@ -218,6 +236,119 @@ export default function AccountPlatformStatusPanel() {
}
};
const openProtectionEdit = (target: DouyuAccountProtectionTarget) => {
setEditingProtection(target);
protectionForm.setFieldsValue({
enabled: target.enabled,
target_count: target.target_count,
probe_interval_minutes: target.probe_interval_minutes,
auto_relogin: target.auto_relogin,
});
setProtectionModalOpen(true);
};
const saveProtectionTarget = async () => {
if (!editingProtection) return;
const values = await protectionForm.validateFields();
setProtectionSaving(true);
try {
await douyuApi.updateAccountProtectionTarget(editingProtection.group_key, {
enabled: Boolean(values.enabled),
target_count: Number(values.target_count || 0),
probe_interval_minutes: Number(values.probe_interval_minutes || 60),
auto_relogin: Boolean(values.auto_relogin),
});
message.success('履约保护目标已更新');
setProtectionModalOpen(false);
await load();
} catch (saveError: unknown) {
message.error(getErrorMessage(saveError));
} finally {
setProtectionSaving(false);
}
};
const protectionColumns: TableProps<DouyuAccountProtectionTarget>['columns'] = [
{
title: '保护分类',
width: 190,
render: (_, row) => (
<Space size={6}>
<SafetyCertificateOutlined />
<Space size={0} orientation="vertical">
<Text strong>{row.label}</Text>
<Text type="secondary" style={{ fontSize: 12 }}>{row.description}</Text>
</Space>
</Space>
),
},
{
title: '当前绑定',
dataIndex: 'bound_count',
width: 90,
},
{
title: '有效 CK / 目标',
width: 130,
render: (_, row) => (
<Space size={4}>
<Text type={row.ck_invalid + row.ck_error > 0 ? 'danger' : undefined}>
{row.ck_valid}
</Text>
<Text type="secondary">/</Text>
<Text>{row.target_count || '未设'}</Text>
</Space>
),
},
{
title: '失效 / 异常',
width: 110,
render: (_, row) => {
const affected = row.ck_invalid + row.ck_error + row.without_cookie;
return affected > 0
? <Text type="danger">{affected}</Text>
: <Text type="success">0</Text>;
},
},
{
title: '巡检间隔',
width: 100,
render: (_, row) => `${row.probe_interval_minutes} 分钟`,
},
{
title: '自动重登',
width: 90,
render: (_, row) => (
row.auto_relogin
? <Tag color="blue">优先</Tag>
: <Tag>不处理</Tag>
),
},
{
title: '状态',
width: 100,
render: (_, row) => {
if (!row.enabled) return <Tag>已停用</Tag>;
if (row.needs_attention) return <Tag color="warning">需关注</Tag>;
return <Tag color="success">正常</Tag>;
},
},
...(canManage ? [{
title: '操作',
width: 110,
render: (_: unknown, row: DouyuAccountProtectionTarget) => (
<Button
type="link"
size="small"
icon={<EditOutlined />}
onClick={() => openProtectionEdit(row)}
>
设置目标
</Button>
),
}] : []),
];
const columns: TableProps<DouyuSupplyTarget>['columns'] = [
{
title: '分类',
@@ -368,10 +499,35 @@ export default function AccountPlatformStatusPanel() {
</Space>
) : null}
<Space orientation="vertical" size={2} style={{ width: '100%', marginTop: 20 }}>
<Text strong>履约保护目标</Text>
<Text type="secondary">
保持预售与外部协作单绑定账号的 CK 有效,失效后优先进入自动重登队列
</Text>
</Space>
<Table
rowKey="group_key"
size="small"
style={{ marginTop: 8 }}
columns={protectionColumns}
dataSource={status?.protection_targets || []}
pagination={false}
scroll={{ x: 950 }}
locale={{
emptyText: (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无履约保护目标" />
),
}}
/>
<Space orientation="vertical" size={2} style={{ width: '100%', marginTop: 20 }}>
<Text strong>账号供给目标</Text>
<Text type="secondary">按高价值、普通账号和商品维度维护可兑换与可分配库存</Text>
</Space>
<Table
rowKey="target_id"
size="small"
style={{ marginTop: 16 }}
style={{ marginTop: 8 }}
columns={columns}
dataSource={targets}
pagination={false}
@@ -464,6 +620,63 @@ export default function AccountPlatformStatusPanel() {
</Form.Item>
</Form>
</Modal>
<Modal
title={editingProtection ? `设置${editingProtection.label}目标` : '设置履约保护目标'}
open={protectionModalOpen}
confirmLoading={protectionSaving}
onOk={() => void saveProtectionTarget()}
onCancel={() => setProtectionModalOpen(false)}
okText="保存"
cancelText="取消"
destroyOnHidden
>
<Form form={protectionForm} layout="vertical">
<Alert
type="info"
showIcon
message={editingProtection?.description}
style={{ marginBottom: 16 }}
/>
<Row gutter={12}>
<Col span={12}>
<Form.Item
name="target_count"
label="目标有效 CK"
tooltip="用于缺口预警;组内当前全部绑定账号都会纳入保护巡检"
>
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
name="probe_interval_minutes"
label="保护巡检间隔"
tooltip="启用后,组内账号至少按此间隔检测一次 CK"
>
<InputNumber
min={15}
max={1440}
precision={0}
addonAfter="分钟"
style={{ width: '100%' }}
/>
</Form.Item>
</Col>
</Row>
<Form.Item name="enabled" label="启用保护" valuePropName="checked">
<Switch />
</Form.Item>
<Form.Item
name="auto_relogin"
label="失效后自动重登"
valuePropName="checked"
tooltip="仍受自动化页面中的 CK 自动重登总开关控制"
>
<Switch />
</Form.Item>
</Form>
</Modal>
</>
);
}