feat(automation): 增加登录预算动态建议
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import api from "./client";
|
||||
import type {
|
||||
AutomationJobItem,
|
||||
AutomationLoginQuota,
|
||||
AutomationLoginQuotaRecommendation,
|
||||
AutomationManualQueue,
|
||||
AutomationJobUpdate,
|
||||
AutomationJobsResponse,
|
||||
@@ -11,6 +13,17 @@ import type {
|
||||
export const automationApi = {
|
||||
jobs: () =>
|
||||
api.get<AutomationJobsResponse, AutomationJobsResponse>("/automation/jobs"),
|
||||
loginQuota: () =>
|
||||
api.get<AutomationLoginQuota, AutomationLoginQuota>("/automation/login-quota"),
|
||||
loginQuotaRecommendation: () =>
|
||||
api.get<AutomationLoginQuotaRecommendation, AutomationLoginQuotaRecommendation>(
|
||||
"/automation/login-quota/recommendation",
|
||||
),
|
||||
updateLoginQuota: (payload: AutomationLoginQuota) =>
|
||||
api.put<AutomationLoginQuota, AutomationLoginQuota>(
|
||||
"/automation/login-quota",
|
||||
payload,
|
||||
),
|
||||
updateJob: (key: string, payload: AutomationJobUpdate) =>
|
||||
api.patch<AutomationJobItem, AutomationJobItem>(
|
||||
`/automation/jobs/${key}`,
|
||||
|
||||
@@ -1658,6 +1658,43 @@ export interface AutomationJobUpdate {
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
export interface AutomationLoginQuota {
|
||||
daily_attempt_limit: number;
|
||||
hourly_attempt_limit: number;
|
||||
per_account_daily_limit: number;
|
||||
onboarding_daily_limit: number;
|
||||
relogin_high_value_daily_limit: number;
|
||||
relogin_ordinary_daily_limit: number;
|
||||
manual_daily_limit: number;
|
||||
login_concurrency: number;
|
||||
failure_pause_ratio: number;
|
||||
enabled: boolean;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface AutomationLoginQuotaRecommendation {
|
||||
generated_at: string;
|
||||
window_days: number;
|
||||
basis: {
|
||||
valid_accounts: number;
|
||||
valid_high_value: number;
|
||||
valid_ordinary: number;
|
||||
invalid_backlog: number;
|
||||
invalid_high_value: number;
|
||||
invalid_ordinary: number;
|
||||
imported_backlog: number;
|
||||
recent_sample: number;
|
||||
recent_success_rate: number;
|
||||
effective_success_rate: number;
|
||||
expected_daily_invalid: number;
|
||||
required_daily_success: number;
|
||||
manual_reserve: number;
|
||||
};
|
||||
current: AutomationLoginQuota;
|
||||
recommended: Omit<AutomationLoginQuota, "failure_pause_ratio" | "enabled" | "updated_at">;
|
||||
delta: Record<string, number>;
|
||||
}
|
||||
|
||||
export interface AutomationRunOutcome {
|
||||
job_key: string;
|
||||
status: string;
|
||||
|
||||
@@ -15,12 +15,17 @@ import {
|
||||
Typography,
|
||||
} from "antd";
|
||||
import type { ColumnsType } from "antd/es/table";
|
||||
import { ReloadOutlined, ThunderboltOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
CheckCircleOutlined,
|
||||
ReloadOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { message } from "../utils/antdMessage";
|
||||
import { getErrorMessage } from "../utils/error";
|
||||
import {
|
||||
automationApi,
|
||||
type AutomationJobItem,
|
||||
type AutomationLoginQuotaRecommendation,
|
||||
type AutomationManualGroup,
|
||||
type AutomationManualSample,
|
||||
type AutomationRunItem,
|
||||
@@ -38,6 +43,17 @@ const STATUS_TAG: Record<string, { color: string; text: string }> = {
|
||||
skipped: { color: "default", text: "已跳过" },
|
||||
};
|
||||
|
||||
const BUDGET_LABELS: Record<string, string> = {
|
||||
daily_attempt_limit: "每日尝试",
|
||||
hourly_attempt_limit: "每小时尝试",
|
||||
per_account_daily_limit: "单账号每日",
|
||||
onboarding_daily_limit: "首次登录",
|
||||
relogin_high_value_daily_limit: "高价值重登",
|
||||
relogin_ordinary_daily_limit: "普通重登",
|
||||
manual_daily_limit: "人工保留",
|
||||
login_concurrency: "登录并发",
|
||||
};
|
||||
|
||||
function nextRunLabel(job: AutomationJobItem): ReactNode {
|
||||
if (!job.enabled) {
|
||||
return <Typography.Text type="secondary">未启用</Typography.Text>;
|
||||
@@ -70,7 +86,10 @@ export default function AutomationPage() {
|
||||
const [manualGroups, setManualGroups] = useState<AutomationManualGroup[]>([]);
|
||||
const [manualTotal, setManualTotal] = useState(0);
|
||||
const [pendingRelogin, setPendingRelogin] = useState(0);
|
||||
const [budgetRecommendation, setBudgetRecommendation] =
|
||||
useState<AutomationLoginQuotaRecommendation | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [applyingBudget, setApplyingBudget] = useState(false);
|
||||
const [savingKey, setSavingKey] = useState<string | null>(null);
|
||||
const [runningKey, setRunningKey] = useState<string | null>(null);
|
||||
const [forms] = Form.useForm();
|
||||
@@ -80,8 +99,12 @@ export default function AutomationPage() {
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await automationApi.jobs();
|
||||
const [data, recommendation] = await Promise.all([
|
||||
automationApi.jobs(),
|
||||
automationApi.loginQuotaRecommendation(),
|
||||
]);
|
||||
setJobs(data.jobs);
|
||||
setBudgetRecommendation(recommendation);
|
||||
setPendingRelogin(data.pending_relogin ?? 0);
|
||||
setSchedulerEnabled(data.scheduler.enabled);
|
||||
setSchedulerRunning(data.scheduler.running);
|
||||
@@ -161,6 +184,23 @@ export default function AutomationPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const applyBudgetRecommendation = async () => {
|
||||
if (!budgetRecommendation) return;
|
||||
setApplyingBudget(true);
|
||||
try {
|
||||
await automationApi.updateLoginQuota({
|
||||
...budgetRecommendation.current,
|
||||
...budgetRecommendation.recommended,
|
||||
});
|
||||
message.success("登录预算已按建议值更新");
|
||||
await load();
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setApplyingBudget(false);
|
||||
}
|
||||
};
|
||||
|
||||
const manualColumns: ColumnsType<AutomationManualSample> = [
|
||||
{ title: "账号ID", dataIndex: "account_id", width: 80 },
|
||||
{
|
||||
@@ -235,6 +275,24 @@ export default function AutomationPage() {
|
||||
{ title: "说明", dataIndex: "message", ellipsis: true },
|
||||
];
|
||||
|
||||
const budgetRows = budgetRecommendation
|
||||
? Object.entries(BUDGET_LABELS).map(([key, label]) => ({
|
||||
key,
|
||||
label,
|
||||
current: Number(
|
||||
budgetRecommendation.current[
|
||||
key as keyof typeof budgetRecommendation.current
|
||||
] ?? 0,
|
||||
),
|
||||
recommended: Number(
|
||||
budgetRecommendation.recommended[
|
||||
key as keyof typeof budgetRecommendation.recommended
|
||||
] ?? 0,
|
||||
),
|
||||
delta: Number(budgetRecommendation.delta[key] ?? 0),
|
||||
}))
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Space direction="vertical" size="middle" style={{ width: "100%" }}>
|
||||
<Card
|
||||
@@ -398,6 +456,87 @@ export default function AutomationPage() {
|
||||
</Form>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="登录预算建议"
|
||||
extra={
|
||||
<Popconfirm
|
||||
title="应用建议预算?"
|
||||
description="会覆盖当前登录预算;失败率熔断比例和启停状态保持不变。"
|
||||
onConfirm={() => void applyBudgetRecommendation()}
|
||||
disabled={!canManage || !budgetRecommendation}
|
||||
okText="应用"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CheckCircleOutlined />}
|
||||
disabled={!canManage || !budgetRecommendation}
|
||||
loading={applyingBudget}
|
||||
>
|
||||
应用建议值
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
}
|
||||
>
|
||||
{budgetRecommendation ? (
|
||||
<>
|
||||
<Descriptions size="small" column={3} style={{ marginBottom: 16 }}>
|
||||
<Descriptions.Item label="有效账号">
|
||||
{budgetRecommendation.basis.valid_accounts}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="失效积压">
|
||||
{budgetRecommendation.basis.invalid_backlog}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="未登录积压">
|
||||
{budgetRecommendation.basis.imported_backlog}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="近期样本">
|
||||
{budgetRecommendation.basis.recent_sample}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="近期成功率">
|
||||
{budgetRecommendation.basis.recent_success_rate.toFixed(1)}%
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="建议每日成功需求">
|
||||
{budgetRecommendation.basis.required_daily_success}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{budgetRecommendation.basis.recent_sample < 20 ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message="近期样本不足 20 条,建议值暂按保守成功率 70% 计算"
|
||||
/>
|
||||
) : null}
|
||||
<Table
|
||||
rowKey="key"
|
||||
size="small"
|
||||
pagination={false}
|
||||
dataSource={budgetRows}
|
||||
columns={[
|
||||
{ title: "预算项", dataIndex: "label" },
|
||||
{ title: "当前", dataIndex: "current", width: 110 },
|
||||
{ title: "建议", dataIndex: "recommended", width: 110 },
|
||||
{
|
||||
title: "差额",
|
||||
dataIndex: "delta",
|
||||
width: 100,
|
||||
render: (value: number) => (
|
||||
<Typography.Text
|
||||
type={value > 0 ? "success" : value < 0 ? "danger" : "secondary"}
|
||||
>
|
||||
{value > 0 ? `+${value}` : value}
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Typography.Text type="secondary">暂无预算建议</Typography.Text>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="待人工处理"
|
||||
extra={
|
||||
|
||||
Reference in New Issue
Block a user