|
@@ -19,8 +19,9 @@
|
|
|
//! 在册列 `use_category`/`annual_price_cents` 在 openapi 请求体里**没有对应入参** ⇒ ⛔ 写;
|
|
//! 在册列 `use_category`/`annual_price_cents` 在 openapi 请求体里**没有对应入参** ⇒ ⛔ 写;
|
|
|
//! 条目里多带的键(含 `item_id`)一律点名在 `service_item_fields_not_persisted`。
|
|
//! 条目里多带的键(含 `item_id`)一律点名在 `service_item_fields_not_persisted`。
|
|
|
//! * `contract_ip_entry`:只落 `line_exit`/`bandwidth_tier_mbps`/`ip_count` 三元组
|
|
//! * `contract_ip_entry`:只落 `line_exit`/`bandwidth_tier_mbps`/`ip_count` 三元组
|
|
|
-//! (openapi 把元素写成无属性 object,多出来的键无处落库 ⇒ 点名在
|
|
|
|
|
-//! `ip_entry_fields_not_persisted`,并回 `ip_entry_fields_persisted` 说清只存这些)。
|
|
|
|
|
|
|
+//! (2026-11-16 起档位可配置、并支持「不承诺带宽」=`bandwidth_tier_mbps` 落 `NULL`,
|
|
|
|
|
+//! 请求侧以 `bandwidth_committed=false` 表达;openapi 把元素写成无属性 object,多出来的键
|
|
|
|
|
+//! 无处落库 ⇒ 点名在 `ip_entry_fields_not_persisted`,并回 `ip_entry_fields_persisted` 说清只存这些)。
|
|
|
//!
|
|
//!
|
|
|
//! ⚠️ 两处 UDS 现实约束决定写侧形状:① `/dml/batch@v1` 同批=原子提交 ⇒ 主表与两张子表
|
|
//! ⚠️ 两处 UDS 现实约束决定写侧形状:① `/dml/batch@v1` 同批=原子提交 ⇒ 主表与两张子表
|
|
|
//! 放**同一条批**(⛔ 拆两批=主档成功、条目丢失);② 批内⛔ 条件中止(`uds.rs:180`)⇒
|
|
//! 放**同一条批**(⛔ 拆两批=主档成功、条目丢失);② 批内⛔ 条件中止(`uds.rs:180`)⇒
|
|
@@ -69,7 +70,12 @@ const COLUMNS_PENDING: &[&str] = &[];
|
|
|
/// 出现=11103(口径=`ErrorCode::BadParams` 60004,message 逐字带 11103)。
|
|
/// 出现=11103(口径=`ErrorCode::BadParams` 60004,message 逐字带 11103)。
|
|
|
const READONLY_KEYS: [&str; 4] = ["source", "opened", "first_referred_at", "derived_plan_id"];
|
|
const READONLY_KEYS: [&str; 4] = ["source", "opened", "first_referred_at", "derived_plan_id"];
|
|
|
/// `contract_ip_entry` 本轮真正落库的字段(openapi 元素无属性 ⇒ 只认这三元组)。
|
|
/// `contract_ip_entry` 本轮真正落库的字段(openapi 元素无属性 ⇒ 只认这三元组)。
|
|
|
-const IP_ENTRY_FIELDS_PERSISTED: [&str; 3] = ["line_exit", "bandwidth_tier_mbps", "ip_count"];
|
|
|
|
|
|
|
+const IP_ENTRY_FIELDS_PERSISTED: [&str; 4] = [
|
|
|
|
|
+ "line_exit",
|
|
|
|
|
+ "bandwidth_tier_mbps",
|
|
|
|
|
+ "bandwidth_committed",
|
|
|
|
|
+ "ip_count",
|
|
|
|
|
+];
|
|
|
/// `contract_service_item` 本轮真正落库的请求字段(§4.3 后 `use_category`/年合同价/月结算标准已入列)。
|
|
/// `contract_service_item` 本轮真正落库的请求字段(§4.3 后 `use_category`/年合同价/月结算标准已入列)。
|
|
|
const SERVICE_ITEM_FIELDS_PERSISTED: [&str; 10] = [
|
|
const SERVICE_ITEM_FIELDS_PERSISTED: [&str; 10] = [
|
|
|
"item_kind",
|
|
"item_kind",
|
|
@@ -92,12 +98,21 @@ const CONTRACT_COLS: &str = "k.contract_id, k.customer_id, k.contract_no, k.stat
|
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
|
k.source, k.created_by, \
|
|
k.source, k.created_by, \
|
|
|
NULLIF(COALESCE(NULLIF(a.display_name,''), NULLIF(u.username,''), \
|
|
NULLIF(COALESCE(NULLIF(a.display_name,''), NULLIF(u.username,''), \
|
|
|
- k.created_by), '') AS created_by_name";
|
|
|
|
|
-/// ⚠️ 两个 LEFT JOIN **必须**与 [`CONTRACT_COLS`] 成对出现(列里有 `a.`/`u.` 的引用)。
|
|
|
|
|
|
|
+ k.created_by), '') AS created_by_name, \
|
|
|
|
|
+ NULLIF(COALESCE(NULLIF(et.team_name,''), NULLIF(ot.team_name,''), \
|
|
|
|
|
+ CASE WHEN u.subject_type = 'hq' THEN '总运营' END), '') AS created_by_org, \
|
|
|
|
|
+ u.mobile AS created_by_mobile";
|
|
|
|
|
+/// ⚠️ 四个 LEFT JOIN **必须**与 [`CONTRACT_COLS`] 成对出现(列里有 `a.`/`u.`/`et.`/`ot.` 的引用)。
|
|
|
/// 都是按主键/账号一一对应 ⇒ ⛔ 改变行数(列表统计卡与列表同一条 WHERE 的前提)。
|
|
/// 都是按主键/账号一一对应 ⇒ ⛔ 改变行数(列表统计卡与列表同一条 WHERE 的前提)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 录入经办人三段的取数:姓名=`bos_account_ext.display_name` → 登录名 → 账号 ID 兜底;
|
|
|
|
|
+/// 机构=运营团队/运维团队名(`hq` 总运营账号回落「总运营」);联系方式=绑定手机号
|
|
|
|
|
+/// (⚠️ 出参前在 [`base_json`] 统一掩码,需求 §3.3「列表页默认掩码」同口径)。
|
|
|
const CONTRACT_FROM: &str = "FROM contract k \
|
|
const CONTRACT_FROM: &str = "FROM contract k \
|
|
|
LEFT JOIN bos_user_binding u ON u.user_id::text = k.created_by \
|
|
LEFT JOIN bos_user_binding u ON u.user_id::text = k.created_by \
|
|
|
- LEFT JOIN bos_account_ext a ON a.user_id = u.user_id";
|
|
|
|
|
|
|
+ LEFT JOIN bos_account_ext a ON a.user_id = u.user_id \
|
|
|
|
|
+ LEFT JOIN ent_team et ON et.team_id = u.subject_id AND u.subject_type = 'ent_team' \
|
|
|
|
|
+ LEFT JOIN ops_team ot ON ot.team_id = u.subject_id AND u.subject_type = 'ops_team'";
|
|
|
|
|
|
|
|
/// 合同主表新增(15 列;`status`/`created_at`/`updated_at` 走默认值)。
|
|
/// 合同主表新增(15 列;`status`/`created_at`/`updated_at` 走默认值)。
|
|
|
///
|
|
///
|
|
@@ -156,8 +171,13 @@ const ITEM_DERIVED_UPDATE: &str = "UPDATE contract_service_item SET derived_plan
|
|
|
updated_at = NOW() WHERE item_id = $1::text";
|
|
updated_at = NOW() WHERE item_id = $1::text";
|
|
|
|
|
|
|
|
/// IP 备案条目新增(只落三元组)。
|
|
/// IP 备案条目新增(只落三元组)。
|
|
|
|
|
+///
|
|
|
|
|
+/// ⚠️ 两个数值列走文本+`$n::text::int`:`bandwidth_tier_mbps` 可空,同一段 SQL 会一次收到
|
|
|
|
|
+/// `NULL`(按 TEXT 绑)、一次收到数字(INT8 绑),而 UDS 的语句缓存键只含 SQL 原文 ⇒ 复用
|
|
|
|
|
+/// 首次声明的 TEXT 类型去解码 INT8,报 `invalid byte sequence for encoding "UTF8": 0x00`。
|
|
|
const IP_INSERT: &str = "INSERT INTO contract_ip_entry (entry_id, contract_id, line_exit, \
|
|
const IP_INSERT: &str = "INSERT INTO contract_ip_entry (entry_id, contract_id, line_exit, \
|
|
|
- bandwidth_tier_mbps, ip_count) VALUES ($1::text, $2::text, $3::text, $4::int, $5::int)";
|
|
|
|
|
|
|
+ bandwidth_tier_mbps, ip_count) VALUES ($1::text, $2::text, $3::text, $4::text::int, \
|
|
|
|
|
+ $5::text::int)";
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
|
pub struct ContractListReq {
|
|
pub struct ContractListReq {
|
|
@@ -225,6 +245,9 @@ pub struct ServiceItemReq {
|
|
|
pub struct IpEntryReq {
|
|
pub struct IpEntryReq {
|
|
|
pub line_exit: Option<Value>,
|
|
pub line_exit: Option<Value>,
|
|
|
pub bandwidth_tier_mbps: Option<Value>,
|
|
pub bandwidth_tier_mbps: Option<Value>,
|
|
|
|
|
+ /// 是否承诺带宽(2026-11-16:档位可配置后新增「不承诺带宽」档)。
|
|
|
|
|
+ /// 缺省=按 `bandwidth_tier_mbps` 是否给值推导;`false` 时兆数必须为空(落库 NULL)。
|
|
|
|
|
+ pub bandwidth_committed: Option<Value>,
|
|
|
pub ip_count: Option<Value>,
|
|
pub ip_count: Option<Value>,
|
|
|
#[serde(flatten)]
|
|
#[serde(flatten)]
|
|
|
pub extra: HashMap<String, Value>,
|
|
pub extra: HashMap<String, Value>,
|
|
@@ -323,6 +346,12 @@ struct ContractRow {
|
|
|
/// 经办人可读名(`display_name` → 登录名 → 账号 ID 兜底),NULL=存量行未记录。
|
|
/// 经办人可读名(`display_name` → 登录名 → 账号 ID 兜底),NULL=存量行未记录。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
created_by_name: Option<String>,
|
|
created_by_name: Option<String>,
|
|
|
|
|
+ /// 录入账号所属机构(运营/运维团队名;`hq` 账号回落「总运营」)。
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ created_by_org: Option<String>,
|
|
|
|
|
+ /// 录入账号绑定手机号(原值;出参前经 `mask_mobile` 掩码,⛔ 明文出接口)。
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ created_by_mobile: Option<String>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
@@ -452,10 +481,13 @@ fn item_json(r: ItemRow, plans: &HashMap<String, PlanName>) -> Value {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn ip_json(r: IpRow) -> Value {
|
|
fn ip_json(r: IpRow) -> Value {
|
|
|
|
|
+ let tier = as_opt_num(r.bandwidth_tier_mbps.as_deref());
|
|
|
json!({
|
|
json!({
|
|
|
"entry_id": r.entry_id,
|
|
"entry_id": r.entry_id,
|
|
|
"line_exit": r.line_exit,
|
|
"line_exit": r.line_exit,
|
|
|
- "bandwidth_tier_mbps": as_opt_num(r.bandwidth_tier_mbps.as_deref()),
|
|
|
|
|
|
|
+ "bandwidth_tier_mbps": tier,
|
|
|
|
|
+ // 承诺位由兆数是否在册推导(NULL=「不承诺带宽」,2026-11-16)。
|
|
|
|
|
+ "bandwidth_committed": !tier.is_null(),
|
|
|
"ip_count": as_opt_num(r.ip_count.as_deref()),
|
|
"ip_count": as_opt_num(r.ip_count.as_deref()),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -498,6 +530,8 @@ fn base_json(r: &ContractRow, customer_name: Option<&str>) -> Value {
|
|
|
"created_at": r.created_at,
|
|
"created_at": r.created_at,
|
|
|
"created_by": r.created_by,
|
|
"created_by": r.created_by,
|
|
|
"created_by_name": r.created_by_name,
|
|
"created_by_name": r.created_by_name,
|
|
|
|
|
+ "created_by_org": r.created_by_org,
|
|
|
|
|
+ "created_by_mobile": mask_mobile(r.created_by_mobile.as_deref()),
|
|
|
"row_version": as_num(&r.row_version),
|
|
"row_version": as_num(&r.row_version),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -754,6 +788,21 @@ fn shown(v: Option<&Value>) -> String {
|
|
|
v.map(Value::to_string).unwrap_or_else(|| "(缺)".to_string())
|
|
v.map(Value::to_string).unwrap_or_else(|| "(缺)".to_string())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 布尔字段:只认 `true`/`false`(含字面字符串);`null`/缺省=`None`。
|
|
|
|
|
+/// ⛔ 把 `"true"`/`0` 当 `false`——承诺位与勾选态同一条纪律(见 [`need_ip`])。
|
|
|
|
|
+fn want_bool(v: Option<&Value>, field: &str) -> Result<Option<bool>, BosError> {
|
|
|
|
|
+ let Some(v) = v.filter(|v| !v.is_null()) else { return Ok(None) };
|
|
|
|
|
+ match v {
|
|
|
|
|
+ Value::Bool(b) => Ok(Some(*b)),
|
|
|
|
|
+ Value::String(s) => match s.trim() {
|
|
|
|
|
+ "true" => Ok(Some(true)),
|
|
|
|
|
+ "false" => Ok(Some(false)),
|
|
|
|
|
+ other => Err(BosError::bad_params(format!("{field} 须为布尔值(11103),收到 {other:?}"))),
|
|
|
|
|
+ },
|
|
|
|
|
+ other => Err(BosError::bad_params(format!("{field} 须为布尔值(11103),收到 {other}"))),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 数值字段:认整数(数字或纯数字串);认不出来=显式失败,⛔ 当 `0`。
|
|
/// 数值字段:认整数(数字或纯数字串);认不出来=显式失败,⛔ 当 `0`。
|
|
|
fn want_int(v: Option<&Value>, field: &str) -> Result<Option<i64>, BosError> {
|
|
fn want_int(v: Option<&Value>, field: &str) -> Result<Option<i64>, BosError> {
|
|
|
let Some(v) = v.filter(|v| !v.is_null()) else { return Ok(None) };
|
|
let Some(v) = v.filter(|v| !v.is_null()) else { return Ok(None) };
|
|
@@ -1284,19 +1333,22 @@ fn new_derived_count(items: &[ItemIns], existing: &HashMap<String, DerivedExisti
|
|
|
/// 一条已校验的 IP 备案条目(三元组)。
|
|
/// 一条已校验的 IP 备案条目(三元组)。
|
|
|
struct IpIns {
|
|
struct IpIns {
|
|
|
line_exit: String,
|
|
line_exit: String,
|
|
|
- tier: i64,
|
|
|
|
|
|
|
+ /// 带宽档位(兆);`None`=「不承诺带宽」(落库 `bandwidth_tier_mbps = NULL`)。
|
|
|
|
|
+ tier: Option<i64>,
|
|
|
count: i64,
|
|
count: i64,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// IP 条目的**类型收敛**形态(⛔ 任何必填/档位/勾选一致性判据=全归 [`check_ip_entries`])。
|
|
/// IP 条目的**类型收敛**形态(⛔ 任何必填/档位/勾选一致性判据=全归 [`check_ip_entries`])。
|
|
|
///
|
|
///
|
|
|
-/// 为什么⛔ 在本层判「三档」「ip_count>0」:`bandwidth_tier_mbps IN (5,10,30)` 与
|
|
|
|
|
-/// 「勾了必填」是**同一请求级判据**的两个侧面,拆开写就会出现「本层放行、判据层拒」
|
|
|
|
|
-/// 或反向的两本账(04 册 §4.4/订阅§10.1 纪律①)。
|
|
|
|
|
|
|
+/// 为什么⛔ 在本层判「档位给了没有」「ip_count>0」:这两条与「勾了必填」是**同一请求级判据**
|
|
|
|
|
+/// 的两个侧面,拆开写就会出现「本层放行、判据层拒」或反向的两本账(04 册 §4.4/订阅§10.1 纪律①)。
|
|
|
|
|
+/// 档位**是否在目录里**则是目录侧判据(2026-11-16 档位可配置),由 [`check_ip_tiers`] 判。
|
|
|
#[derive(Default)]
|
|
#[derive(Default)]
|
|
|
struct IpRawOwned {
|
|
struct IpRawOwned {
|
|
|
line_exit: Option<String>,
|
|
line_exit: Option<String>,
|
|
|
tier: Option<i64>,
|
|
tier: Option<i64>,
|
|
|
|
|
+ /// 承诺位:`None`=按兆数是否给值推导(老客户端只送三元组)。
|
|
|
|
|
+ committed: Option<bool>,
|
|
|
count: Option<i64>,
|
|
count: Option<i64>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1325,6 +1377,10 @@ fn ip_norm(raw: &[IpEntryReq]) -> Result<(Vec<IpRawOwned>, Vec<String>), BosErro
|
|
|
e.bandwidth_tier_mbps.as_ref(),
|
|
e.bandwidth_tier_mbps.as_ref(),
|
|
|
&format!("{prefix}.bandwidth_tier_mbps"),
|
|
&format!("{prefix}.bandwidth_tier_mbps"),
|
|
|
)?,
|
|
)?,
|
|
|
|
|
+ committed: want_bool(
|
|
|
|
|
+ e.bandwidth_committed.as_ref(),
|
|
|
|
|
+ &format!("{prefix}.bandwidth_committed"),
|
|
|
|
|
+ )?,
|
|
|
count: want_int(e.ip_count.as_ref(), &format!("{prefix}.ip_count"))?,
|
|
count: want_int(e.ip_count.as_ref(), &format!("{prefix}.ip_count"))?,
|
|
|
});
|
|
});
|
|
|
dropped.extend(e.extra.keys().cloned());
|
|
dropped.extend(e.extra.keys().cloned());
|
|
@@ -1346,7 +1402,8 @@ fn need_ip(flag: Option<&Value>, ip_non_empty: bool) -> Result<bool, BosError> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/// 固定 IP 段:类型收敛 ⇒ [`check_ip_entries`](勾选态 ⊥ 条目集合的请求级判据)⇒ 可落库形态。
|
|
|
|
|
|
|
+/// 固定 IP 段:类型收敛 ⇒ 承诺位自相矛盾拦截(11103)⇒ [`check_ip_entries`]
|
|
|
|
|
+/// (勾选态 ⊥ 条目集合的请求级判据)⇒ 可落库形态。
|
|
|
fn resolve_ips(need: bool, raw: &[IpEntryReq]) -> Result<(Vec<IpIns>, Vec<String>), BosError> {
|
|
fn resolve_ips(need: bool, raw: &[IpEntryReq]) -> Result<(Vec<IpIns>, Vec<String>), BosError> {
|
|
|
let (normed, dropped) = ip_norm(raw)?;
|
|
let (normed, dropped) = ip_norm(raw)?;
|
|
|
let rows: Vec<IpEntryRaw<'_>> = normed
|
|
let rows: Vec<IpEntryRaw<'_>> = normed
|
|
@@ -1354,6 +1411,7 @@ fn resolve_ips(need: bool, raw: &[IpEntryReq]) -> Result<(Vec<IpIns>, Vec<String
|
|
|
.map(|r| IpEntryRaw {
|
|
.map(|r| IpEntryRaw {
|
|
|
line_exit: r.line_exit.as_deref(),
|
|
line_exit: r.line_exit.as_deref(),
|
|
|
bandwidth_tier_mbps: r.tier,
|
|
bandwidth_tier_mbps: r.tier,
|
|
|
|
|
+ bandwidth_committed: r.committed,
|
|
|
ip_count: r.count,
|
|
ip_count: r.count,
|
|
|
})
|
|
})
|
|
|
.collect();
|
|
.collect();
|
|
@@ -1361,13 +1419,25 @@ fn resolve_ips(need: bool, raw: &[IpEntryReq]) -> Result<(Vec<IpIns>, Vec<String
|
|
|
let mut out = Vec::with_capacity(normed.len());
|
|
let mut out = Vec::with_capacity(normed.len());
|
|
|
for (i, r) in normed.into_iter().enumerate() {
|
|
for (i, r) in normed.into_iter().enumerate() {
|
|
|
let prefix = format!("ip_entries[{i}]");
|
|
let prefix = format!("ip_entries[{i}]");
|
|
|
- // 走到这里判据已放行 ⇒ 三项必有值;取不到=判据与落库脱节(系统故障,⛔ 当脏数据写进去)。
|
|
|
|
|
|
|
+ // 承诺位⊥兆数:声明「不承诺带宽」就不该再给兆数(两边都收=不知道以谁为准)。
|
|
|
|
|
+ let committed = r.committed.unwrap_or(r.tier.is_some());
|
|
|
|
|
+ if !committed && r.tier.is_some() {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "{prefix}:bandwidth_committed=false 时不得再填 bandwidth_tier_mbps(11103)"
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 走到这里判据已放行 ⇒ 出口/数量必有值;档位在承诺态必有值、不承诺态必为 NULL。
|
|
|
let line_exit = r
|
|
let line_exit = r
|
|
|
.line_exit
|
|
.line_exit
|
|
|
.ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后线路出口仍缺值")))?;
|
|
.ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后线路出口仍缺值")))?;
|
|
|
- let tier = r
|
|
|
|
|
- .tier
|
|
|
|
|
- .ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后带宽档位仍缺值")))?;
|
|
|
|
|
|
|
+ let tier = if committed {
|
|
|
|
|
+ Some(
|
|
|
|
|
+ r.tier
|
|
|
|
|
+ .ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后带宽档位仍缺值")))?,
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ None
|
|
|
|
|
+ };
|
|
|
let count = r
|
|
let count = r
|
|
|
.count
|
|
.count
|
|
|
.ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后 IP 数量仍缺值")))?;
|
|
.ok_or_else(|| BosError::internal(format!("{prefix}:判据通过后 IP 数量仍缺值")))?;
|
|
@@ -1376,6 +1446,18 @@ fn resolve_ips(need: bool, raw: &[IpEntryReq]) -> Result<(Vec<IpIns>, Vec<String
|
|
|
Ok((out, dropped))
|
|
Ok((out, dropped))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// IP 条目的**带宽档位**目录校验(2026-11-16:档位在套餐配置里增删,⛔ 写死 5/10/30)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 与出口同一纪律:一次收集所有不合法值再整单拒绝;`None`(不承诺带宽)也须目录里配了那一档。
|
|
|
|
|
+async fn check_ip_tiers(db: &UdsClient, ips: &[IpIns]) -> Result<(), BosError> {
|
|
|
|
|
+ let uses: Vec<(String, Option<i64>)> = ips
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .enumerate()
|
|
|
|
|
+ .map(|(index, e)| (format!("ip_entries[{index}].bandwidth_tier_mbps"), e.tier))
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ super::ip_bandwidth_tier::check_configured(db, &uses).await
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 载荷里出现过的只读/派生键(顶层 `extra` + 条目/IP 的 `extra`)。
|
|
/// 载荷里出现过的只读/派生键(顶层 `extra` + 条目/IP 的 `extra`)。
|
|
|
fn readonly_hits(
|
|
fn readonly_hits(
|
|
|
extra: &HashMap<String, Value>,
|
|
extra: &HashMap<String, Value>,
|
|
@@ -1547,8 +1629,9 @@ fn ip_params(contract_id: &str, entry_id: &str, e: &IpIns) -> Vec<Value> {
|
|
|
Value::String(entry_id.to_string()),
|
|
Value::String(entry_id.to_string()),
|
|
|
Value::String(contract_id.to_string()),
|
|
Value::String(contract_id.to_string()),
|
|
|
Value::String(e.line_exit.clone()),
|
|
Value::String(e.line_exit.clone()),
|
|
|
- Value::from(e.tier),
|
|
|
|
|
- Value::from(e.count),
|
|
|
|
|
|
|
+ // 可空数值列:文本入参+SQL 侧 `$n::text::int`(见 [`num_text`] 的绑参说明)。
|
|
|
|
|
+ num_text(e.tier),
|
|
|
|
|
+ Value::String(e.count.to_string()),
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1843,6 +1926,7 @@ async fn do_create(
|
|
|
.map(|(index, e)| (format!("ip_entries[{index}].line_exit"), e.line_exit.clone()))
|
|
.map(|(index, e)| (format!("ip_entries[{index}].line_exit"), e.line_exit.clone()))
|
|
|
.collect();
|
|
.collect();
|
|
|
super::line_exit::check_configured(db, &ip_uses).await?;
|
|
super::line_exit::check_configured(db, &ip_uses).await?;
|
|
|
|
|
+ check_ip_tiers(db, &ips).await?;
|
|
|
|
|
|
|
|
// ② 服务构成:空=L215、形态互斥=L216、档位缺失/停用/跨客户=I112(⛔ 本地再判一遍)。
|
|
// ② 服务构成:空=L215、形态互斥=L216、档位缺失/停用/跨客户=I112(⛔ 本地再判一遍)。
|
|
|
let (mut items, item_dropped) = resolve_items(db, customer_id, raw_items).await?;
|
|
let (mut items, item_dropped) = resolve_items(db, customer_id, raw_items).await?;
|
|
@@ -2076,7 +2160,7 @@ async fn do_update(
|
|
|
// 经办人=录入账号(`contract.created_by`):新建时由服务端按登录账号写入,建后与状态/来源
|
|
// 经办人=录入账号(`contract.created_by`):新建时由服务端按登录账号写入,建后与状态/来源
|
|
|
// 无关**一律只读**(`KLT-L221`)。⚠️ 与 `agent_name`/`agent_mobile`/`agent_org` 是两件事:
|
|
// 无关**一律只读**(`KLT-L221`)。⚠️ 与 `agent_name`/`agent_mobile`/`agent_org` 是两件事:
|
|
|
// 那三项是**运营商交接单上的经办人**,属商务档案、随 `archive` 轴可改(见下「编辑口径闸门」)。
|
|
// 那三项是**运营商交接单上的经办人**,属商务档案、随 `archive` 轴可改(见下「编辑口径闸门」)。
|
|
|
- for key in ["created_by", "created_by_name"] {
|
|
|
|
|
|
|
+ for key in ["created_by", "created_by_name", "created_by_org", "created_by_mobile"] {
|
|
|
if b.extra.contains_key(key) {
|
|
if b.extra.contains_key(key) {
|
|
|
return Err(BosError::klt(
|
|
return Err(BosError::klt(
|
|
|
KltCode::L221,
|
|
KltCode::L221,
|
|
@@ -2239,6 +2323,7 @@ async fn do_update(
|
|
|
.map(|(index, e)| (format!("ip_entries[{index}].line_exit"), e.line_exit.clone()))
|
|
.map(|(index, e)| (format!("ip_entries[{index}].line_exit"), e.line_exit.clone()))
|
|
|
.collect();
|
|
.collect();
|
|
|
super::line_exit::check_configured(db, &ip_uses).await?;
|
|
super::line_exit::check_configured(db, &ip_uses).await?;
|
|
|
|
|
+ check_ip_tiers(db, &ips).await?;
|
|
|
let replace_ips = b.ip_entries.is_some();
|
|
let replace_ips = b.ip_entries.is_some();
|
|
|
|
|
|
|
|
if !touched_main && b.service_items.is_none() && !replace_ips {
|
|
if !touched_main && b.service_items.is_none() && !replace_ips {
|
|
@@ -2437,7 +2522,7 @@ async fn do_update(
|
|
|
let sig = |e: &Value| {
|
|
let sig = |e: &Value| {
|
|
|
ip_label(
|
|
ip_label(
|
|
|
e.get("line_exit").and_then(Value::as_str).unwrap_or(""),
|
|
e.get("line_exit").and_then(Value::as_str).unwrap_or(""),
|
|
|
- e.get("bandwidth_tier_mbps").and_then(Value::as_i64).unwrap_or(0),
|
|
|
|
|
|
|
+ e.get("bandwidth_tier_mbps").and_then(Value::as_i64),
|
|
|
e.get("ip_count").and_then(Value::as_i64).unwrap_or(0),
|
|
e.get("ip_count").and_then(Value::as_i64).unwrap_or(0),
|
|
|
)
|
|
)
|
|
|
};
|
|
};
|
|
@@ -2701,6 +2786,36 @@ async fn opened_flags(db: &UdsClient, ids: &[String]) -> Result<HashMap<String,
|
|
|
contracts_opened(&probes)
|
|
contracts_opened(&probes)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 合同侧「是否已开通」列下方的**实际开通日**(04 册 §4.5:优先取关联订单上的
|
|
|
|
|
+/// `actual_opened_at`;多份订单时取**最早**一个,即首次交付日)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 与 [`opened_flags`] 同一条 `IN` 批量读,⛔ 逐行 N+1;只收非空值,空值=尚未回填。
|
|
|
|
|
+async fn opened_dates(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, String>, BosError> {
|
|
|
|
|
+ let mut out: HashMap<String, String> = HashMap::with_capacity(ids.len());
|
|
|
|
|
+ if ids.is_empty() {
|
|
|
|
|
+ return Ok(out);
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let in_pred = push_in(&mut p, "s.contract_id", ids, "text");
|
|
|
|
|
+ let sql = format!(
|
|
|
|
|
+ "SELECT s.contract_id AS contract_id, s.actual_opened_at AS opened_at \
|
|
|
|
|
+ FROM subscription s WHERE {in_pred}"
|
|
|
|
|
+ );
|
|
|
|
|
+ for r in db.query_all::<SubOpenedRow>(&sql, p.values()).await? {
|
|
|
|
|
+ let Some(d) = r.opened_at.filter(|v| !v.trim().is_empty()) else {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ };
|
|
|
|
|
+ out.entry(r.contract_id)
|
|
|
|
|
+ .and_modify(|cur| {
|
|
|
|
|
+ if d < *cur {
|
|
|
|
|
+ *cur = d.clone();
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .or_insert(d);
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(out)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 编辑口径出参(04 册 §4.2):只给布尔与原因码,文案表在前端(⛔ 后端拼提示语)。
|
|
/// 编辑口径出参(04 册 §4.2):只给布尔与原因码,文案表在前端(⛔ 后端拼提示语)。
|
|
|
fn edit_scope_json(s: &ContractEditScope) -> Value {
|
|
fn edit_scope_json(s: &ContractEditScope) -> Value {
|
|
|
let axis = |a: &AxisLock| {
|
|
let axis = |a: &AxisLock| {
|
|
@@ -2794,8 +2909,11 @@ fn item_label(kind: &str, plan_id: Option<&str>, quantity: Option<i64>, accounts
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// IP 条目的可读名(整组替换 ⇒ ⛔ 按 `entry_id` 三向对比,只按内容多重集对比)。
|
|
/// IP 条目的可读名(整组替换 ⇒ ⛔ 按 `entry_id` 三向对比,只按内容多重集对比)。
|
|
|
-fn ip_label(line_exit: &str, tier: i64, count: i64) -> String {
|
|
|
|
|
- format!("{line_exit} · {tier}M · {count} IP")
|
|
|
|
|
|
|
+fn ip_label(line_exit: &str, tier: Option<i64>, count: i64) -> String {
|
|
|
|
|
+ match tier {
|
|
|
|
|
+ Some(mbps) => format!("{line_exit} · {mbps}M · {count} IP"),
|
|
|
|
|
+ None => format!("{line_exit} · 不承诺带宽 · {count} IP"),
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// 多重集差(`created`=新有旧无、`deleted`=旧有新无)。返回 `(created, deleted)`。
|
|
/// 多重集差(`created`=新有旧无、`deleted`=旧有新无)。返回 `(created, deleted)`。
|
|
@@ -2972,19 +3090,32 @@ pub async fn get_list(
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
|
|
+ // 04 册 §4.5:「是否已开通」标签下方的**实际开通日**(关联订单回填值,多份取最早)。
|
|
|
|
|
+ let opened_on = match opened_dates(state.db.as_ref(), &cids).await {
|
|
|
|
|
+ Ok(m) => m,
|
|
|
|
|
+ Err(e) => return json_err(e),
|
|
|
|
|
+ };
|
|
|
json_ok(with_pending(json!({
|
|
json_ok(with_pending(json!({
|
|
|
"items": rows
|
|
"items": rows
|
|
|
.iter()
|
|
.iter()
|
|
|
- .map(|r| with_opened(
|
|
|
|
|
- with_children(
|
|
|
|
|
- base_json(r, names.get(&r.customer_id).map(String::as_str)),
|
|
|
|
|
- &r.contract_id,
|
|
|
|
|
- &items,
|
|
|
|
|
- &ips,
|
|
|
|
|
- ),
|
|
|
|
|
- r,
|
|
|
|
|
- &flags,
|
|
|
|
|
- ))
|
|
|
|
|
|
|
+ .map(|r| {
|
|
|
|
|
+ let mut v = with_opened(
|
|
|
|
|
+ with_children(
|
|
|
|
|
+ base_json(r, names.get(&r.customer_id).map(String::as_str)),
|
|
|
|
|
+ &r.contract_id,
|
|
|
|
|
+ &items,
|
|
|
|
|
+ &ips,
|
|
|
|
|
+ ),
|
|
|
|
|
+ r,
|
|
|
|
|
+ &flags,
|
|
|
|
|
+ );
|
|
|
|
|
+ // 未回填=`null`(界面标「待回填」),⛔ 折成空串让前端分不出「未开通」。
|
|
|
|
|
+ v["actual_opened_at"] = match opened_on.get(&r.contract_id) {
|
|
|
|
|
+ Some(d) => json!(d),
|
|
|
|
|
+ None => Value::Null,
|
|
|
|
|
+ };
|
|
|
|
|
+ v
|
|
|
|
|
+ })
|
|
|
.collect::<Vec<Value>>(),
|
|
.collect::<Vec<Value>>(),
|
|
|
"total": total_n,
|
|
"total": total_n,
|
|
|
"page": body.pg.page,
|
|
"page": body.pg.page,
|
|
@@ -3049,6 +3180,16 @@ pub async fn get(
|
|
|
v["subscriptions"] = json!(subs);
|
|
v["subscriptions"] = json!(subs);
|
|
|
v["subscriptions_note"] =
|
|
v["subscriptions_note"] =
|
|
|
json!("关联订阅按 contract_id 现查 subscription 组装(第 6 类只读关联,⛔ 冗余列)");
|
|
json!("关联订阅按 contract_id 现查 subscription 组装(第 6 类只读关联,⛔ 冗余列)");
|
|
|
|
|
+ // 04 册 §4.5:详情「商业信息 · 网络开通」的实际开通日同样取关联订单回填值(多份取最早)。
|
|
|
|
|
+ // 此前只下发 `opened` 不下发日期 ⇒ 已开通合同显示「已开通 · 待回填日期」,与下方
|
|
|
|
|
+ // 「04 关联订单」里的实际开通日自相矛盾。
|
|
|
|
|
+ v["actual_opened_at"] = match opened_dates(state.db.as_ref(), &ids).await {
|
|
|
|
|
+ Ok(m) => match m.get(&r.contract_id) {
|
|
|
|
|
+ Some(d) => json!(d),
|
|
|
|
|
+ None => Value::Null,
|
|
|
|
|
+ },
|
|
|
|
|
+ Err(e) => return json_err(e),
|
|
|
|
|
+ };
|
|
|
// D-23:「01 客户资料」段此前只回 `customer_id`+`customer_name` ⇒ 六项全显「未登记」。
|
|
// D-23:「01 客户资料」段此前只回 `customer_id`+`customer_name` ⇒ 六项全显「未登记」。
|
|
|
// 档案取不到(客户被注销)=`null` +如实口径,⛔ 让界面把「档案取不到」显示成「未登记」。
|
|
// 档案取不到(客户被注销)=`null` +如实口径,⛔ 让界面把「档案取不到」显示成「未登记」。
|
|
|
let profile = match customer_profile(&state, &r.customer_id).await {
|
|
let profile = match customer_profile(&state, &r.customer_id).await {
|
|
@@ -3644,11 +3785,28 @@ mod tests {
|
|
|
assert_eq!(klt_of(e), Some("KLT-L212"));
|
|
assert_eq!(klt_of(e), Some("KLT-L212"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn IP_条目数值列一律文本入参() {
|
|
|
|
|
+ // UDS 语句缓存键只含 SQL 原文:同一段 INSERT 先收 NULL(TEXT 绑)再收数字(INT8 绑)
|
|
|
|
|
+ // 会报 `invalid byte sequence for encoding "UTF8": 0x00`(2026-11-16 实测:
|
|
|
|
|
+ // 合同先存「不承诺带宽」、再改回 10 兆即复现)。⇒ 数值列⛔ 直发数字。
|
|
|
|
|
+ assert!(IP_INSERT.contains("$4::text::int"), "带宽列必须文本入参:{IP_INSERT}");
|
|
|
|
|
+ assert!(IP_INSERT.contains("$5::text::int"), "IP 数必须文本入参:{IP_INSERT}");
|
|
|
|
|
+ let e = IpIns { line_exit: "美国".to_string(), tier: Some(10), count: 2 };
|
|
|
|
|
+ let p = ip_params("CT-000001", "IE-000001", &e);
|
|
|
|
|
+ assert_eq!(p[3], Value::String("10".to_string()));
|
|
|
|
|
+ assert_eq!(p[4], Value::String("2".to_string()));
|
|
|
|
|
+ // 「不承诺带宽」=NULL(`NULL::text::int` 仍是 NULL,语义不变)。
|
|
|
|
|
+ let u = IpIns { line_exit: "美国".to_string(), tier: None, count: 1 };
|
|
|
|
|
+ assert_eq!(ip_params("CT-000001", "IE-000001", &u)[3], Value::Null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[test]
|
|
#[test]
|
|
|
fn 勾选与备案条目互相矛盾一律_L217() {
|
|
fn 勾选与备案条目互相矛盾一律_L217() {
|
|
|
let row = IpEntryRaw {
|
|
let row = IpEntryRaw {
|
|
|
line_exit: Some("CMNET-1"),
|
|
line_exit: Some("CMNET-1"),
|
|
|
bandwidth_tier_mbps: Some(10),
|
|
bandwidth_tier_mbps: Some(10),
|
|
|
|
|
+ bandwidth_committed: None,
|
|
|
ip_count: Some(2),
|
|
ip_count: Some(2),
|
|
|
};
|
|
};
|
|
|
assert_eq!(
|
|
assert_eq!(
|