|
|
@@ -1,103 +1,52 @@
|
|
|
/**
|
|
|
- * 工单处理链里「明细表格」的行模型与行校验(工单§5.2)。
|
|
|
- *
|
|
|
- * 存在理由:施工回填的「网络线路/境外 IP 明细」是**整行才算一条事实**的可重复录入区,
|
|
|
- * 后端逐行必填(`handlers/handle.rs`:线路 12 列、境外 IP 6 项),前端少填一格就换回一次
|
|
|
- * `60404`。这些判定⛔ 留在组件里——组件只在点提交时才校验,填到第 3 行才发现第 1 行缺网关,
|
|
|
- * 等于让运维白填一遍。
|
|
|
- *
|
|
|
- * ⚠️ 2026-11-17:「开通准备资料」整块退役(开户单不再单独登记),本模块只保留回填两类明细。
|
|
|
- *
|
|
|
- * ⛔ 在本模块造假数据兜底:校验不过就回错误文案,由页面原样透出。
|
|
|
+ * 施工回填「一账号一通路」行模型与校验/提交适配。
|
|
|
+ * 通路=客户侧接入(含接入口令)→ 路径/出口 → 境外出口资源;共享=挂靠前序境外资源(可选再共用口令)。
|
|
|
*/
|
|
|
import type { BackfillInIp, BackfillInRoute, IpRow, RouteRow } from "./api/ticket";
|
|
|
|
|
|
-// ── 常量:全部取自后端,⛔ 前端自造枚举 ──────────────────────────────────
|
|
|
-
|
|
|
-/** 带宽档位(后端硬校验:回填与竣工两处,只认 5/10/30 Mbps;合同侧自 2026-11-17 起不再核档位)。 */
|
|
|
export const BANDWIDTH_TIERS = [5, 10, 30];
|
|
|
-
|
|
|
-/** IP 类型(后端只认 `fixed_ip`/`nat_forward`)。 */
|
|
|
export const IP_TYPES: { code: string; label: string }[] = [
|
|
|
{ code: "fixed_ip", label: "固定 IP" },
|
|
|
{ code: "nat_forward", label: "NAT 共享出口" },
|
|
|
];
|
|
|
-
|
|
|
-/** 境外 IP 物理上限 4 行(工单§2.4,后端 `ip_rows.len() > 4` ⇒ 11103)。 */
|
|
|
export const OVERSEAS_IP_MAX_ROWS = 4;
|
|
|
-/** 网络线路上限 12 行(同一客户分账号的物理上限,与 `BackfillInRoute` 注释一致)。 */
|
|
|
export const ROUTE_MAX_ROWS = 12;
|
|
|
+export const PATH_MAX_ROWS = ROUTE_MAX_ROWS;
|
|
|
|
|
|
-/**
|
|
|
- * 「网络线路」12 列(`RouteIn`):页面据此铺字段,校验与提交也读同一份清单,
|
|
|
- * ⛔ 在页面里再抄一遍字段名——少抄一列就是线上一次 `60404`。
|
|
|
- */
|
|
|
-export type RouteFieldDef = {
|
|
|
- key: keyof RouteRowDraft;
|
|
|
- label: string;
|
|
|
- ph?: string;
|
|
|
- /** 跨境专线分组:客户侧接入/隧道与跨境路由 */
|
|
|
- group: "cpe" | "tunnel";
|
|
|
- /** 常识带条码/二维码的字段,挂扫码入口 */
|
|
|
- scannable?: boolean;
|
|
|
- hint?: string;
|
|
|
-};
|
|
|
-
|
|
|
-/** 「网络线路」12 列:按跨境专线常识分组展示,列真源不变。 */
|
|
|
-export const ROUTE_FIELDS: RouteFieldDef[] = [
|
|
|
- { key: "sub_account_id", label: "分账号编号", ph: "ACC-0001", group: "cpe", scannable: true, hint: "本系统分账号主键;现场标签有码时可扫入" },
|
|
|
- { key: "network_account_name", label: "网络侧账号名", ph: "hailan-office-01", group: "cpe", scannable: true, hint: "运营商/网管侧登录名,默认可带出分账号网络账户名" },
|
|
|
- { key: "intranet_ip", label: "客户侧内网 IP", ph: "10.20.30.11", group: "cpe", hint: "CPE/LAN 侧地址" },
|
|
|
- { key: "subnet_mask", label: "子网掩码", ph: "255.255.255.0", group: "cpe" },
|
|
|
- { key: "gateway", label: "默认网关", ph: "10.20.30.1", group: "cpe" },
|
|
|
- { key: "vlan", label: "接入 VLAN", ph: "120", group: "cpe", hint: "客户侧接入 VLAN,字符串非空即可" },
|
|
|
- { key: "vni", label: "隧道 VNI", ph: "50120", group: "tunnel", hint: "VXLAN/隧道网络标识" },
|
|
|
- { key: "src_endpoint", label: "本端隧道端点", group: "tunnel", hint: "客户侧 PE/CPE 隧道端点" },
|
|
|
- { key: "dst_endpoint", label: "对端隧道端点", group: "tunnel", hint: "跨境对端/PoP 侧隧道端点" },
|
|
|
- { key: "egress_pop", label: "出口 PoP", ph: "合同核定出口候选", group: "tunnel", hint: "系统可带入订阅核定出口,现场可改;只作施工记录" },
|
|
|
- { key: "down_mbps", label: "下行实测 Mbps", ph: "100", group: "tunnel", hint: "开通实测下行,可与套餐承诺对照" },
|
|
|
- { key: "up_mbps", label: "上行实测 Mbps", ph: "50", group: "tunnel" },
|
|
|
-];
|
|
|
-
|
|
|
-export const ROUTE_GROUP_LABELS: Record<RouteFieldDef["group"], string> = {
|
|
|
- cpe: "客户侧接入(CPE/内网)",
|
|
|
- tunnel: "隧道与跨境路由",
|
|
|
-};
|
|
|
-
|
|
|
-/** 「境外出口与接入凭据」6 项(含 PIN/CPID)。 */
|
|
|
-export const IP_ROW_FIELDS: { key: keyof BackfillIpRowDraft; label: string; ph?: string; hint?: string }[] = [
|
|
|
- { key: "egress", label: "出境口岸", ph: "合同核定出口候选", hint: "与线路出口 PoP 同属施工记录,可与核定候选不一致" },
|
|
|
- { key: "overseas_ip", label: "境外出口 IP", ph: "203.0.113.7" },
|
|
|
- { key: "ip_type", label: "接入方式", hint: "固定 IP=独占;NAT 共享出口=多账号可共用" },
|
|
|
- { key: "bandwidth_mbps", label: "带宽档位" },
|
|
|
- { key: "pin", label: "PIN", ph: "只写不读" },
|
|
|
- { key: "cpid", label: "CPID" },
|
|
|
-];
|
|
|
-
|
|
|
-export const IP_TYPE_LABELS: Record<string, string> = {
|
|
|
- fixed_ip: "固定 IP",
|
|
|
- nat_forward: "NAT 共享出口",
|
|
|
-};
|
|
|
-
|
|
|
-// ── 行草稿:受控输入一律存字符串,提交时才收敛成后端类型 ──────────────────
|
|
|
-
|
|
|
-export type RouteRowDraft = {
|
|
|
+export type PathDraft = {
|
|
|
key: string;
|
|
|
+ open_this_time: boolean;
|
|
|
+ /** 空=独立境外资源;非空=挂靠主通路 key */
|
|
|
+ share_egress_of: string;
|
|
|
+ /** 与 share_egress_of 联用:同时共用主通路接入口令 */
|
|
|
+ share_credential: boolean;
|
|
|
+ require_cpid: boolean;
|
|
|
+ tunnel_encap: "none" | "vxlan";
|
|
|
sub_account_id: string;
|
|
|
network_account_name: string;
|
|
|
intranet_ip: string;
|
|
|
subnet_mask: string;
|
|
|
gateway: string;
|
|
|
vlan: string;
|
|
|
+ pin: string;
|
|
|
+ cpid: string;
|
|
|
+ proxy_host: string;
|
|
|
+ proxy_port: string;
|
|
|
vni: string;
|
|
|
src_endpoint: string;
|
|
|
dst_endpoint: string;
|
|
|
egress_pop: string;
|
|
|
down_mbps: string;
|
|
|
up_mbps: string;
|
|
|
- open_this_time: boolean;
|
|
|
+ overseas_ip: string;
|
|
|
+ ip_type: string;
|
|
|
+ bandwidth_mbps: string;
|
|
|
+ pin_registered?: boolean;
|
|
|
+ cpid_registered?: boolean;
|
|
|
};
|
|
|
|
|
|
+/** @deprecated 兼容旧调用;新代码用 PathDraft */
|
|
|
+export type RouteRowDraft = PathDraft & { /* alias shape */ };
|
|
|
export type BackfillIpRowDraft = {
|
|
|
key: string;
|
|
|
egress: string;
|
|
|
@@ -106,28 +55,41 @@ export type BackfillIpRowDraft = {
|
|
|
bandwidth_mbps: string;
|
|
|
pin: string;
|
|
|
cpid: string;
|
|
|
+ sub_account_ids?: string[];
|
|
|
};
|
|
|
|
|
|
let seq = 0;
|
|
|
const key = (p: string) => `${p}-${(seq += 1)}`;
|
|
|
|
|
|
-export const newRouteRow = (): RouteRowDraft => ({
|
|
|
- key: key("route"),
|
|
|
+export const newPathDraft = (): PathDraft => ({
|
|
|
+ key: key("path"),
|
|
|
+ open_this_time: true,
|
|
|
+ share_egress_of: "",
|
|
|
+ share_credential: false,
|
|
|
+ require_cpid: false,
|
|
|
+ tunnel_encap: "none",
|
|
|
sub_account_id: "",
|
|
|
network_account_name: "",
|
|
|
intranet_ip: "",
|
|
|
subnet_mask: "",
|
|
|
gateway: "",
|
|
|
vlan: "",
|
|
|
+ pin: "",
|
|
|
+ cpid: "",
|
|
|
+ proxy_host: "",
|
|
|
+ proxy_port: "",
|
|
|
vni: "",
|
|
|
src_endpoint: "",
|
|
|
dst_endpoint: "",
|
|
|
egress_pop: "",
|
|
|
down_mbps: "",
|
|
|
up_mbps: "",
|
|
|
- open_this_time: true,
|
|
|
+ overseas_ip: "",
|
|
|
+ ip_type: "fixed_ip",
|
|
|
+ bandwidth_mbps: "5",
|
|
|
});
|
|
|
|
|
|
+export const newRouteRow = newPathDraft;
|
|
|
export const newBackfillIpRow = (ip_type = "fixed_ip", bandwidth_mbps = "5"): BackfillIpRowDraft => ({
|
|
|
key: key("bip"),
|
|
|
egress: "",
|
|
|
@@ -138,49 +100,13 @@ export const newBackfillIpRow = (ip_type = "fixed_ip", bandwidth_mbps = "5"): Ba
|
|
|
cpid: "",
|
|
|
});
|
|
|
|
|
|
-/** 线路行回填:把已交付的明细摊平回草稿(`null` 落空串,⛔ 显示成 "null")。 */
|
|
|
-export function routeRowsFromDetail(rows: RouteRow[]): RouteRowDraft[] {
|
|
|
- return rows.map((r) => ({
|
|
|
- key: key("route"),
|
|
|
- sub_account_id: r.sub_account_id ?? "",
|
|
|
- network_account_name: r.network_account_name ?? "",
|
|
|
- intranet_ip: r.intranet_ip ?? "",
|
|
|
- subnet_mask: r.subnet_mask ?? "",
|
|
|
- gateway: r.gateway ?? "",
|
|
|
- vlan: r.vlan ?? "",
|
|
|
- vni: r.vni ?? "",
|
|
|
- src_endpoint: r.src_endpoint ?? "",
|
|
|
- dst_endpoint: r.dst_endpoint ?? "",
|
|
|
- egress_pop: r.egress_pop ?? "",
|
|
|
- down_mbps: r.down_mbps ?? "",
|
|
|
- up_mbps: r.up_mbps ?? "",
|
|
|
- // 读侧没有这一列(数据模型⛔ `open_this_time` 的回读),覆盖保存时按后端默认「本次开通」重填。
|
|
|
- open_this_time: true,
|
|
|
- }));
|
|
|
-}
|
|
|
-
|
|
|
-/** 境外 IP 行回填:库里⛔ 存 PIN/CPID 明文,只回「有没有登记」⇒ 覆盖保存前须重填。 */
|
|
|
-export function backfillIpRowsFromDetail(rows: IpRow[]): BackfillIpRowDraft[] {
|
|
|
- return rows.map((r) => ({
|
|
|
- key: key("bip"),
|
|
|
- egress: r.egress ?? "",
|
|
|
- overseas_ip: r.overseas_ip ?? "",
|
|
|
- ip_type: r.ip_type || "fixed_ip",
|
|
|
- bandwidth_mbps: r.bandwidth_mbps || "5",
|
|
|
- pin: "",
|
|
|
- cpid: "",
|
|
|
- }));
|
|
|
+export function exitNormKey(s: string): string {
|
|
|
+ return s.replace(/\s+/g, "").toLowerCase();
|
|
|
}
|
|
|
|
|
|
-// ── 校验 ──────────────────────────────────────────────────────────────────
|
|
|
-
|
|
|
const blank = (v: string | undefined | null) => !v || !v.trim();
|
|
|
const posNum = (v: string) => /^\d+(\.\d+)?$/.test(v.trim()) && Number(v) > 0;
|
|
|
|
|
|
-/**
|
|
|
- * IP 形状:后端取 `IpAddr::from_str(raw.trim_end_matches("/32"))`,掩码列习惯带 `/32` 后缀。
|
|
|
- * 这里同口径放行,其余交给后端点名(⛔ 前端把 IPv6 判死)。
|
|
|
- */
|
|
|
function isIpLike(v: string): boolean {
|
|
|
const raw = v.trim().replace(/\/\d+$/, "");
|
|
|
if (raw.includes(":")) return true;
|
|
|
@@ -188,104 +114,244 @@ function isIpLike(v: string): boolean {
|
|
|
return m.length === 4 && m.every((o) => /^\d{1,3}$/.test(o) && Number(o) <= 255);
|
|
|
}
|
|
|
|
|
|
-/** 整行全空 ⇒ 视作「没这一行」,静默丢弃;填了一格又缺别的 ⇒ 报错(后端同样整行必填)。 */
|
|
|
-const isVoidRow = (r: Record<string, unknown>) =>
|
|
|
- Object.entries(r).every(([k, v]) => k === "key" || k === "open_this_time" || blank(v as string));
|
|
|
+function isVoidPath(r: PathDraft): boolean {
|
|
|
+ return blank(r.sub_account_id) && blank(r.intranet_ip) && blank(r.overseas_ip) && blank(r.proxy_host);
|
|
|
+}
|
|
|
+
|
|
|
+/** 解析主通路:独立配置且本次开通。 */
|
|
|
+export function primaryPaths(paths: PathDraft[]): PathDraft[] {
|
|
|
+ return paths.filter((p) => p.open_this_time && !p.share_egress_of.trim());
|
|
|
+}
|
|
|
+
|
|
|
+export function validatePathRows(
|
|
|
+ paths: PathDraft[],
|
|
|
+ require: boolean,
|
|
|
+ allowedExits: string[] = [],
|
|
|
+ involveOverseasIp = true,
|
|
|
+): string | null {
|
|
|
+ const kept = paths.filter((r) => !isVoidPath(r));
|
|
|
+ if (kept.length > PATH_MAX_ROWS) return `网络通路最多 ${PATH_MAX_ROWS} 条。`;
|
|
|
+ const allowKeys = new Set(allowedExits.map(exitNormKey));
|
|
|
+ const byKey = new Map(paths.map((p) => [p.key, p]));
|
|
|
+ const seenIp = new Set<string>();
|
|
|
|
|
|
-/**
|
|
|
- * 回填「网络线路」12 列整行必填(后端 `route_complete` 逐列点名)。
|
|
|
- *
|
|
|
- * 口径与后端一致:只有勾了「本次开通」的行才是 `picked`(`handle.rs` 先
|
|
|
- * `filter(|r| r.open_this_time)` 再校验、再插库),未勾选的行后端既不校验也不入库,
|
|
|
- * 前端⛔ 拿 12 列去卡它——没开通的线路本来就还没有 IP 可填。
|
|
|
- */
|
|
|
-export function validateRouteRows(rows: RouteRowDraft[], require: boolean): string | null {
|
|
|
- const kept = rows.filter((r) => !isVoidRow(r));
|
|
|
- if (kept.length > ROUTE_MAX_ROWS) return `网络线路最多 ${ROUTE_MAX_ROWS} 行。`;
|
|
|
for (const r of kept) {
|
|
|
if (!r.open_this_time) continue;
|
|
|
- const n = rows.indexOf(r) + 1;
|
|
|
- const miss = ROUTE_FIELDS.filter((f) => blank(r[f.key as keyof RouteRowDraft] as string)).map(
|
|
|
- (f) => f.label,
|
|
|
- );
|
|
|
- if (miss.length) return `第 ${n} 行线路缺${miss.join("、")}(后端要求整行 12 列填齐)。`;
|
|
|
+ const n = paths.indexOf(r) + 1;
|
|
|
+ const shareKey = r.share_egress_of.trim();
|
|
|
+ const primary = shareKey ? byKey.get(shareKey) : null;
|
|
|
+ if (shareKey) {
|
|
|
+ if (!primary || !primary.open_this_time || primary.share_egress_of.trim()) {
|
|
|
+ return `第 ${n} 条通路的挂靠目标无效(须为本次开通的独立主通路)。`;
|
|
|
+ }
|
|
|
+ if (paths.indexOf(primary) >= paths.indexOf(r)) {
|
|
|
+ return `第 ${n} 条通路只能挂靠更靠前的主通路。`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const miss: string[] = [];
|
|
|
+ if (blank(r.sub_account_id)) miss.push("分账号编号");
|
|
|
+ if (blank(r.network_account_name)) miss.push("网络接入账号");
|
|
|
+ if (blank(r.intranet_ip)) miss.push("内网 IP");
|
|
|
+ if (blank(r.subnet_mask)) miss.push("子网掩码");
|
|
|
+ if (blank(r.gateway)) miss.push("默认网关");
|
|
|
+ if (blank(r.vlan)) miss.push("接入 VLAN");
|
|
|
+ if (blank(r.proxy_host)) miss.push("正向代理地址");
|
|
|
+ if (blank(r.proxy_port)) miss.push("正向代理端口");
|
|
|
+ if (blank(r.egress_pop)) miss.push("出口 PoP");
|
|
|
+ if (blank(r.down_mbps)) miss.push("下行实测");
|
|
|
+ if (blank(r.up_mbps)) miss.push("上行实测");
|
|
|
+ if (!shareKey || !r.share_credential) {
|
|
|
+ if (blank(r.pin) && !r.pin_registered) miss.push("接入口令(PIN)");
|
|
|
+ }
|
|
|
+ if (r.require_cpid && !shareKey && blank(r.cpid) && !r.cpid_registered) miss.push("CPID");
|
|
|
+ if (r.tunnel_encap === "vxlan") {
|
|
|
+ if (blank(r.vni)) miss.push("VNI");
|
|
|
+ if (blank(r.src_endpoint)) miss.push("隧道本端");
|
|
|
+ if (blank(r.dst_endpoint)) miss.push("隧道对端");
|
|
|
+ }
|
|
|
+ if (involveOverseasIp && !shareKey) {
|
|
|
+ if (blank(r.overseas_ip)) miss.push("境外出口 IP");
|
|
|
+ if (blank(r.ip_type)) miss.push("接入方式");
|
|
|
+ if (blank(r.bandwidth_mbps)) miss.push("申报带宽档位");
|
|
|
+ }
|
|
|
+ if (miss.length) return `第 ${n} 条通路缺${miss.join("、")}。`;
|
|
|
+
|
|
|
for (const f of ["intranet_ip", "subnet_mask", "gateway"] as const) {
|
|
|
- if (!isIpLike(r[f])) {
|
|
|
- const label = ROUTE_FIELDS.find((x) => x.key === f)!.label;
|
|
|
- return `第 ${n} 行线路的${label}「${r[f]}」不是合法 IP。`;
|
|
|
+ if (!isIpLike(r[f])) return `第 ${n} 条通路的${f}「${r[f]}」不是合法 IP。`;
|
|
|
+ }
|
|
|
+ const port = Number(r.proxy_port);
|
|
|
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
|
+ return `第 ${n} 条通路的代理端口「${r.proxy_port}」须在 1~65535。`;
|
|
|
+ }
|
|
|
+ if (!posNum(r.down_mbps) || !posNum(r.up_mbps)) {
|
|
|
+ return `第 ${n} 条通路的上下行实测须为正数。`;
|
|
|
+ }
|
|
|
+ if (allowKeys.size && r.egress_pop.trim() && !allowKeys.has(exitNormKey(r.egress_pop))) {
|
|
|
+ return `第 ${n} 条通路出口 PoP「${r.egress_pop}」不在本单订阅核定出口内(须为:${allowedExits.join("、")})。`;
|
|
|
+ }
|
|
|
+ if (involveOverseasIp && !shareKey) {
|
|
|
+ if (!isIpLike(r.overseas_ip)) return `第 ${n} 条通路境外 IP「${r.overseas_ip}」不是合法 IP。`;
|
|
|
+ if (seenIp.has(r.overseas_ip.trim())) return `境外 IP「${r.overseas_ip}」重复登记。`;
|
|
|
+ seenIp.add(r.overseas_ip.trim());
|
|
|
+ if (!BANDWIDTH_TIERS.includes(Number(r.bandwidth_mbps))) {
|
|
|
+ return `第 ${n} 条通路带宽档位只能是 5/10/30 Mbps。`;
|
|
|
}
|
|
|
}
|
|
|
- if (!posNum(r.down_mbps) || !posNum(r.up_mbps)) return `第 ${n} 行线路的下行/上行带宽须为正数。`;
|
|
|
}
|
|
|
+
|
|
|
if (require && !kept.some((r) => r.open_this_time)) {
|
|
|
return kept.length
|
|
|
- ? "勾选至少一行「本次开通」并整行填齐(工单§5.1.3:勾一行就填整行,一列没填就整行别勾)。"
|
|
|
- : "至少填写一行网络线路(工单§5.2 组一)。";
|
|
|
+ ? "勾选至少一条「本次开通」通路并填齐。"
|
|
|
+ : "至少填写一条网络通路。";
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-/** 回填「境外 IP 明细」6 项整行必填(含 PIN/CPID,后端组三拦截 2)。 */
|
|
|
-export function validateBackfillIpRows(rows: BackfillIpRowDraft[]): string | null {
|
|
|
- const kept = rows.filter((r) => !isVoidRow(r));
|
|
|
- const seen = new Set<string>();
|
|
|
- for (const r of kept) {
|
|
|
- const n = rows.indexOf(r) + 1;
|
|
|
- const miss = IP_ROW_FIELDS.filter((f) => blank(r[f.key as keyof BackfillIpRowDraft])).map((f) => f.label);
|
|
|
- if (miss.length) return `第 ${n} 行境外 IP 缺${miss.join("、")}(组三六项含 PIN/CPID)。`;
|
|
|
- if (!isIpLike(r.overseas_ip)) return `第 ${n} 行境外 IP「${r.overseas_ip}」不是合法 IP。`;
|
|
|
- if (seen.has(r.overseas_ip.trim())) return `境外 IP「${r.overseas_ip}」重复登记(工单§5.2)。`;
|
|
|
- seen.add(r.overseas_ip.trim());
|
|
|
- if (!BANDWIDTH_TIERS.includes(Number(r.bandwidth_mbps))) {
|
|
|
- return `第 ${n} 行带宽档位只能是 5/10/30 Mbps。`;
|
|
|
- }
|
|
|
- }
|
|
|
- if (kept.length > OVERSEAS_IP_MAX_ROWS) return `境外 IP 最多 ${OVERSEAS_IP_MAX_ROWS} 行。`;
|
|
|
- return null;
|
|
|
+/** 兼容旧名。 */
|
|
|
+export function validateRouteRows(
|
|
|
+ rows: PathDraft[],
|
|
|
+ require: boolean,
|
|
|
+ allowedExits: string[] = [],
|
|
|
+): string | null {
|
|
|
+ return validatePathRows(rows, require, allowedExits, true);
|
|
|
+}
|
|
|
+
|
|
|
+export function validateBackfillIpRows(
|
|
|
+ _rows: BackfillIpRowDraft[],
|
|
|
+ _allowedExits: string[] = [],
|
|
|
+): string | null {
|
|
|
+ return null; // 境外资源已并入通路校验
|
|
|
}
|
|
|
|
|
|
-/** 建单人:后端要 `text` 列里的**数字身份 ID**(`parse::<i64>`),非数字=等于没填 ⇒ 组二永不齐。 */
|
|
|
export function normalizeBuilderUserId(raw: string | undefined | null): string | null {
|
|
|
const v = (raw ?? "").trim();
|
|
|
return /^\d+$/.test(v) ? v : null;
|
|
|
}
|
|
|
|
|
|
-/** 合同核定出口(`subscription.line_exits` 是 JSON 数组文本);取不到就回空数组,让页面退回手填。 */
|
|
|
-export function parseLineExits(raw: string | null | undefined): string[] {
|
|
|
- if (!raw || !raw.trim()) return [];
|
|
|
+export function parseLineExits(raw: string | string[] | null | undefined): string[] {
|
|
|
+ if (Array.isArray(raw)) return raw.map((x) => String(x).trim()).filter(Boolean);
|
|
|
+ if (!raw || !String(raw).trim()) return [];
|
|
|
try {
|
|
|
- const v = JSON.parse(raw);
|
|
|
- return Array.isArray(v) ? v.map((x) => String(x)).filter((x) => x.trim() !== "") : [];
|
|
|
+ const v = JSON.parse(String(raw));
|
|
|
+ return Array.isArray(v) ? v.map((x) => String(x).trim()).filter(Boolean) : [];
|
|
|
} catch {
|
|
|
return [];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// ── 提交载荷 ──────────────────────────────────────────────────────────────
|
|
|
-
|
|
|
-/** 只下发勾选「本次开通」的行:后端按 `picked` 插库,未勾选的行发过去也是白扔。 */
|
|
|
-export function buildRouteRows(rows: RouteRowDraft[]): BackfillInRoute[] {
|
|
|
- return rows
|
|
|
- .filter((r) => !isVoidRow(r) && r.open_this_time)
|
|
|
- .map((r) => ({
|
|
|
- sub_account_id: r.sub_account_id.trim(),
|
|
|
- network_account_name: r.network_account_name.trim() || null,
|
|
|
- intranet_ip: r.intranet_ip.trim(),
|
|
|
- subnet_mask: r.subnet_mask.trim(),
|
|
|
- gateway: r.gateway.trim(),
|
|
|
- vlan: r.vlan.trim(),
|
|
|
- vni: r.vni.trim(),
|
|
|
- src_endpoint: r.src_endpoint.trim(),
|
|
|
- dst_endpoint: r.dst_endpoint.trim(),
|
|
|
- egress_pop: r.egress_pop.trim(),
|
|
|
- down_mbps: Number(r.down_mbps),
|
|
|
- up_mbps: Number(r.up_mbps),
|
|
|
- open_this_time: r.open_this_time,
|
|
|
+export function resolveApprovedLineExits(detail: {
|
|
|
+ order?: { line_exits?: string | string[] | null } | null;
|
|
|
+ construction_guide?: {
|
|
|
+ plan?: { line_exits?: string | string[] | null } | null;
|
|
|
+ defaults?: { line_exits?: string[] | null } | null;
|
|
|
+ } | null;
|
|
|
+}): string[] {
|
|
|
+ const fromOrder = parseLineExits(detail.order?.line_exits);
|
|
|
+ if (fromOrder.length) return fromOrder;
|
|
|
+ const fromPlan = parseLineExits(detail.construction_guide?.plan?.line_exits);
|
|
|
+ if (fromPlan.length) return fromPlan;
|
|
|
+ return parseLineExits(detail.construction_guide?.defaults?.line_exits);
|
|
|
+}
|
|
|
+
|
|
|
+export function derivePinBindMode(paths: PathDraft[]): "shared" | "per_account" {
|
|
|
+ return paths.some((p) => p.open_this_time && p.share_credential && p.share_egress_of.trim())
|
|
|
+ ? "shared"
|
|
|
+ : "per_account";
|
|
|
+}
|
|
|
+
|
|
|
+/** 通路 → 后端 route_rows + ip_rows + pin_bind_mode */
|
|
|
+export function buildPathSubmit(paths: PathDraft[]): {
|
|
|
+ route_rows: BackfillInRoute[];
|
|
|
+ ip_rows: Array<BackfillInIp & { sub_account_ids: string[] }>;
|
|
|
+ pin_bind_mode: "shared" | "per_account";
|
|
|
+} {
|
|
|
+ const opened = paths.filter((r) => !isVoidPath(r) && r.open_this_time);
|
|
|
+ const byKey = new Map(opened.map((p) => [p.key, p]));
|
|
|
+ const pin_bind_mode = derivePinBindMode(opened);
|
|
|
+
|
|
|
+ const route_rows: BackfillInRoute[] = opened.map((r) => {
|
|
|
+ const primary = r.share_egress_of.trim() ? byKey.get(r.share_egress_of.trim()) : null;
|
|
|
+ const shareCredOf = r.share_credential && primary ? (primary.sub_account_id.trim() || null) : null;
|
|
|
+ return {
|
|
|
+ sub_account_id: r.sub_account_id.trim(),
|
|
|
+ network_account_name: r.network_account_name.trim() || null,
|
|
|
+ intranet_ip: r.intranet_ip.trim(),
|
|
|
+ subnet_mask: r.subnet_mask.trim(),
|
|
|
+ gateway: r.gateway.trim(),
|
|
|
+ vlan: r.vlan.trim(),
|
|
|
+ tunnel_encap: r.tunnel_encap,
|
|
|
+ vni: r.tunnel_encap === "vxlan" ? r.vni.trim() : "",
|
|
|
+ src_endpoint: r.tunnel_encap === "vxlan" ? r.src_endpoint.trim() : "",
|
|
|
+ dst_endpoint: r.tunnel_encap === "vxlan" ? r.dst_endpoint.trim() : "",
|
|
|
+ egress_pop: r.egress_pop.trim(),
|
|
|
+ down_mbps: Number(r.down_mbps),
|
|
|
+ up_mbps: Number(r.up_mbps),
|
|
|
+ proxy_host: r.proxy_host.trim(),
|
|
|
+ proxy_port: Number(r.proxy_port),
|
|
|
+ pin: shareCredOf ? "" : r.pin,
|
|
|
+ cpid: shareCredOf ? "" : r.cpid.trim(),
|
|
|
+ require_cpid: r.require_cpid,
|
|
|
+ share_credential_of: shareCredOf,
|
|
|
+ open_this_time: true,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ /** 按境外 IP 聚合:独立通路各一条;挂靠行并入主通路 IP。 */
|
|
|
+ type Acc = {
|
|
|
+ egress: string;
|
|
|
+ overseas_ip: string;
|
|
|
+ ip_type: string;
|
|
|
+ bandwidth_mbps: number;
|
|
|
+ sub_account_ids: string[];
|
|
|
+ pin: string;
|
|
|
+ cpid: string;
|
|
|
+ };
|
|
|
+ const groups = new Map<string, Acc>();
|
|
|
+ for (const r of opened) {
|
|
|
+ const primary = r.share_egress_of.trim() ? byKey.get(r.share_egress_of.trim()) : r;
|
|
|
+ if (!primary || blank(primary.overseas_ip)) continue;
|
|
|
+ const ipKey = primary.overseas_ip.trim();
|
|
|
+ let g = groups.get(ipKey);
|
|
|
+ if (!g) {
|
|
|
+ const multi = opened.some(
|
|
|
+ (x) => x.share_egress_of && byKey.get(x.share_egress_of.trim())?.overseas_ip.trim() === ipKey,
|
|
|
+ );
|
|
|
+ g = {
|
|
|
+ egress: primary.egress_pop.trim(),
|
|
|
+ overseas_ip: ipKey,
|
|
|
+ ip_type: multi || primary.ip_type === "nat_forward" ? "nat_forward" : (primary.ip_type || "fixed_ip"),
|
|
|
+ bandwidth_mbps: Number(primary.bandwidth_mbps) || 5,
|
|
|
+ sub_account_ids: [],
|
|
|
+ pin: primary.pin,
|
|
|
+ cpid: primary.cpid.trim(),
|
|
|
+ };
|
|
|
+ groups.set(ipKey, g);
|
|
|
+ }
|
|
|
+ const acc = r.sub_account_id.trim();
|
|
|
+ if (acc && !g.sub_account_ids.includes(acc)) g.sub_account_ids.push(acc);
|
|
|
+ }
|
|
|
+
|
|
|
+ const ip_rows = [...groups.values()].map((g) => ({
|
|
|
+ egress: g.egress,
|
|
|
+ overseas_ip: g.overseas_ip,
|
|
|
+ ip_type: g.sub_account_ids.length > 1 ? "nat_forward" : g.ip_type,
|
|
|
+ bandwidth_mbps: g.bandwidth_mbps,
|
|
|
+ pin: g.pin || undefined,
|
|
|
+ cpid: g.cpid || undefined,
|
|
|
+ action: "allocate" as const,
|
|
|
+ sub_account_ids: g.sub_account_ids,
|
|
|
}));
|
|
|
+
|
|
|
+ return { route_rows, ip_rows, pin_bind_mode };
|
|
|
+}
|
|
|
+
|
|
|
+export function buildRouteRows(rows: PathDraft[]): BackfillInRoute[] {
|
|
|
+ return buildPathSubmit(rows).route_rows;
|
|
|
}
|
|
|
|
|
|
export function buildBackfillIpRows(rows: BackfillIpRowDraft[]): BackfillInIp[] {
|
|
|
- return rows.filter((r) => !isVoidRow(r)).map((r) => ({
|
|
|
+ return rows.filter((r) => !blank(r.overseas_ip)).map((r) => ({
|
|
|
egress: r.egress.trim(),
|
|
|
overseas_ip: r.overseas_ip.trim(),
|
|
|
ip_type: r.ip_type,
|
|
|
@@ -294,3 +360,143 @@ export function buildBackfillIpRows(rows: BackfillIpRowDraft[]): BackfillInIp[]
|
|
|
cpid: r.cpid.trim(),
|
|
|
}));
|
|
|
}
|
|
|
+
|
|
|
+export function pathsFromDetail(
|
|
|
+ routes: RouteRow[],
|
|
|
+ ips: IpRow[],
|
|
|
+): PathDraft[] {
|
|
|
+ if (!routes.length) return [newPathDraft()];
|
|
|
+ const ipByAcc = new Map<string, IpRow>();
|
|
|
+ const multiOwners = new Map<string, string[]>();
|
|
|
+ for (const ip of ips) {
|
|
|
+ const accs = [...(ip.sub_account_ids ?? [])];
|
|
|
+ if (!accs.length && routes.length === 1 && ips.length === 1) {
|
|
|
+ const only = routes[0].sub_account_id ?? "";
|
|
|
+ if (only) accs.push(only);
|
|
|
+ }
|
|
|
+ for (const a of accs) {
|
|
|
+ if (a) ipByAcc.set(a, ip);
|
|
|
+ }
|
|
|
+ if (accs.length > 1 && ip.overseas_ip) {
|
|
|
+ multiOwners.set(ip.overseas_ip, accs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const pathKeys = new Map<string, string>();
|
|
|
+ const drafts: PathDraft[] = routes.map((r) => {
|
|
|
+ const d = newPathDraft();
|
|
|
+ pathKeys.set(r.sub_account_id ?? "", d.key);
|
|
|
+ const ip = ipByAcc.get(r.sub_account_id ?? "");
|
|
|
+ const owners = ip?.overseas_ip ? multiOwners.get(ip.overseas_ip) : undefined;
|
|
|
+ const isPrimary = !owners || owners[0] === r.sub_account_id;
|
|
|
+ const primaryAcc = owners?.[0];
|
|
|
+ return {
|
|
|
+ ...d,
|
|
|
+ sub_account_id: r.sub_account_id ?? "",
|
|
|
+ network_account_name: r.network_account_name ?? "",
|
|
|
+ intranet_ip: r.intranet_ip ?? "",
|
|
|
+ subnet_mask: r.subnet_mask ?? "",
|
|
|
+ gateway: r.gateway ?? "",
|
|
|
+ vlan: r.vlan ?? "",
|
|
|
+ tunnel_encap: (r as RouteRow & { tunnel_encap?: string }).tunnel_encap === "vxlan" ? "vxlan" : "none",
|
|
|
+ vni: r.vni ?? "",
|
|
|
+ src_endpoint: r.src_endpoint ?? "",
|
|
|
+ dst_endpoint: r.dst_endpoint ?? "",
|
|
|
+ egress_pop: r.egress_pop ?? "",
|
|
|
+ down_mbps: r.down_mbps ?? "",
|
|
|
+ up_mbps: r.up_mbps ?? "",
|
|
|
+ proxy_host: (r as RouteRow & { proxy_host?: string }).proxy_host ?? "",
|
|
|
+ proxy_port: (r as RouteRow & { proxy_port?: string }).proxy_port ?? "",
|
|
|
+ pin_registered: (r as RouteRow & { pin_registered?: string }).pin_registered === "true"
|
|
|
+ || (r as RouteRow & { pin_registered?: string }).pin_registered === "1",
|
|
|
+ cpid_registered: (r as RouteRow & { cpid_registered?: string }).cpid_registered === "true"
|
|
|
+ || (r as RouteRow & { cpid_registered?: string }).cpid_registered === "1",
|
|
|
+ overseas_ip: isPrimary ? (ip?.overseas_ip ?? "") : "",
|
|
|
+ ip_type: ip?.ip_type || "fixed_ip",
|
|
|
+ bandwidth_mbps: ip?.bandwidth_mbps || "5",
|
|
|
+ share_egress_of: !isPrimary && primaryAcc ? (pathKeys.get(primaryAcc) || "") : "",
|
|
|
+ share_credential: false,
|
|
|
+ open_this_time: true,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ // 第二遍:挂靠 key(第一遍时 primary 的 key 可能尚未写入 map 顺序问题——按账号再补)
|
|
|
+ for (const d of drafts) {
|
|
|
+ if (!d.share_egress_of && d.overseas_ip === "") {
|
|
|
+ const ip = ipByAcc.get(d.sub_account_id);
|
|
|
+ const owners = ip?.overseas_ip ? multiOwners.get(ip.overseas_ip) : undefined;
|
|
|
+ if (owners && owners[0] !== d.sub_account_id) {
|
|
|
+ const pk = drafts.find((x) => x.sub_account_id === owners[0])?.key;
|
|
|
+ if (pk) d.share_egress_of = pk;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return drafts;
|
|
|
+}
|
|
|
+
|
|
|
+export function routeRowsFromDetail(rows: RouteRow[]): PathDraft[] {
|
|
|
+ return pathsFromDetail(rows, []);
|
|
|
+}
|
|
|
+
|
|
|
+export function backfillIpRowsFromDetail(rows: IpRow[]): BackfillIpRowDraft[] {
|
|
|
+ return rows.map((r) => ({
|
|
|
+ key: key("bip"),
|
|
|
+ egress: r.egress ?? "",
|
|
|
+ overseas_ip: r.overseas_ip ?? "",
|
|
|
+ ip_type: r.ip_type || "fixed_ip",
|
|
|
+ bandwidth_mbps: r.bandwidth_mbps || "5",
|
|
|
+ pin: "",
|
|
|
+ cpid: "",
|
|
|
+ sub_account_ids: r.sub_account_ids,
|
|
|
+ }));
|
|
|
+}
|
|
|
+
|
|
|
+/** 字段元数据(通路卡分段渲染)。 */
|
|
|
+export const PATH_CPE_FIELDS: { key: keyof PathDraft; label: string; ph?: string; hint?: string; scannable?: boolean; type?: string }[] = [
|
|
|
+ { key: "sub_account_id", label: "分账号编号", ph: "ACC-0001", scannable: true, hint: "本系统分账号主键" },
|
|
|
+ { key: "network_account_name", label: "网络接入账号", ph: "proxy-user-01", scannable: true, hint: "正向代理/网管侧认证用户名" },
|
|
|
+ { key: "intranet_ip", label: "客户侧内网 IP", ph: "10.20.30.11", hint: "CPE/LAN 侧地址" },
|
|
|
+ { key: "subnet_mask", label: "子网掩码", ph: "255.255.255.0" },
|
|
|
+ { key: "gateway", label: "默认网关", ph: "10.20.30.1" },
|
|
|
+ { key: "vlan", label: "接入 VLAN", ph: "120", hint: "客户侧 L2 分段,与 VNI 无包含关系" },
|
|
|
+ { key: "pin", label: "接入口令(PIN)", ph: "只写不读", type: "password", hint: "与网络接入账号配对的口令;一账号一 PIN" },
|
|
|
+ { key: "cpid", label: "CPID", ph: "选填", hint: "有则录;默认非必填" },
|
|
|
+ { key: "proxy_host", label: "正向代理地址", ph: "proxy.example.com", hint: "客户侧接入点" },
|
|
|
+ { key: "proxy_port", label: "正向代理端口", ph: "8080" },
|
|
|
+];
|
|
|
+
|
|
|
+export const PATH_TUNNEL_FIELDS: { key: keyof PathDraft; label: string; ph?: string; hint?: string }[] = [
|
|
|
+ { key: "vni", label: "隧道 VNI", ph: "50120", hint: "VXLAN 网络标识(与 VLAN 不同层)" },
|
|
|
+ { key: "src_endpoint", label: "隧道本端(VTEP/PE)", hint: "客户侧隧道端点" },
|
|
|
+ { key: "dst_endpoint", label: "隧道对端(VTEP/PE)", hint: "对端/PoP 侧隧道端点" },
|
|
|
+ { key: "egress_pop", label: "出口 PoP", ph: "请选择核定出口", hint: "须∈订阅核定出口(KLT-G20406)" },
|
|
|
+ { key: "down_mbps", label: "下行实测 Mbps", ph: "100", hint: "开通实测,非申报档位" },
|
|
|
+ { key: "up_mbps", label: "上行实测 Mbps", ph: "50" },
|
|
|
+];
|
|
|
+
|
|
|
+// 旧 ROUTE_FIELDS 兼容(部分页面可能仍引用)
|
|
|
+export type RouteFieldDef = {
|
|
|
+ key: keyof PathDraft;
|
|
|
+ label: string;
|
|
|
+ ph?: string;
|
|
|
+ group: "cpe" | "tunnel";
|
|
|
+ scannable?: boolean;
|
|
|
+ hint?: string;
|
|
|
+};
|
|
|
+export const ROUTE_FIELDS: RouteFieldDef[] = [
|
|
|
+ ...PATH_CPE_FIELDS.filter((f) => !["pin", "cpid", "proxy_host", "proxy_port"].includes(f.key as string)).map((f) => ({ ...f, group: "cpe" as const })),
|
|
|
+ ...PATH_TUNNEL_FIELDS.map((f) => ({ ...f, group: "tunnel" as const })),
|
|
|
+];
|
|
|
+export const ROUTE_GROUP_LABELS = {
|
|
|
+ cpe: "客户侧接入",
|
|
|
+ tunnel: "路径与出口",
|
|
|
+};
|
|
|
+export const IP_ROW_FIELDS: { key: keyof BackfillIpRowDraft; label: string; ph?: string; hint?: string }[] = [
|
|
|
+ { key: "overseas_ip", label: "境外出口 IP", ph: "203.0.113.7" },
|
|
|
+ { key: "ip_type", label: "接入方式" },
|
|
|
+ { key: "bandwidth_mbps", label: "申报带宽档位" },
|
|
|
+];
|
|
|
+export const IP_TYPE_LABELS: Record<string, string> = {
|
|
|
+ fixed_ip: "固定 IP",
|
|
|
+ nat_forward: "NAT 共享出口",
|
|
|
+};
|