mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-29 11:01:50 +08:00
Merge pull request #48 from RuoJi6/feat/finding-dedup-1-2-3
feat(findings): 降低重复确认噪音——分组疑似重复建议、候选打分排序、放宽归并验收(方案1+2+3)
This commit is contained in:
14 files changed
+1000
-129
No files matched your search
@@ -192,15 +192,29 @@ function FindingMergeSuggestionCard({
|
||||
onResolve,
|
||||
}: {
|
||||
suggestion: FindingCaseSuggestion;
|
||||
onResolve: (s: FindingCaseSuggestion, accept: boolean) => Promise<void>;
|
||||
onResolve: (s: FindingCaseSuggestion, accept: boolean, excludeIds?: string[]) => Promise<void>;
|
||||
}) {
|
||||
const [expanded, setExpanded] = React.useState(false);
|
||||
const [busy, setBusy] = React.useState(false);
|
||||
const ids = React.useMemo(
|
||||
() => (Array.isArray(s.finding_ids) && s.finding_ids.length > 0 ? s.finding_ids : [s.left_id, s.right_id]),
|
||||
[s.finding_ids, s.left_id, s.right_id],
|
||||
);
|
||||
const [excluded, setExcluded] = React.useState<string[]>([]);
|
||||
React.useEffect(() => {
|
||||
setExcluded((current) => {
|
||||
const next = current.filter((id) => ids.includes(id));
|
||||
return next.length === current.length ? current : next;
|
||||
});
|
||||
}, [ids]);
|
||||
const validExcluded = excluded.filter((id) => ids.includes(id));
|
||||
const included = ids.filter((id) => !validExcluded.includes(id));
|
||||
async function resolve(accept: boolean) {
|
||||
if (busy) return;
|
||||
if (accept && included.length < 2) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await onResolve(s, accept);
|
||||
await onResolve(s, accept, accept ? validExcluded : []);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -209,17 +223,30 @@ function FindingMergeSuggestionCard({
|
||||
<Card size="sm" className="min-w-0">
|
||||
<CardHeader>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge variant="outline">疑似重复 · 待确认</Badge>
|
||||
<Badge variant="outline">疑似重复分组 · {ids.length} 条 · 待确认</Badge>
|
||||
<CardDescription>任务 #{s.task_id}</CardDescription>
|
||||
</div>
|
||||
<CardTitle className="break-words">{s.title}</CardTitle>
|
||||
<CardDescription className="flex flex-wrap gap-3">
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${s.left_id}`}>
|
||||
查看原报告 #{s.left_id}
|
||||
</Link>
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${s.right_id}`}>
|
||||
查看原报告 #{s.right_id}
|
||||
</Link>
|
||||
<CardDescription className="flex flex-col gap-1">
|
||||
{ids.map((id) => (
|
||||
<span key={id} className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={!excluded.includes(id)}
|
||||
disabled={busy}
|
||||
onCheckedChange={(value) =>
|
||||
setExcluded((current) =>
|
||||
value === true
|
||||
? current.filter((item) => item !== id)
|
||||
: [...current.filter((item) => item !== id), id],
|
||||
)
|
||||
}
|
||||
aria-label={`归并时包含上报 #${id}`}
|
||||
/>
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${id}`}>
|
||||
查看原报告 #{id}
|
||||
</Link>
|
||||
</span>
|
||||
))}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
@@ -238,11 +265,12 @@ function FindingMergeSuggestionCard({
|
||||
</Collapsible>
|
||||
</CardContent>
|
||||
<CardFooter className="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="sm" disabled={busy} onClick={() => resolve(true)}>
|
||||
{busy ? <Spinner /> : null}确认归并
|
||||
<Button variant="outline" size="sm" disabled={busy || included.length < 2} onClick={() => resolve(true)}>
|
||||
{busy ? <Spinner /> : null}
|
||||
{included.length === ids.length ? "整组确认归并" : `确认归并所选(${included.length} 条)`}
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" disabled={busy} onClick={() => resolve(false)}>
|
||||
不是同一漏洞
|
||||
整组不是同一漏洞
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
@@ -271,21 +299,39 @@ export function FindingCaseReviewPanel({ taskId, onChange }: { taskId?: string;
|
||||
const [suggestions, setSuggestions] = React.useState<FindingCaseSuggestion[]>([]);
|
||||
const [runs, setRuns] = React.useState<FindingCaseReviewRun[]>([]);
|
||||
const [error, setError] = React.useState("");
|
||||
const [reload, setReload] = React.useState(0);
|
||||
const requestSeq = React.useRef(0);
|
||||
const taskKey = taskId ?? "";
|
||||
const taskKeyRef = React.useRef(taskKey);
|
||||
taskKeyRef.current = taskKey;
|
||||
const previousTaskKey = React.useRef(taskKey);
|
||||
React.useEffect(() => {
|
||||
if (previousTaskKey.current === taskKey) return;
|
||||
previousTaskKey.current = taskKey;
|
||||
setSuggestions([]);
|
||||
setRuns([]);
|
||||
setError("");
|
||||
}, [taskKey]);
|
||||
React.useEffect(() => {
|
||||
const seq = ++requestSeq.current;
|
||||
const requestedTask = taskKey;
|
||||
void reload;
|
||||
let active = true;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
async function load() {
|
||||
try {
|
||||
const [s, r] = await Promise.all([api.findingCaseSuggestions(taskId), api.findingCaseReviewRuns()]);
|
||||
if (active) {
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current) {
|
||||
setSuggestions(s);
|
||||
setRuns(r.filter((x) => !taskId || x.task_id === taskId));
|
||||
setError("");
|
||||
}
|
||||
} catch (e) {
|
||||
if (active) setError((e as Error).message);
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current)
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
if (active) timer = setTimeout(load, 5000);
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current)
|
||||
timer = setTimeout(load, 5000);
|
||||
}
|
||||
}
|
||||
void load();
|
||||
@@ -293,19 +339,29 @@ export function FindingCaseReviewPanel({ taskId, onChange }: { taskId?: string;
|
||||
active = false;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [taskId]);
|
||||
async function resolve(s: FindingCaseSuggestion, accept: boolean) {
|
||||
}, [reload, taskId, taskKey]);
|
||||
async function resolve(s: FindingCaseSuggestion, accept: boolean, excludeIds?: string[]) {
|
||||
const seq = ++requestSeq.current;
|
||||
const requestedTask = taskKey;
|
||||
try {
|
||||
const result = await api.resolveFindingCaseSuggestion(s.id, accept);
|
||||
setSuggestions((v) => v.filter((x) => x.id !== s.id));
|
||||
if (accept && result.case_id !== "0") {
|
||||
toast.success("已归并,请进入文件夹生成统一报告");
|
||||
} else {
|
||||
toast.success("已否决,不会自动再次归并");
|
||||
const result = await api.resolveFindingCaseSuggestion(s.id, accept, excludeIds);
|
||||
if (requestedTask === taskKeyRef.current) {
|
||||
setReload((v) => v + 1);
|
||||
if (seq === requestSeq.current) {
|
||||
setSuggestions((v) => v.filter((x) => x.id !== s.id));
|
||||
if (accept && result.case_id !== "0") {
|
||||
toast.success("已归并,请进入文件夹生成统一报告");
|
||||
} else {
|
||||
toast.success("已否决,不会自动再次归并");
|
||||
}
|
||||
onChange?.();
|
||||
}
|
||||
}
|
||||
onChange?.();
|
||||
} catch (e) {
|
||||
toast.error((e as Error).message);
|
||||
if (requestedTask === taskKeyRef.current) {
|
||||
setReload((v) => v + 1);
|
||||
if (seq === requestSeq.current) toast.error((e as Error).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (
|
||||
|
||||
+5
-2
@@ -651,8 +651,11 @@ export const api = {
|
||||
get<FindingCaseSuggestion[]>(
|
||||
`/exploration/finding-case-suggestions${task ? `?task_id=${encodeURIComponent(task)}` : ""}`,
|
||||
),
|
||||
resolveFindingCaseSuggestion: (id: string, accept: boolean) =>
|
||||
post<{ case_id: string }>(`/exploration/finding-case-suggestions/${id}`, { accept }),
|
||||
resolveFindingCaseSuggestion: (id: string, accept: boolean, excludeIds?: string[]) =>
|
||||
post<{ case_id: string }>(`/exploration/finding-case-suggestions/${id}`, {
|
||||
accept,
|
||||
...(excludeIds && excludeIds.length > 0 ? { exclude_ids: excludeIds } : {}),
|
||||
}),
|
||||
reviewFindingCases: (ids: string[]) =>
|
||||
post<{ runs: { conversation_id: number; task_id: string }[] }>("/exploration/finding-case-review", {
|
||||
finding_ids: ids,
|
||||
|
||||
@@ -2587,7 +2587,8 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
const from = q.get("from") || "";
|
||||
const to = q.get("to") || "";
|
||||
if (status && !["pending", "allowed", "denied", "timeout"].includes(status)) throw new Error("无效审批状态");
|
||||
if (decisionSource && !["model", "rule", "manual", "unknown"].includes(decisionSource)) throw new Error("无效判定来源");
|
||||
if (decisionSource && !["model", "rule", "manual", "unknown"].includes(decisionSource))
|
||||
throw new Error("无效判定来源");
|
||||
if ([...search].length > 200) throw new Error("搜索关键词不能超过 200 个字符");
|
||||
if (search.startsWith("#") && !/^#[1-9]\d*$/.test(search)) throw new Error("审批编号必须为 # 后接正整数");
|
||||
for (const value of [from, to]) {
|
||||
|
||||
@@ -1782,6 +1782,7 @@ export interface FindingCaseSuggestion {
|
||||
task_id: string;
|
||||
left_id: string;
|
||||
right_id: string;
|
||||
finding_ids: string[];
|
||||
title: string;
|
||||
reason: string;
|
||||
state: string;
|
||||
|
||||
Reference in new issue
Block a user