| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- /**
- * 「交付现状」表(讨论稿 §7.7)—— 客户详情页签与订阅详情「当前资源」区块**共用一份**。
- *
- * 四条口径(缺一条这张表就会误导人):
- * 1. **以订阅为轴、账号为行、IP 为展开行**:一个账号两个 IP ⇒ 两行(⛔ 只显示第一个 IP);
- * 2. **申报带宽与实测带宽两列并排**(第 5 册 §2.4):合成一列必然有人拿实测值去对合同,
- * 也必然有人拿档位去判断「客户实际没跑满」;
- * 3. **出口同样两列**:合同 `line_exits` 是批准集合、实测 `egress_pop` 是实际落地 POP;
- * 不一致时**标红并同时显示**,⛔ 用实测覆盖合同、也⛔ 用合同盖掉实测;
- * 4. **实测列头带测值日期**:实测参数记录的是「最后一次交付时测到的值」,⛔ 显示成「现在的带宽」。
- *
- * ⚠️ **没有「端口段」列**(D-6):端口列恒 `NULL`,显示它只能是整列「—」,反而让运营以为该填。
- *
- * 三态:在用(正常)/已到期待回收(黄色警示,运营要盯的那一批)/已回收(灰,需勾选才显示)。
- */
- import { useMemo, useState } from "react";
- import { Download, RefreshCcw, Search } from "lucide-react";
- import { Button } from "./ui/button";
- import { Input } from "./ui/input";
- import { FilterSelect } from "./ui/filter-select";
- import { OpsStatus, OpsTableEmpty, OpsTableColumns, type OpsTone } from "./OperationsKit";
- import { Tri } from "./triState";
- import { deliveryExport, deliveryList } from "../lib/api/bos";
- import type { ApiError } from "../lib/api/http";
- import type { DeliveryRow } from "../lib/api/types";
- import { useLoad } from "../lib/useLoad";
- import { LIST_PAGE_SIZE } from "../lib/list-paging";
- import { ListPager } from "./ListPager";
- import "../styles/operations.css";
- const MISSING = "后端未下发";
- /** 交付现状默认每页条数=前端台账口径,由本组件请求下推。 */
- const PAGE_SIZE = LIST_PAGE_SIZE;
- const STATE_LABEL: Record<string, string> = {
- in_use: "在用",
- pending_release: "已到期待回收",
- released: "已回收",
- };
- const stateTone = (state: string): OpsTone =>
- state === "pending_release" ? "warning" : state === "released" ? "neutral" : "success";
- const PLAN_FAMILY_LABEL: Record<string, string> = { link: "跨境", addon: "叠加" };
- const IP_TYPE_LABEL: Record<string, string> = { fixed_ip: "固定 IP", nat_forward: "NAT 转发" };
- const RELEASE_REASON_LABEL: Record<string, string> = {
- expiry_stop: "到期停机",
- service_stop: "提前停机",
- updown: "升降配替换",
- rebind: "换绑",
- manual: "人工销账",
- };
- /** 申报带宽:跨境账号取档位上下行,IP 侧取台账 `bandwidth_mbps`(D-18 后叠加档不带带宽)。 */
- function declaredBandwidth(row: DeliveryRow): string {
- if (row.plan_family === "link" && (row.plan_bandwidth_down_mbps !== null || row.plan_bandwidth_up_mbps !== null)) {
- const down = row.plan_bandwidth_down_mbps === null ? "—" : `${row.plan_bandwidth_down_mbps}`;
- const up = row.plan_bandwidth_up_mbps === null ? "—" : `${row.plan_bandwidth_up_mbps}`;
- return `下行 ${down} / 上行 ${up} Mbps(档位)`;
- }
- return row.declared_bandwidth_mbps === null ? "" : `${row.declared_bandwidth_mbps} Mbps`;
- }
- function bandwidthText(down: number | null, up: number | null): string {
- if (down === null && up === null) return "";
- return `下行 ${down === null ? "—" : down} / 上行 ${up === null ? "—" : up} Mbps`;
- }
- function exitText(list: string[] | null | undefined): string {
- return (list ?? []).map((item) => String(item).trim()).filter(Boolean).join("、");
- }
- function accountText(row: DeliveryRow): string {
- return (row.display_name ?? "").trim() || (row.username ?? "").trim();
- }
- export type DeliveryStatusTableProps = {
- /** 客户详情页签:按客户取数。 */
- customerId?: string;
- /** 订阅详情「当前资源」:按订阅取数(与客户二选一,优先 subscriptionId)。 */
- subscriptionId?: string;
- /** 订阅详情里不重复渲染「所属订阅」列与筛选栏(外框已有上下文)。 */
- compact?: boolean;
- };
- export function DeliveryStatusTable({ customerId, subscriptionId, compact = false }: DeliveryStatusTableProps) {
- const [keyword, setKeyword] = useState("");
- const [state, setState] = useState<"live" | "in_use" | "pending_release" | "released" | "all">("live");
- const [page, setPage] = useState(0);
- const [exportBusy, setExportBusy] = useState(false);
- const [exportError, setExportError] = useState("");
- const [exportNotice, setExportNotice] = useState("");
- // 三态映射:`live`(默认)=不传 state ⇒ 后端按「在用+已到期待回收」;其余精确过滤。
- const query = useMemo(
- () => ({
- ...(subscriptionId ? { subscription_id: subscriptionId } : { customer_id: customerId }),
- ...(keyword.trim() ? { keyword: keyword.trim() } : {}),
- ...(state === "live" ? {} : { state }),
- page,
- page_size: PAGE_SIZE,
- }),
- [customerId, subscriptionId, keyword, state, page],
- );
- const load = useLoad(() => deliveryList(query), [query]);
- const rows = load.data?.items ?? [];
- const total = load.data?.total ?? 0;
- // 测值日期:同页可能跨多次回填 ⇒ 列头取本页最新一条,逐行日期另在「实测日期」列给出。
- const measuredOn = useMemo(() => {
- const dates = rows.map((row) => (row.measured_at ?? "").trim()).filter(Boolean).sort();
- return dates.length ? dates[dates.length - 1] : "";
- }, [rows]);
- async function runExport() {
- setExportBusy(true);
- setExportError("");
- setExportNotice("");
- try {
- const res = await deliveryExport(query);
- setExportNotice(`已生成 ${res.row_count} 行(${res.file_name}),可交运维在对象存储下载;本次导出已留痕。`);
- } catch (e) {
- setExportError((e as ApiError)?.message || "导出失败");
- } finally {
- setExportBusy(false);
- }
- }
- const columns = compact
- ? ["账号", "网络账户名", "账号状态", "开通日", "到期日", "合同出口", "实测出口", "内网 IP", "申报带宽", "实测带宽", "境外 IP", "IP 出口", "IP 类型", "来源回填单号", "状态"]
- : ["账号", "网络账户名", "所属订阅", "账号状态", "开通日", "到期日", "合同出口", "实测出口", "内网 IP", "申报带宽", "实测带宽", "境外 IP", "IP 出口", "IP 类型", "来源回填单号", "状态"];
- const colSpan = columns.length;
- return <div className="ops-delivery-status">
- {!compact && <div className="ops-toolbar">
- <label className="ops-search"><Search size={17} /><Input aria-label="搜索交付现状" placeholder="搜索账号、网络侧账号名、境外 IP 或档位名" value={keyword} onChange={(event) => { setKeyword(event.target.value); setPage(0); }} /></label>
- <FilterSelect icon="status" aria-label="在册状态筛选" value={state} onChange={(event) => { setState(event.target.value as typeof state); setPage(0); }}>
- <option value="live">在用+已到期待回收</option>
- <option value="in_use">仅在用</option>
- <option value="pending_release">仅已到期待回收</option>
- <option value="released">仅已回收</option>
- <option value="all">全部(含已回收)</option>
- </FilterSelect>
- <Button variant="outline" onClick={load.reload}><RefreshCcw size={15} />刷新</Button>
- <Button variant="outline" disabled={exportBusy || !rows.length} onClick={() => void runExport()} title="与列表同一段谓词、同一组列(导出不另立判据)"><Download size={15} />{exportBusy ? "导出中…" : "导出 CSV"}</Button>
- <span className="ops-muted">共 {total} 条;默认只显示「在用」与「已到期待回收」,已回收需在筛选里选。</span>
- </div>}
- {compact && <div className="ops-toolbar">
- <FilterSelect icon="status" aria-label="在册状态筛选" value={state} onChange={(event) => { setState(event.target.value as typeof state); setPage(0); }}>
- <option value="live">在用+已到期待回收</option>
- <option value="in_use">仅在用</option>
- <option value="pending_release">仅已到期待回收</option>
- <option value="released">仅已回收</option>
- <option value="all">全部(含已回收)</option>
- </FilterSelect>
- <Button variant="outline" onClick={load.reload}><RefreshCcw size={15} />刷新</Button>
- {!load.error && !load.loading && <span className="ops-muted">共 {total} 条</span>}
- </div>}
- {exportNotice && <p className="ops-form-note">{exportNotice}</p>}
- {exportError && <p className="ops-form-error" role="alert">{exportError}</p>}
- <div className="ops-table-wrap record-table-scroll" role="region" aria-label="交付现状列表" tabIndex={0}>
- <table className="ops-table">
- <OpsTableColumns widths={compact ? [110, 120, 90, 100, 100, 110, 110, 120, 110, 140, 120, 100, 90, 120, 110] : [110, 120, 140, 90, 100, 100, 110, 110, 120, 110, 140, 120, 100, 90, 120, 110]} />
- <thead><tr>{columns.map((title, index) => <th key={`${title}-${index}`}>{title}{title === "实测带宽" && measuredOn ? <span className="ops-muted">({measuredOn} 测值)</span> : null}</th>)}</tr></thead>
- <tbody>
- {load.error ? <OpsTableEmpty colSpan={colSpan} kind="error" onRetry={load.reload} details={load.error.message}>交付资源加载失败</OpsTableEmpty>
- : load.loading && !rows.length ? <OpsTableEmpty colSpan={colSpan} kind="loading">正在读取交付资源…</OpsTableEmpty>
- : rows.length ? rows.map((row) => {
- const mismatch = row.exit_mismatch === true;
- const account = accountText(row);
- const declared = declaredBandwidth(row);
- const measured = bandwidthText(row.measured_down_mbps, row.measured_up_mbps);
- return <tr key={row.assign_id} className={mismatch ? "ops-delivery-mismatch" : undefined} title={mismatch ? "实测出口不在合同出口集合内:两列同时显示,请核对交付回填或合同出口" : undefined}>
- <td>{account ? account : <Tri tone="missing" text="未开通" title="该账号尚未开通(sub_account.display_name/username 均为空)" />}
- {row.parent_subscription_id ? <><br /><span className="ops-muted">叠加于 {row.parent_subscription_id}</span></> : null}
- {row.username && row.display_name ? <><br /><span className="ops-muted">{row.username}</span></> : null}
- </td>
- <td>{row.net_account?.trim() ? row.net_account : <span className="table-placeholder">未登记</span>}</td>
- {!compact && <td>{row.plan_name ?? <span className="table-placeholder">-</span>}{row.plan_family ? <><br /><span className="ops-muted">{PLAN_FAMILY_LABEL[row.plan_family] ?? row.plan_family}</span></> : null}</td>}
- <td>{row.account_status ? <OpsStatus tone={row.account_status === "active" || row.account_status === "in_use" ? "success" : row.account_status === "stopped" || row.account_status === "disabled" ? "danger" : "neutral"}>{row.account_status}</OpsStatus> : <Tri tone="missing" text={MISSING} title={MISSING + ":sub_account.status"} />}</td>
- <td>{row.opened_at ?? <span className="ops-muted table-placeholder">—(未开通)</span>}</td>
- <td>{row.sub_end_date ?? <span className="ops-muted">长期有效</span>}</td>
- <td>{exitText(row.contract_exits) || <Tri tone="missing" text={MISSING} title={MISSING + ":subscription.line_exits"} />}</td>
- <td className={mismatch ? "ops-delivery-mismatch-cell" : undefined}>{row.measured_egress ?? <span className="ops-muted table-placeholder" title="该账号没有成功的开通回填,无实测值">无实测</span>}
- {mismatch ? <><br /><span className="ops-muted">不在合同出口集合内</span></> : null}</td>
- <td>{row.intranet_ip ?? <span className="ops-muted table-placeholder">无实测</span>}</td>
- <td>{declared ? <span className="table-number">{declared}</span> : <span className="table-placeholder">—</span>}</td>
- <td>{measured ? <span className="table-number">{measured}</span> : <span className="ops-muted table-placeholder">无实测</span>}</td>
- <td>{row.overseas_ip ?? <span className="ops-muted table-placeholder">—(已释放)</span>}</td>
- <td>{row.ip_egress ?? <span className="ops-muted table-placeholder">—(已释放)</span>}</td>
- <td>{row.ip_type ? IP_TYPE_LABEL[row.ip_type] ?? row.ip_type : <span className="table-placeholder">—</span>}</td>
- <td>{row.source_ticket_no ?? <span className="table-placeholder">—</span>}</td>
- <td><OpsStatus tone={stateTone(row.state)}>{STATE_LABEL[row.state] ?? row.state}</OpsStatus>
- {row.state === "released" ? <><br /><span className="ops-muted">{row.released_at ?? "释放日未下发"}{row.release_reason ? ` · ${RELEASE_REASON_LABEL[row.release_reason] ?? row.release_reason}` : ""}</span></> : null}
- {row.state === "pending_release" ? <><br /><span className="ops-muted">订阅已到期、资源未回收(待停机单生效)</span></> : null}
- </td>
- </tr>;
- }) : <OpsTableEmpty colSpan={colSpan}>没有符合筛选条件的在册资源(默认只显示在用与已到期待回收;已回收需在筛选里选)</OpsTableEmpty>}
- </tbody>
- </table>
- </div>
- {!load.error && !load.loading && <ListPager total={total} page={page} pageSize={PAGE_SIZE} onPageChange={setPage} unit="行" />}
- <p className="customer-form-note">
- 在册资源只认交付台账({`released_at IS NULL`});实测参数取该账号**最近一次成功开通回填**的测值(列头带测值日期),
- 与「现在的带宽」不是一回事。合同出口与实测出口两列并排,不一致的行整行标红并两值同显。本表**不含端口段**(D-6 端口本轮不启用)。默认每页 {PAGE_SIZE} 行,由前端请求下推。
- </p>
- </div>;
- }
|