/** * 「交付现状」表(讨论稿 §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 = { in_use: "在用", pending_release: "已到期待回收", released: "已回收", }; const stateTone = (state: string): OpsTone => state === "pending_release" ? "warning" : state === "released" ? "neutral" : "success"; const PLAN_FAMILY_LABEL: Record = { link: "跨境", addon: "叠加" }; const IP_TYPE_LABEL: Record = { fixed_ip: "固定 IP", nat_forward: "NAT 转发" }; const RELEASE_REASON_LABEL: Record = { 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
{!compact &&
{ setState(event.target.value as typeof state); setPage(0); }}> 共 {total} 条;默认只显示「在用」与「已到期待回收」,已回收需在筛选里选。
} {compact &&
{ setState(event.target.value as typeof state); setPage(0); }}> {!load.error && !load.loading && 共 {total} 条}
} {exportNotice &&

{exportNotice}

} {exportError &&

{exportError}

}
{columns.map((title, index) => )} {load.error ? 交付资源加载失败 : load.loading && !rows.length ? 正在读取交付资源… : 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 {!compact && } ; }) : 没有符合筛选条件的在册资源(默认只显示在用与已到期待回收;已回收需在筛选里选)}
{title}{title === "实测带宽" && measuredOn ? ({measuredOn} 测值) : null}
{account ? account : } {row.parent_subscription_id ? <>
叠加于 {row.parent_subscription_id} : null} {row.username && row.display_name ? <>
{row.username} : null}
{row.net_account?.trim() ? row.net_account : 未登记}{row.plan_name ?? -}{row.plan_family ? <>
{PLAN_FAMILY_LABEL[row.plan_family] ?? row.plan_family} : null}
{row.account_status ? {row.account_status} : } {row.opened_at ?? —(未开通)} {row.sub_end_date ?? 长期有效} {exitText(row.contract_exits) || } {row.measured_egress ?? 无实测} {mismatch ? <>
不在合同出口集合内 : null}
{row.intranet_ip ?? 无实测} {declared ? {declared} : —} {measured ? {measured} : 无实测} {row.overseas_ip ?? —(已释放)} {row.ip_egress ?? —(已释放)} {row.ip_type ? IP_TYPE_LABEL[row.ip_type] ?? row.ip_type : —} {row.source_ticket_no ?? —} {STATE_LABEL[row.state] ?? row.state} {row.state === "released" ? <>
{row.released_at ?? "释放日未下发"}{row.release_reason ? ` · ${RELEASE_REASON_LABEL[row.release_reason] ?? row.release_reason}` : ""} : null} {row.state === "pending_release" ? <>
订阅已到期、资源未回收(待停机单生效) : null}
{!load.error && !load.loading && }

在册资源只认交付台账({`released_at IS NULL`});实测参数取该账号**最近一次成功开通回填**的测值(列头带测值日期), 与「现在的带宽」不是一回事。合同出口与实测出口两列并排,不一致的行整行标红并两值同显。本表**不含端口段**(D-6 端口本轮不启用)。默认每页 {PAGE_SIZE} 行,由前端请求下推。

; }