| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- /**
- * 册10 SC-03 执行记录与轮次详情。
- * 契约:docs/.../10-第10册-定时任务与审计视图/14-页面契约本册逐页.md §14.2、作业§4.4/§4.5。
- * 接线现状:`/jobs/runs@v1` [实]——五件筛选(关键字/任务/触发方式/结果/日期区间)、
- * `page` 0 基翻页、留存期总数 N 与命中数 M 分列下发;标注行返回空流水说明(⛔ 显 0)。
- * 关键字当前只检索轮次字段(平台 R-1 `object_keyword` 未交付)⇒ `W22` 常驻。
- */
- import { useMemo, useState, type ReactNode } from "react";
- import { Check, Search, X } from "lucide-react";
- import { OpsDialog, OpsStatus, OpsTableColumns } from "../components/OperationsKit";
- import { Button } from "../components/ui/button";
- import { FilterSelect } from "../components/ui/filter-select";
- import { Input } from "../components/ui/input";
- import {
- fmtDateTime,
- fmtDuration,
- last7Days,
- useJobRuns,
- EMPTY_RUNS_FILTER,
- type JobListRow,
- type RunsFilter,
- } from "../lib/scheduled-jobs";
- import {
- RESULT_WORDS,
- ROUND_DETAIL_EMPTY,
- RUNS_EMPTY,
- TRIGGER_WORDS,
- W18A,
- W18B,
- W18C,
- W18D,
- W18E_FROM,
- W18E_TO,
- W19,
- W20,
- W21_ABNORMAL,
- W21_LAST7,
- W21_RESET,
- W22,
- W23_DETAIL,
- W23_GOTO,
- W27,
- W28,
- w16,
- w17,
- w26,
- w29,
- } from "../lib/copy-jobs";
- import type { JobRunRow } from "../lib/api/types";
- import { useNavigate } from "react-router";
- export interface JobRunsPreset {
- jobKey: string;
- jobName: string;
- }
- export function JobRunsDialog({ preset, rows, onClose }: { preset: JobRunsPreset; rows: JobListRow[]; onClose: () => void }) {
- const navigate = useNavigate();
- const [filter, setFilter] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset.jobKey });
- const [applied, setApplied] = useState<RunsFilter>({ ...EMPTY_RUNS_FILTER, jobKey: preset.jobKey });
- const [detail, setDetail] = useState<JobRunRow | null>(null);
- const state = useJobRuns(applied);
- const jobOptions = useMemo(() => rows.filter((row) => !row.annotation), [rows]);
- const recentDates = last7DaysFilter();
- const recentSelected = applied.dateFrom === recentDates.dateFrom && applied.dateTo === recentDates.dateTo;
- const abnormalSelected = applied.result === "异常";
- const apply = (next: RunsFilter) => {
- setFilter(next);
- setApplied(next);
- };
- // W16:N 为服务端留存期总数,M 为当前已装载轮次。
- const title = w16(state.retentionTotal === null ? "—" : String(state.retentionTotal), state.runs.length);
- return (
- <OpsDialog title={title} subtitle="按轮次查看执行流水" className="job-runs-dialog" onClose={onClose}>
- <div className="job-runs-body">
- <p className="ops-import-note">{w17(preset.jobName)}</p>
- <div className="ops-toolbar scheduled-jobs-filters">
- <label className="ops-search">
- <Search size={16} />
- <Input
- aria-label="关键字"
- placeholder={W18A}
- value={filter.keyword}
- onChange={(event) => setFilter({ ...filter, keyword: event.target.value })}
- />
- {filter.keyword && (
- <button aria-label="清空关键字" type="button" onClick={() => setFilter({ ...filter, keyword: "" })}>
- <X size={14} />
- </button>
- )}
- </label>
- <FilterSelect icon="task" aria-label="按任务筛选" value={filter.jobKey} onChange={(event) => setFilter({ ...filter, jobKey: event.target.value })}>
- <option value="">{W18B}</option>
- {jobOptions.map((row) => (
- <option key={row.key} value={row.key}>
- {row.meta?.displayName ?? row.registryName}
- </option>
- ))}
- </FilterSelect>
- <FilterSelect icon="trigger" aria-label="按触发方式筛选" value={filter.trigger} onChange={(event) => setFilter({ ...filter, trigger: event.target.value })}>
- <option value="">{W18C}</option>
- {TRIGGER_WORDS.map((word) => (
- <option key={word}>{word}</option>
- ))}
- </FilterSelect>
- <FilterSelect icon="status" aria-label="按执行结果筛选" value={filter.result} onChange={(event) => setFilter({ ...filter, result: event.target.value })}>
- <option value="">{W18D}</option>
- {RESULT_WORDS.map((word) => (
- <option key={word}>{word}</option>
- ))}
- <option value="异常">{W19}</option>
- </FilterSelect>
- <Input aria-label={W18E_FROM} type="date" value={filter.dateFrom} onChange={(event) => setFilter({ ...filter, dateFrom: event.target.value })} />
- <Input aria-label={W18E_TO} type="date" value={filter.dateTo} onChange={(event) => setFilter({ ...filter, dateTo: event.target.value })} />
- <Button size="sm" type="button" onClick={() => apply(filter)}>
- 查询
- </Button>
- <Button size="sm" type="button" variant="ghost" onClick={() => apply({ ...EMPTY_RUNS_FILTER })}>
- {W21_RESET}
- </Button>
- </div>
- <div className="ops-toolbar">
- <Button
- size="sm"
- type="button"
- variant={recentSelected ? "default" : "outline"}
- aria-pressed={recentSelected}
- onClick={() => apply({ ...filter, ...(recentSelected ? { dateFrom: "", dateTo: "" } : recentDates) })}
- >
- {recentSelected && <Check size={14} aria-hidden="true" />}
- {W21_LAST7}
- </Button>
- <Button
- size="sm"
- type="button"
- variant={abnormalSelected ? "default" : "outline"}
- aria-pressed={abnormalSelected}
- onClick={() => apply({ ...filter, result: abnormalSelected ? "" : "异常" })}
- >
- {abnormalSelected && <Check size={14} aria-hidden="true" />}
- {W21_ABNORMAL}
- </Button>
- </div>
- {/* 平台 R-1(object_keyword 入参)未交付 ⇒ W22 常驻(契约 作业§4.4.6) */}
- <p className="ops-import-note">{W22}</p>
- {state.error ? (
- <p className="ops-form-error" role="alert">
- {W20}:{state.error} <Button size="sm" type="button" variant="outline" onClick={state.reload}>重试</Button>
- </p>
- ) : state.annotationMessage ? (
- <div className="ops-empty">{state.annotationMessage}</div>
- ) : state.loading && state.runs.length === 0 ? (
- <p className="ops-empty">正在加载…</p>
- ) : state.runs.length === 0 ? (
- <div className="ops-empty">{RUNS_EMPTY}</div>
- ) : (
- <div className="ops-list-shell">
- <div className="job-runs-table">
- <table className="ops-table" role="table" aria-label="执行流水">
- <OpsTableColumns widths={[15, 16, 11, 17, 17, 13, 11]} />
- <thead role="rowgroup">
- <tr role="row">
- <th scope="col">执行编号</th>
- <th scope="col">任务</th>
- <th scope="col">触发 / 执行人</th>
- <th scope="col">执行时间</th>
- <th scope="col">对象处理<small>扫描 / 命中 / 成功 / 跳过 / 失败</small></th>
- <th scope="col">结果 / 处置</th>
- <th scope="col">操作</th>
- </tr>
- </thead>
- <tbody role="rowgroup">
- {state.runs.map((run) => (
- <RunRow key={run.run_id} run={run} rows={rows} onDetail={() => setDetail(run)} onGoto={(page) => { onClose(); navigate(page); }} />
- ))}
- </tbody>
- </table>
- </div>
- {state.hasMore && (
- <div className="ops-toolbar" style={{ justifyContent: "center" }}>
- <Button size="sm" type="button" variant="outline" disabled={state.loadingMore} onClick={state.loadMore}>
- {state.loadingMore ? "加载中…" : `加载更多(已显示 ${state.runs.length}/${state.matchedTotal ?? "—"} 条命中)`}
- </Button>
- </div>
- )}
- </div>
- )}
- </div>
- {detail && <RoundDialog run={detail} rows={rows} onClose={() => setDetail(null)} />}
- </OpsDialog>
- );
- }
- function last7DaysFilter(): Pick<RunsFilter, "dateFrom" | "dateTo"> {
- const { from, to } = last7Days();
- return { dateFrom: from, dateTo: to };
- }
- function RunCell({ label, children }: { label: string; children: ReactNode }) {
- return (
- <td role="cell">
- <span className="job-run-cell-label" aria-hidden="true">{label}</span>
- {children}
- </td>
- );
- }
- function RunText({ children }: { children: string }) {
- return <span className="job-run-text" title={children}>{children}</span>;
- }
- function RunRow({ run, rows, onDetail, onGoto }: { run: JobRunRow; rows: JobListRow[]; onDetail: () => void; onGoto: (page: string) => void }) {
- const meta = rows.find((row) => row.key === run.job_key);
- const gotoPage = run.goto_page;
- const executor = run.trigger === "人工" ? run.actor_user_id ?? "—" : "系统";
- const duration = fmtDuration(run.started_at, run.finished_at);
- const counts = [run.scanned, run.matched, run.succeeded, run.skipped, run.failed].join(" / ");
- return (
- <tr role="row">
- <RunCell label="执行编号"><code className="ops-mono"><RunText>{run.run_id}</RunText></code></RunCell>
- <RunCell label="任务">
- <RunText>{run.job_name ?? meta?.displayName ?? run.job_key}</RunText>
- <small className="ops-mono"><RunText>{run.job_key}</RunText></small>
- </RunCell>
- <RunCell label="触发 / 执行人">
- <RunText>{run.trigger || "—"}</RunText>
- <small><RunText>{executor}</RunText></small>
- </RunCell>
- <RunCell label="执行时间">
- <RunText>{fmtDateTime(run.started_at)}</RunText>
- {run.finished_at && <small><RunText>{`完成 ${fmtDateTime(run.finished_at)}`}</RunText></small>}
- <small><RunText>{`耗时 ${duration}`}</RunText></small>
- </RunCell>
- <RunCell label="对象处理(扫描 / 命中 / 成功 / 跳过 / 失败)">
- <code className="ops-mono"><RunText>{counts}</RunText></code>
- </RunCell>
- <RunCell label="结果 / 处置">
- <OpsStatus tone={run.status === "成功" ? "success" : run.status === "失败" ? "danger" : "warning"}>
- <RunText>{run.status}</RunText>
- </OpsStatus>
- {run.disposition_code !== "none" && run.disposition && <small><RunText>{run.disposition}</RunText></small>}
- </RunCell>
- <RunCell label="操作">
- <div className="ops-table-actions">
- <button className="ops-table-action" type="button" onClick={onDetail}>
- {W23_DETAIL}
- </button>
- {run.disposition_code === "pending_rerun" && run.goto_visible && gotoPage && (
- <button className="ops-table-action" type="button" onClick={() => onGoto(gotoPage)}>
- {W23_GOTO}
- </button>
- )}
- </div>
- </RunCell>
- </tr>
- );
- }
- /** 轮次弹窗(契约 作业§4.5):计数卡五格+结果说明+对象级明细区。 */
- function RoundDialog({ run, rows, onClose }: { run: JobRunRow; rows: JobListRow[]; onClose: () => void }) {
- const meta = rows.find((row) => row.key === run.job_key);
- const interrupted = run.scanned === 0 && run.matched === 0 && run.status === "失败";
- const detail = run.detail ?? [];
- const violations = run.violations ?? [];
- return (
- <OpsDialog title={w26(run.run_id)} className="job-round-dialog" onClose={onClose}>
- <div className="job-runs-body">
- <p className="ops-import-note">
- {run.job_name ?? meta?.displayName ?? run.job_key}
- {interrupted ? W28 : W27}
- </p>
- <div className="ops-stat-strip">
- <div><span>扫描</span><strong>{run.scanned}</strong></div>
- <div><span>命中</span><strong>{run.matched}</strong></div>
- <div><span>成功</span><strong>{run.succeeded}</strong></div>
- <div><span>跳过</span><strong>{run.skipped}</strong></div>
- <div><span>失败</span><strong>{run.failed}</strong></div>
- </div>
- {run.message && <p className="ops-import-note">{run.message}</p>}
- {run.period && <p className="ops-import-note">账期:{run.period}</p>}
- {run.biz_date && <p className="ops-import-note">业务日:{run.biz_date}</p>}
- <p className="ops-import-note" role="status">{w29(detail.length)}</p>
- {detail.length === 0 ? (
- <p className="ops-import-note">{ROUND_DETAIL_EMPTY}</p>
- ) : (
- <div className="ops-list-shell job-round-table" role="region" aria-label="轮次对象明细,可滚动" tabIndex={0}>
- <table className="ops-table">
- <thead>
- <tr>
- <th>对象类型</th>
- <th>对象标识</th>
- <th>处置</th>
- <th>说明</th>
- </tr>
- </thead>
- <tbody>
- {detail.map((item, idx) => (
- <tr key={`${item.object_id ?? item.object_type ?? "row"}-${idx}`}>
- <td>{item.object_type ?? "—"}</td>
- <td className="ops-mono">{item.object_name ?? item.object_id ?? "—"}</td>
- <td>{item.disposition ?? "—"}</td>
- <td>{item.reason ?? "—"}</td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- )}
- {violations.length > 0 && (
- <>
- <p className="ops-import-note">跳过/失败原因({violations.length} 条)</p>
- <ul className="ops-import-note">
- {violations.map((v, idx) => (
- <li key={`v-${idx}`}>
- <span className="ops-mono">{v.object_name ?? v.object_id ?? v.object_type ?? "—"}</span>
- {v.reason ? `:${v.reason}` : ""}
- </li>
- ))}
- </ul>
- </>
- )}
- <footer className="job-round-actions">
- <Button type="button" variant="outline" onClick={onClose}>
- 关闭
- </Button>
- </footer>
- </div>
- </OpsDialog>
- );
- }
|