|
@@ -36,7 +36,7 @@
|
|
|
//! ⚠️ `customer_name`:`contract` 只有 `customer_id`,名字在 `customer.customer_name`
|
|
//! ⚠️ `customer_name`:`contract` 只有 `customer_id`,名字在 `customer.customer_name`
|
|
|
//! ⇒ 分页后按本页 `customer_id` 集合回查(⛔ JOIN 嵌套循环)。
|
|
//! ⇒ 分页后按本页 `customer_id` 集合回查(⛔ JOIN 嵌套循环)。
|
|
|
|
|
|
|
|
-use std::collections::{BTreeSet, HashMap};
|
|
|
|
|
|
|
+use std::collections::{BTreeSet, HashMap, HashSet};
|
|
|
|
|
|
|
|
use axum::extract::State;
|
|
use axum::extract::State;
|
|
|
use axum::response::Response;
|
|
use axum::response::Response;
|
|
@@ -59,7 +59,7 @@ use bos_invariant::{
|
|
|
check_contract_deletable, check_contract_items, check_ip_entries, contract_edit_scope,
|
|
check_contract_deletable, check_contract_items, check_ip_entries, contract_edit_scope,
|
|
|
contracts_opened, monthly_settle_of, resolve_contract_no, validate_contract_payload, AxisLock,
|
|
contracts_opened, monthly_settle_of, resolve_contract_no, validate_contract_payload, AxisLock,
|
|
|
ContractDraft, ContractEditScope, ContractItemRaw, ContractRaw, CrossRead, IpEntryRaw, ItemKind,
|
|
ContractDraft, ContractEditScope, ContractItemRaw, ContractRaw, CrossRead, IpEntryRaw, ItemKind,
|
|
|
- Opened, OpenedProbe, PlanRef, UseCategory,
|
|
|
|
|
|
|
+ Opened, OpenedProbe, PlanRef, UseCategory, CONTRACT_ATTACHMENT_KEY_PREFIX,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/// 补列后设计列**全部在册** ⇒ 无缺列;键仍回给前端(值=空数组),契约形状不变。
|
|
/// 补列后设计列**全部在册** ⇒ 无缺列;键仍回给前端(值=空数组),契约形状不变。
|
|
@@ -253,9 +253,37 @@ pub struct IpEntryReq {
|
|
|
pub extra: HashMap<String, Value>,
|
|
pub extra: HashMap<String, Value>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(Deserialize)]
|
|
|
|
|
+pub struct CustomerInlineReq {
|
|
|
|
|
+ /// 客户名称(必填,允许重名——查重靠识别号)。
|
|
|
|
|
+ pub customer_name: Option<String>,
|
|
|
|
|
+ /// `enterprise`/`individual`/`sole_proprietor`(必填)。
|
|
|
|
|
+ pub subject_type: Option<String>,
|
|
|
|
|
+ /// 客户识别号(必填):既是安全存储的载体,也是**重试幂等键**。
|
|
|
|
|
+ pub id_code: Option<String>,
|
|
|
|
|
+ pub contact_name: Option<String>,
|
|
|
|
|
+ pub contact_mobile: Option<String>,
|
|
|
|
|
+ pub address: Option<String>,
|
|
|
|
|
+ /// 挂载区域(区域树节点 ID;与 `/customer/create@v1` 的 `parent_node_id` 同义,必填)。
|
|
|
|
|
+ pub parent_node_id: Option<String>,
|
|
|
|
|
+ /// 归属运营商(必填;弹窗内下拉,候选=所挂区域省份下可见的运营商)。
|
|
|
|
|
+ pub operator_id: Option<String>,
|
|
|
|
|
+ /// 运维团队(必填**恰好 1 支**,单支定案;弹窗内下拉)。
|
|
|
|
|
+ pub ops_team_ids: Option<Vec<String>>,
|
|
|
|
|
+ /// 营业执照影像:本通道**可留空**(建档后到客户档案「补传/替换」);
|
|
|
|
|
+ /// 主体类型不是企业时⛔ 收(与 `customer/create` 同一条判据)。
|
|
|
|
|
+ pub license: Option<super::customer::LicenseInput>,
|
|
|
|
|
+ /// 主账号登录名(选填;留空按主体号派生)。
|
|
|
|
|
+ pub primary_username: Option<String>,
|
|
|
|
|
+ pub primary_mobile: Option<String>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
|
pub struct ContractCreateReq {
|
|
pub struct ContractCreateReq {
|
|
|
pub customer_id: Option<String>,
|
|
pub customer_id: Option<String>,
|
|
|
|
|
+ /// 客户未命中时的**内联建档**段(需求 §5.3 CU-13;业主 2026-11-16 定案关闭 CU-41)。
|
|
|
|
|
+ /// ⚠️ 与 `customer_id` 只可二选一;它只在本接口内生效,⛔ 另开路由。
|
|
|
|
|
+ pub customer_inline: Option<CustomerInlineReq>,
|
|
|
/// 合同编号(空则服务端发号 `{customer_id}-C{序号}`)。
|
|
/// 合同编号(空则服务端发号 `{customer_id}-C{序号}`)。
|
|
|
pub contract_no: Option<String>,
|
|
pub contract_no: Option<String>,
|
|
|
pub external_no: Option<String>,
|
|
pub external_no: Option<String>,
|
|
@@ -551,6 +579,48 @@ fn with_pending(v: Value) -> Value {
|
|
|
v
|
|
v
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 合同附件取值形态(2026-11-16 单值附件定案):
|
|
|
|
|
+/// * `none`=未登记;`link`=外部 `http(s)` 链接(可直接打开);
|
|
|
|
|
+/// * `object`=平台桶对象键([`CONTRACT_ATTACHMENT_KEY_PREFIX`] 下)⇒ 读口现签,⛔ 当链接下发。
|
|
|
|
|
+fn attachment_kind_of(raw: Option<&str>) -> &'static str {
|
|
|
|
|
+ match raw.map(str::trim).filter(|s| !s.is_empty()) {
|
|
|
|
|
+ None => "none",
|
|
|
|
|
+ Some(s) if s.starts_with("http://") || s.starts_with("https://") => "link",
|
|
|
|
|
+ Some(s) if s.starts_with(CONTRACT_ATTACHMENT_KEY_PREFIX) => "object",
|
|
|
|
|
+ // 存量脏值(形态校验上线前写入):如实标 `other`,⛔ 冒充 link 让界面渲染死链。
|
|
|
|
|
+ Some(_) => "other",
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 合同附件现签下载地址(只对 `object` 形态发起平台调用;其余形态不付这次开销)。
|
|
|
|
|
+///
|
|
|
|
|
+/// ⚠️ 失败关闭:`Err` ⇒ 读口整体报下游故障,⛔ 静默回 `None`——那会把平台故障
|
|
|
|
|
+/// 伪装成「这份合同没有附件」,界面上的「查看附件」会无故消失。
|
|
|
|
|
+async fn attachment_view_url(
|
|
|
|
|
+ state: &AppState,
|
|
|
|
|
+ contract_id: &str,
|
|
|
|
|
+ raw: Option<&str>,
|
|
|
|
|
+) -> Result<Option<(String, Option<String>)>, BosError> {
|
|
|
|
|
+ if attachment_kind_of(raw) != "object" {
|
|
|
|
|
+ return Ok(None);
|
|
|
|
|
+ }
|
|
|
|
|
+ let key = raw.unwrap_or_default().trim();
|
|
|
|
|
+ let sig = state
|
|
|
|
|
+ .platform
|
|
|
|
|
+ .oss_presign_get(&state.tenant_id, &state.project_id, key)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .map_err(|e| {
|
|
|
|
|
+ BosError::biz(
|
|
|
|
|
+ ErrorCode::Downstream,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "合同 {contract_id} 的附件下载签名获取失败({e})⇒ 本次不下发 attachment_view_url;\
|
|
|
|
|
+ 合同其余字段可正常读取,请稍后重试"
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+ })?;
|
|
|
|
|
+ Ok(Some((sig.presigned_url, sig.expires_at)))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 按合同 ID 集合批量回查两张子表(⛔ 逐条 N+1)。
|
|
/// 按合同 ID 集合批量回查两张子表(⛔ 逐条 N+1)。
|
|
|
async fn load_children(db: &UdsClient, ids: &[String]) -> Result<(Children, Children), BosError> {
|
|
async fn load_children(db: &UdsClient, ids: &[String]) -> Result<(Children, Children), BosError> {
|
|
|
if ids.is_empty() {
|
|
if ids.is_empty() {
|
|
@@ -1458,6 +1528,68 @@ async fn check_ip_tiers(db: &UdsClient, ips: &[IpIns]) -> Result<(), BosError> {
|
|
|
super::ip_bandwidth_tier::check_configured(db, &uses).await
|
|
super::ip_bandwidth_tier::check_configured(db, &uses).await
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 固定 IP 条目的线路出口只能是本合同服务构成条目已选出口(2026-11-16 裁定)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 与 [`super::line_exit::check_configured`] 是**两道**闸门:目录校验回答「这个出口在
|
|
|
|
|
+/// 套餐配置里配过吗」,本函数回答「这个出口在本合同服务构成里选过吗」。比对口径沿用目录的
|
|
|
|
|
+/// 归一化键([`super::line_exit::exit_key`]:去全部空白+小写),两处一致才不会出现
|
|
|
|
|
+/// 「条目写『美 国』、IP 写『美国』被误拦」。
|
|
|
|
|
+///
|
|
|
|
|
+/// `item_exits` 取**生效**条目的 `line_exits`:新建=请求解析结果;修改时载荷带服务构成=
|
|
|
|
|
+/// 请求解析结果,否则=库里在册条目(只改 IP 时不能拿全量目录兜底)。
|
|
|
|
|
+fn check_ip_exits_in_items<'a>(
|
|
|
|
|
+ ips: &[IpIns],
|
|
|
|
|
+ item_exits: impl IntoIterator<Item = Option<&'a Value>>,
|
|
|
|
|
+) -> Result<(), BosError> {
|
|
|
|
|
+ if ips.is_empty() {
|
|
|
|
|
+ return Ok(());
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut allowed: HashSet<String> = HashSet::new();
|
|
|
|
|
+ for value in item_exits.into_iter().flatten() {
|
|
|
|
|
+ collect_item_exit_keys(value, &mut allowed);
|
|
|
|
|
+ }
|
|
|
|
|
+ let bad: Vec<String> = ips
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .enumerate()
|
|
|
|
|
+ .filter(|(_, e)| match super::line_exit::exit_key(&e.line_exit) {
|
|
|
|
|
+ Some(key) => !allowed.contains(&key),
|
|
|
|
|
+ None => true,
|
|
|
|
|
+ })
|
|
|
|
|
+ .map(|(index, e)| format!("ip_entries[{index}].line_exit「{}」", e.line_exit))
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ if bad.is_empty() {
|
|
|
|
|
+ return Ok(());
|
|
|
|
|
+ }
|
|
|
|
|
+ Err(BosError::bad_params(format!(
|
|
|
|
|
+ "固定 IP 条目的线路出口必须从本合同服务构成已选出口中选取(11103):{}",
|
|
|
|
|
+ bad.join("、")
|
|
|
|
|
+ )))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 从条目 `line_exits` 单元格收集归一化出口键(JSONB 可能整列回字符串)。
|
|
|
|
|
+fn collect_item_exit_keys(value: &Value, out: &mut HashSet<String>) {
|
|
|
|
|
+ match value {
|
|
|
|
|
+ Value::Array(items) => {
|
|
|
|
|
+ for name in items.iter().filter_map(Value::as_str) {
|
|
|
|
|
+ if let Some(key) = super::line_exit::exit_key(name) {
|
|
|
|
|
+ out.insert(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // UDS 的 JSONB 列偶尔以 JSON 文本回传(同 `json_cell` 的坑):先按数组解析,
|
|
|
|
|
+ // 解析不了再当单个出口原文处理,⛔ 直接丢弃(会把合法条目判成「没选出口」)。
|
|
|
|
|
+ Value::String(text) => match serde_json::from_str::<Value>(text) {
|
|
|
|
|
+ Ok(inner) => collect_item_exit_keys(&inner, out),
|
|
|
|
|
+ Err(_) => {
|
|
|
|
|
+ if let Some(key) = super::line_exit::exit_key(text) {
|
|
|
|
|
+ out.insert(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ _ => {}
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 载荷里出现过的只读/派生键(顶层 `extra` + 条目/IP 的 `extra`)。
|
|
/// 载荷里出现过的只读/派生键(顶层 `extra` + 条目/IP 的 `extra`)。
|
|
|
fn readonly_hits(
|
|
fn readonly_hits(
|
|
|
extra: &HashMap<String, Value>,
|
|
extra: &HashMap<String, Value>,
|
|
@@ -1485,7 +1617,7 @@ fn readonly_guard(keys: &[String]) -> Result<(), BosError> {
|
|
|
return Ok(());
|
|
return Ok(());
|
|
|
}
|
|
}
|
|
|
Err(BosError::bad_params(format!(
|
|
Err(BosError::bad_params(format!(
|
|
|
- "只读/派生键⛔ 提交(11103):{}",
|
|
|
|
|
|
|
+ "只读/派生键不提交(11103):{}",
|
|
|
keys.join("、")
|
|
keys.join("、")
|
|
|
)))
|
|
)))
|
|
|
}
|
|
}
|
|
@@ -1902,11 +2034,167 @@ async fn do_create(
|
|
|
state: &AppState,
|
|
state: &AppState,
|
|
|
auth: &AuthContext,
|
|
auth: &AuthContext,
|
|
|
b: &ContractCreateReq,
|
|
b: &ContractCreateReq,
|
|
|
|
|
+) -> Result<Value, BosError> {
|
|
|
|
|
+ let (customer_id, inline) = resolve_contract_customer(state, auth, b).await?;
|
|
|
|
|
+ match do_create_for_customer(state, auth, b, &customer_id).await {
|
|
|
|
|
+ Ok(mut v) => {
|
|
|
|
|
+ if let Some(info) = inline {
|
|
|
|
|
+ v["inline_customer"] = info;
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(v)
|
|
|
|
|
+ }
|
|
|
|
|
+ // 建档成功而合同事务失败 ⇒ 客户已存在(设计 04 册 §4.2 ①「失败形态天然可恢复」)。
|
|
|
|
|
+ // ⛔ 补偿/回滚客户:把已分配的主体号写进错误文案,让操作人改用 `customer_id` 重试,
|
|
|
|
|
+ // 避免再提交一次 `customer_inline` 撞识别号唯一索引。
|
|
|
|
|
+ Err(e) => Err(match inline {
|
|
|
|
|
+ Some(info) => inline_failure_note(e, &customer_id, &info),
|
|
|
|
|
+ None => e,
|
|
|
|
|
+ }),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 合同写入口的客户解析(CU-13:命中即挂、未命中随合同建档)。
|
|
|
|
|
+///
|
|
|
|
|
+/// `customer_id` 与 `customer_inline` **只可二选一**(同时给=口径错,⛔ 静默取其一);
|
|
|
|
|
+/// 都不给=`60004` 业务文案(与 CU-51 的缺合同号同族,⛔ serde 的 `missing field`)。
|
|
|
|
|
+async fn resolve_contract_customer(
|
|
|
|
|
+ state: &AppState,
|
|
|
|
|
+ auth: &AuthContext,
|
|
|
|
|
+ b: &ContractCreateReq,
|
|
|
|
|
+) -> Result<(String, Option<Value>), BosError> {
|
|
|
|
|
+ let picked = trimmed(&b.customer_id);
|
|
|
|
|
+ match (picked, b.customer_inline.as_ref()) {
|
|
|
|
|
+ (Some(id), None) => {
|
|
|
|
|
+ // 客户不在可见/可代录范围=`KLT-L211`(⛔ bad_params:前端靠在册码分「客户选错」与「报文不对」)。
|
|
|
|
|
+ ensure_customer_visible(state, auth, id).await?;
|
|
|
|
|
+ Ok((id.to_string(), None))
|
|
|
|
|
+ }
|
|
|
|
|
+ (None, Some(raw)) => {
|
|
|
|
|
+ let body = inline_customer_body(raw)?;
|
|
|
|
|
+ let v = super::customer::create_inline(state, auth, body).await?;
|
|
|
|
|
+ let created = v
|
|
|
|
|
+ .get("customer_id")
|
|
|
|
|
+ .and_then(Value::as_str)
|
|
|
|
|
+ .map(str::to_string)
|
|
|
|
|
+ .ok_or_else(|| {
|
|
|
|
|
+ BosError::internal(
|
|
|
|
|
+ "内联建档未回 customer_id(客户档案是否已落库无法判定)⇒ 请到客户管理核对后再录合同",
|
|
|
|
|
+ )
|
|
|
|
|
+ })?;
|
|
|
|
|
+ let info = json!({
|
|
|
|
|
+ "customer_id": created,
|
|
|
|
|
+ "customer_name": v.get("customer_name").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ "user_id": v.get("user_id").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ "primary_username": v.pointer("/primary_account/username").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ "acct_status": v.get("acct_status").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ "code_issued": v.get("code_issued").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ "license_pending": v.get("license_pending").cloned().unwrap_or(Value::Null),
|
|
|
|
|
+ });
|
|
|
|
|
+ Ok((created, Some(info)))
|
|
|
|
|
+ }
|
|
|
|
|
+ (Some(_), Some(_)) => Err(BosError::bad_params(
|
|
|
|
|
+ "customer_id 与 customer_inline 只可二选一:命中已有客户就不再提交新建客户资料",
|
|
|
|
|
+ )),
|
|
|
|
|
+ (None, None) => Err(BosError::bad_params(
|
|
|
|
|
+ "请选择签约客户:命中已有客户提交 customer_id;未命中则提交 customer_inline\
|
|
|
|
|
+ (CU-13 未命中随合同建档,含客户名称/主体类型/识别号/联系人/电话/地址/挂载区域/运营商/运维团队)",
|
|
|
|
|
+ )),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 内联客户段 → `/customer/create@v1` 的同一份请求体(⚠️ 两通道共用建档实现,⛔ 各自实现)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 必填集=需求 CU-13 第 1 步逐字:客户名称、主体类型、识别号、经办联系人、联系电话、地址、
|
|
|
|
|
+/// 挂载区域,加「运营商、运维团队」两个下拉(业主 2026-11-16 定案:弹窗内给选择位,默认预选
|
|
|
|
|
+/// 范围内第一个,⛔ 后端静默取第一个)。识别号**必填**:它同时是幂等键——合同事务失败后
|
|
|
|
|
+/// 重试要靠它命中已建客户,否则会建出第二个。
|
|
|
|
|
+fn inline_customer_body(
|
|
|
|
|
+ raw: &CustomerInlineReq,
|
|
|
|
|
+) -> Result<super::customer::CustomerCreate, BosError> {
|
|
|
|
|
+ let need = |v: &Option<String>, field: &str, hint: &str| -> Result<String, BosError> {
|
|
|
|
|
+ v.as_deref()
|
|
|
|
|
+ .map(str::trim)
|
|
|
|
|
+ .filter(|s| !s.is_empty())
|
|
|
|
|
+ .map(str::to_string)
|
|
|
|
|
+ .ok_or_else(|| BosError::bad_params(format!("新建客户缺少{field}(11103):{hint}")))
|
|
|
|
|
+ };
|
|
|
|
|
+ let teams = raw
|
|
|
|
|
+ .ops_team_ids
|
|
|
|
|
+ .as_ref()
|
|
|
|
|
+ .map(|v| {
|
|
|
|
|
+ v.iter()
|
|
|
|
|
+ .map(|s| s.trim().to_string())
|
|
|
|
|
+ .filter(|s| !s.is_empty())
|
|
|
|
|
+ .collect::<Vec<_>>()
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter(|v| !v.is_empty())
|
|
|
|
|
+ .ok_or_else(|| {
|
|
|
|
|
+ BosError::bad_params(
|
|
|
|
|
+ "新建客户缺少运维团队(11103):单支定案,请提交 ops_team_ids=[团队 ID]",
|
|
|
|
|
+ )
|
|
|
|
|
+ })?;
|
|
|
|
|
+ Ok(super::customer::CustomerCreate {
|
|
|
|
|
+ customer_name: need(&raw.customer_name, "客户名称", "customer_inline.customer_name")?,
|
|
|
|
|
+ subject_type: need(
|
|
|
|
|
+ &raw.subject_type,
|
|
|
|
|
+ "主体类型",
|
|
|
|
|
+ "customer_inline.subject_type(enterprise/individual/sole_proprietor)",
|
|
|
|
|
+ )?,
|
|
|
|
|
+ operator_id: need(&raw.operator_id, "归属运营商", "customer_inline.operator_id")?,
|
|
|
|
|
+ mount_request_id: None,
|
|
|
|
|
+ parent_node_id: Some(need(
|
|
|
|
|
+ &raw.parent_node_id,
|
|
|
|
|
+ "挂载区域",
|
|
|
|
|
+ "customer_inline.parent_node_id(区域树节点 ID)",
|
|
|
|
|
+ )?),
|
|
|
|
|
+ partner_id: None,
|
|
|
|
|
+ id_code: Some(need(
|
|
|
|
|
+ &raw.id_code,
|
|
|
|
|
+ "客户识别号",
|
|
|
|
|
+ "customer_inline.id_code(幂等键:合同事务失败重试要靠它命中已建客户)",
|
|
|
|
|
+ )?),
|
|
|
|
|
+ contact_name: trimmed(&raw.contact_name).map(str::to_string),
|
|
|
|
|
+ contact_mobile: trimmed(&raw.contact_mobile).map(str::to_string),
|
|
|
|
|
+ address: trimmed(&raw.address).map(str::to_string),
|
|
|
|
|
+ ops_team_ids: Some(teams),
|
|
|
|
|
+ primary_username: trimmed(&raw.primary_username).map(str::to_string),
|
|
|
|
|
+ primary_mobile: trimmed(&raw.primary_mobile).map(str::to_string),
|
|
|
|
|
+ // 本通道影像可留空(业主 2026-11-16 定案);给了照常落库。
|
|
|
|
|
+ license: raw.license.clone(),
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 合同事务失败时把「客户已建成」写进错误文案(⛔ 静默失败 ⇒ 操作人会重复建档)。
|
|
|
|
|
+fn inline_failure_note(e: BosError, customer_id: &str, info: &Value) -> BosError {
|
|
|
|
|
+ let name = info
|
|
|
|
|
+ .get("customer_name")
|
|
|
|
|
+ .and_then(Value::as_str)
|
|
|
|
|
+ .unwrap_or(customer_id);
|
|
|
|
|
+ let note = format!(
|
|
|
|
|
+ "(客户 {customer_id}「{name}」已按合同录入建档,本次仅合同未写入。\
|
|
|
|
|
+ 修正后重新保存时请改用 customer_id 引用该客户,不再提交 customer_inline)"
|
|
|
|
|
+ );
|
|
|
|
|
+ match e {
|
|
|
|
|
+ BosError::Biz {
|
|
|
|
|
+ code,
|
|
|
|
|
+ error_code,
|
|
|
|
|
+ message,
|
|
|
|
|
+ } => BosError::Biz {
|
|
|
|
|
+ code,
|
|
|
|
|
+ error_code,
|
|
|
|
|
+ message: format!("{message}{note}"),
|
|
|
|
|
+ },
|
|
|
|
|
+ other => BosError::internal(format!("{other}{note}")),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async fn do_create_for_customer(
|
|
|
|
|
+ state: &AppState,
|
|
|
|
|
+ auth: &AuthContext,
|
|
|
|
|
+ b: &ContractCreateReq,
|
|
|
|
|
+ customer_id: &str,
|
|
|
) -> Result<Value, BosError> {
|
|
) -> Result<Value, BosError> {
|
|
|
let db = state.db.as_ref();
|
|
let db = state.db.as_ref();
|
|
|
- let customer_id = required_text(&b.customer_id, "customer_id")?;
|
|
|
|
|
- // 客户不在可见/可代录范围=`KLT-L211`(⛔ bad_params:前端靠在册码分「客户选错」与「报文不对」)。
|
|
|
|
|
- ensure_customer_visible(state, auth, customer_id).await?;
|
|
|
|
|
|
|
|
|
|
let raw_items = b.service_items.as_deref().unwrap_or_default();
|
|
let raw_items = b.service_items.as_deref().unwrap_or_default();
|
|
|
let raw_ips = b.ip_entries.as_deref().unwrap_or_default();
|
|
let raw_ips = b.ip_entries.as_deref().unwrap_or_default();
|
|
@@ -1930,6 +2218,8 @@ async fn do_create(
|
|
|
|
|
|
|
|
// ② 服务构成:空=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?;
|
|
|
|
|
+ // 固定 IP 条目的出口只能取自本合同服务构成已选出口(2026-11-16 裁定)。
|
|
|
|
|
+ check_ip_exits_in_items(&ips, items.iter().map(|item| Some(&item.line_exits)))?;
|
|
|
|
|
|
|
|
// ③ 主档字段:金额 >0、账期枚举、起 < 止、经办人三件套、附件 ≤1 ⇒ 11103 口径。
|
|
// ③ 主档字段:金额 >0、账期枚举、起 < 止、经办人三件套、附件 ≤1 ⇒ 11103 口径。
|
|
|
// 判据=`bos-invariant::validate_contract_payload`(与第 1 册录入表单同一份真源)。
|
|
// 判据=`bos-invariant::validate_contract_payload`(与第 1 册录入表单同一份真源)。
|
|
@@ -2013,7 +2303,7 @@ async fn do_create(
|
|
|
let id = it
|
|
let id = it
|
|
|
.item_id
|
|
.item_id
|
|
|
.as_deref()
|
|
.as_deref()
|
|
|
- .ok_or_else(|| BosError::internal("服务构成条目未发号(⛔ 落库)"))?;
|
|
|
|
|
|
|
+ .ok_or_else(|| BosError::internal("服务构成条目未发号(不落库)"))?;
|
|
|
stmts.push(DmlStatement::new(ITEM_INSERT_FULL, item_params(&contract_id, id, it)));
|
|
stmts.push(DmlStatement::new(ITEM_INSERT_FULL, item_params(&contract_id, id, it)));
|
|
|
}
|
|
}
|
|
|
stmts.extend(plans);
|
|
stmts.extend(plans);
|
|
@@ -2032,7 +2322,7 @@ async fn do_create(
|
|
|
v["contract_no_generated"] = json!(no.generated);
|
|
v["contract_no_generated"] = json!(no.generated);
|
|
|
v["contract_no_next_seq"] = json!(no.next_seq);
|
|
v["contract_no_next_seq"] = json!(no.next_seq);
|
|
|
v["contract_no_seq_note"] =
|
|
v["contract_no_seq_note"] =
|
|
|
- json!("发号序号按该客户既有合同数推导(dev ⛔ contract_no_seq 表 ⇒ next_seq 未持久化)");
|
|
|
|
|
|
|
+ json!("发号序号按该客户既有合同数推导(dev 不contract_no_seq 表 ⇒ next_seq 未持久化)");
|
|
|
v["has_fixed_ip"] = json!(need);
|
|
v["has_fixed_ip"] = json!(need);
|
|
|
v["derived_plans"] = json!(derived_acts.iter().map(DerivedPlan::json).collect::<Vec<_>>());
|
|
v["derived_plans"] = json!(derived_acts.iter().map(DerivedPlan::json).collect::<Vec<_>>());
|
|
|
// 新建合同⛔ 可能有订阅回填 ⇒ 恒未开通;`opened_state` 仍回 `unconfigured`(工单侧未接线)。
|
|
// 新建合同⛔ 可能有订阅回填 ⇒ 恒未开通;`opened_state` 仍回 `unconfigured`(工单侧未接线)。
|
|
@@ -2140,7 +2430,7 @@ async fn do_update(
|
|
|
return Err(BosError::klt(
|
|
return Err(BosError::klt(
|
|
|
KltCode::L214,
|
|
KltCode::L214,
|
|
|
format!(
|
|
format!(
|
|
|
- "签约客户建后⛔ 可改(库里={},请求={v})(KLT-L214)",
|
|
|
|
|
|
|
+ "签约客户建后不可改(库里={},请求={v})(KLT-L214)",
|
|
|
cur.customer_id
|
|
cur.customer_id
|
|
|
),
|
|
),
|
|
|
));
|
|
));
|
|
@@ -2150,7 +2440,7 @@ async fn do_update(
|
|
|
if let Some(v) = trimmed(&b.contract_no) {
|
|
if let Some(v) = trimmed(&b.contract_no) {
|
|
|
if v != cur.contract_no {
|
|
if v != cur.contract_no {
|
|
|
return Err(BosError::bad_params(format!(
|
|
return Err(BosError::bad_params(format!(
|
|
|
- "contract_no 建后⛔ 可改(11103):库里={},请求={v}",
|
|
|
|
|
|
|
+ "contract_no 建后不可改(11103):库里={},请求={v}",
|
|
|
cur.contract_no
|
|
cur.contract_no
|
|
|
)));
|
|
)));
|
|
|
}
|
|
}
|
|
@@ -2165,7 +2455,7 @@ async fn do_update(
|
|
|
return Err(BosError::klt(
|
|
return Err(BosError::klt(
|
|
|
KltCode::L221,
|
|
KltCode::L221,
|
|
|
format!(
|
|
format!(
|
|
|
- "合同经办人(录入账号)建后⛔ 可改(KLT-L221):该列由服务端在录入时按当前登录\
|
|
|
|
|
|
|
+ "合同经办人(录入账号)建后不可改(KLT-L221):该列由服务端在录入时按当前登录\
|
|
|
账号写入,页面只读展示;需变更走变更工单(合同 {contract_id})"
|
|
账号写入,页面只读展示;需变更走变更工单(合同 {contract_id})"
|
|
|
),
|
|
),
|
|
|
));
|
|
));
|
|
@@ -2288,7 +2578,7 @@ async fn do_update(
|
|
|
BosError::klt(
|
|
BosError::klt(
|
|
|
KltCode::L220,
|
|
KltCode::L220,
|
|
|
format!(
|
|
format!(
|
|
|
- "本合同来源为{},本地⛔ 修改{axis}(KLT-L220):以同步数据为准;\
|
|
|
|
|
|
|
+ "本合同来源为{},本地不修改{axis}(KLT-L220):以同步数据为准;\
|
|
|
如需更正请联系运营商侧重新同步(合同 {contract_id})",
|
|
如需更正请联系运营商侧重新同步(合同 {contract_id})",
|
|
|
contract_source_label(&cur.source)
|
|
contract_source_label(&cur.source)
|
|
|
),
|
|
),
|
|
@@ -2312,7 +2602,7 @@ async fn do_update(
|
|
|
&& b.ip_entries.is_none()
|
|
&& b.ip_entries.is_none()
|
|
|
{
|
|
{
|
|
|
return Err(BosError::bad_params(
|
|
return Err(BosError::bad_params(
|
|
|
- "has_fixed_ip=false 须同时给出 ip_entries: [](11103;勾选态⛔ 单独清空已备案条目)",
|
|
|
|
|
|
|
+ "has_fixed_ip=false 须同时给出 ip_entries: [](11103;勾选态不得单独清空已备案条目)",
|
|
|
));
|
|
));
|
|
|
}
|
|
}
|
|
|
let (ips, ip_dropped) = resolve_ips(need, raw_ips)?;
|
|
let (ips, ip_dropped) = resolve_ips(need, raw_ips)?;
|
|
@@ -2391,7 +2681,7 @@ async fn do_update(
|
|
|
}
|
|
}
|
|
|
if !unknown.is_empty() {
|
|
if !unknown.is_empty() {
|
|
|
return Err(BosError::bad_params(format!(
|
|
return Err(BosError::bad_params(format!(
|
|
|
- "service_items 里的 item_id ⛔ 属于本合同(11103;⛔ 靠改名新增):{}",
|
|
|
|
|
|
|
+ "service_items 里的 item_id 不属于本合同(11103;不靠改名新增):{}",
|
|
|
unknown.join("、")
|
|
unknown.join("、")
|
|
|
)));
|
|
)));
|
|
|
}
|
|
}
|
|
@@ -2414,7 +2704,7 @@ async fn do_update(
|
|
|
return Err(BosError::klt(
|
|
return Err(BosError::klt(
|
|
|
KltCode::L213,
|
|
KltCode::L213,
|
|
|
format!(
|
|
format!(
|
|
|
- "服务构成条目已被订阅引用,⛔ 删除(KLT-L213);先在订阅侧处理这些订阅:{}",
|
|
|
|
|
|
|
+ "服务构成条目已被订阅引用,不删除(KLT-L213);先在订阅侧处理这些订阅:{}",
|
|
|
held.join("、")
|
|
held.join("、")
|
|
|
),
|
|
),
|
|
|
));
|
|
));
|
|
@@ -2422,6 +2712,8 @@ async fn do_update(
|
|
|
|
|
|
|
|
// 判据=**整组载荷**(⛔ 只判被改的那条=放行半套服务构成)⇒ L215/L216/I112。
|
|
// 判据=**整组载荷**(⛔ 只判被改的那条=放行半套服务构成)⇒ L215/L216/I112。
|
|
|
let (mut items, dropped) = resolve_items(db, &cur.customer_id, raw_items).await?;
|
|
let (mut items, dropped) = resolve_items(db, &cur.customer_id, raw_items).await?;
|
|
|
|
|
+ // 固定 IP 条目的出口只能取自**本次生效**的服务构成已选出口(2026-11-16 裁定)。
|
|
|
|
|
+ check_ip_exits_in_items(&ips, items.iter().map(|item| Some(&item.line_exits)))?;
|
|
|
item_dropped = dropped;
|
|
item_dropped = dropped;
|
|
|
let new_ids =
|
|
let new_ids =
|
|
|
issue_ids(db, "SI", "contract_service_item", year, items.iter().filter(|i| i.item_id.is_none()).count())
|
|
issue_ids(db, "SI", "contract_service_item", year, items.iter().filter(|i| i.item_id.is_none()).count())
|
|
@@ -2436,7 +2728,7 @@ async fn do_update(
|
|
|
let id = it
|
|
let id = it
|
|
|
.item_id
|
|
.item_id
|
|
|
.clone()
|
|
.clone()
|
|
|
- .ok_or_else(|| BosError::internal("服务构成条目未发号(⛔ 落库)"))?;
|
|
|
|
|
|
|
+ .ok_or_else(|| BosError::internal("服务构成条目未发号(不落库)"))?;
|
|
|
all_ids.push(id.clone());
|
|
all_ids.push(id.clone());
|
|
|
if kind_of.contains_key(id.as_str()) {
|
|
if kind_of.contains_key(id.as_str()) {
|
|
|
upd.push(DmlStatement::new(ITEM_UPDATE, item_update_params(contract_id, &id, it)));
|
|
upd.push(DmlStatement::new(ITEM_UPDATE, item_update_params(contract_id, &id, it)));
|
|
@@ -2507,6 +2799,11 @@ async fn do_update(
|
|
|
stmts.extend(writeback);
|
|
stmts.extend(writeback);
|
|
|
stmts.extend(downgrade);
|
|
stmts.extend(downgrade);
|
|
|
stmts.extend(del);
|
|
stmts.extend(del);
|
|
|
|
|
+ } else if !ips.is_empty() {
|
|
|
|
|
+ // 本次只改 IP 条目(载荷不带服务构成)⇒ 以库内在册条目为生效出口集合,
|
|
|
|
|
+ // ⛔ 拿全量目录兜底——否则「先删条目出口、再从全量选 IP 出口」就能绕过。
|
|
|
|
|
+ let stored = stored_items(db, contract_id).await?;
|
|
|
|
|
+ check_ip_exits_in_items(&ips, stored.iter().map(|row| row.line_exits.as_ref()))?;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// IP 备案:dev `contract_ip_entry` ⛔ `item_id` ⇒ 只能整组替换(`None`=不碰、`Some([])`=清空)。
|
|
// IP 备案:dev `contract_ip_entry` ⛔ `item_id` ⇒ 只能整组替换(`None`=不碰、`Some([])`=清空)。
|
|
@@ -2573,7 +2870,7 @@ async fn do_update(
|
|
|
"external_no_changed": ext_changed,
|
|
"external_no_changed": ext_changed,
|
|
|
"linked_subscriptions": linked,
|
|
"linked_subscriptions": linked,
|
|
|
"order_no_writeback_note": ext_changed.then(||
|
|
"order_no_writeback_note": ext_changed.then(||
|
|
|
- "改了外部单号 ⇒ 关联订阅的 order_no ⛔ 回写(订阅侧 order_no 录入即冻结)"
|
|
|
|
|
|
|
+ "改了外部单号 ⇒ 关联订阅的 order_no 不回写(订阅侧 order_no 录入即冻结)"
|
|
|
),
|
|
),
|
|
|
});
|
|
});
|
|
|
stmts.push(audit_statement(&AuditEvent {
|
|
stmts.push(audit_statement(&AuditEvent {
|
|
@@ -2633,7 +2930,7 @@ async fn do_update(
|
|
|
v["plans_downgraded"] = json!(downgraded);
|
|
v["plans_downgraded"] = json!(downgraded);
|
|
|
v["ip_entries_replaced"] = json!(replace_ips);
|
|
v["ip_entries_replaced"] = json!(replace_ips);
|
|
|
v["ip_entries_note"] = json!(
|
|
v["ip_entries_note"] = json!(
|
|
|
- "dev contract_ip_entry ⛔ item_id ⇒ ip_entries 仍整组替换(⛔ 按条目三向对比)"
|
|
|
|
|
|
|
+ "dev contract_ip_entry 不item_id ⇒ ip_entries 仍整组替换(不按条目三向对比)"
|
|
|
);
|
|
);
|
|
|
// 审计已随业务语句同批提交 ⇒ 走到这里必已落库(失败的话上面整批回滚并报错)。
|
|
// 审计已随业务语句同批提交 ⇒ 走到这里必已落库(失败的话上面整批回滚并报错)。
|
|
|
v["audit_written"] = json!(true);
|
|
v["audit_written"] = json!(true);
|
|
@@ -3114,6 +3411,11 @@ pub async fn get_list(
|
|
|
Some(d) => json!(d),
|
|
Some(d) => json!(d),
|
|
|
None => Value::Null,
|
|
None => Value::Null,
|
|
|
};
|
|
};
|
|
|
|
|
+ // 附件形态(列表页只用它决定「有附件」角标;签名只在详情读口现签,
|
|
|
|
|
+ // ⛔ 列表按行 N 次调平台)。
|
|
|
|
|
+ v["attachment_kind"] = json!(attachment_kind_of(r.attachment_url.as_deref()));
|
|
|
|
|
+ v["attachment_view_url"] = Value::Null;
|
|
|
|
|
+ v["attachment_view_url_expires_at"] = Value::Null;
|
|
|
v
|
|
v
|
|
|
})
|
|
})
|
|
|
.collect::<Vec<Value>>(),
|
|
.collect::<Vec<Value>>(),
|
|
@@ -3128,7 +3430,7 @@ pub async fn get_list(
|
|
|
},
|
|
},
|
|
|
"opened_state": json!(OPENED_STATE_UNCONFIGURED),
|
|
"opened_state": json!(OPENED_STATE_UNCONFIGURED),
|
|
|
"opened_source": "开通态=订阅实际开通日回填 ∪ 开户工单在册;一期工单只读口未接线 \
|
|
"opened_source": "开通态=订阅实际开通日回填 ∪ 开户工单在册;一期工单只读口未接线 \
|
|
|
- ⇒ opened_state=unconfigured(⛔ 当作「确认未开通」的结论)",
|
|
|
|
|
|
|
+ ⇒ opened_state=unconfigured(不当作「确认未开通」的结论)",
|
|
|
})))
|
|
})))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3179,7 +3481,7 @@ 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:详情「商业信息 · 网络开通」的实际开通日同样取关联订单回填值(多份取最早)。
|
|
// 04 册 §4.5:详情「商业信息 · 网络开通」的实际开通日同样取关联订单回填值(多份取最早)。
|
|
|
// 此前只下发 `opened` 不下发日期 ⇒ 已开通合同显示「已开通 · 待回填日期」,与下方
|
|
// 此前只下发 `opened` 不下发日期 ⇒ 已开通合同显示「已开通 · 待回填日期」,与下方
|
|
|
// 「04 关联订单」里的实际开通日自相矛盾。
|
|
// 「04 关联订单」里的实际开通日自相矛盾。
|
|
@@ -3198,11 +3500,32 @@ pub async fn get(
|
|
|
};
|
|
};
|
|
|
v["customer_profile"] = profile.clone().unwrap_or(Value::Null);
|
|
v["customer_profile"] = profile.clone().unwrap_or(Value::Null);
|
|
|
v["customer_profile_note"] = json!(match &profile {
|
|
v["customer_profile_note"] = json!(match &profile {
|
|
|
- Some(_) => "客户档案=按 customer_id 现查 customer 组装(只读关联,⛔ 冗余列);\
|
|
|
|
|
- 识别号经平台解密后脱敏下发,dev ⛔ credit_code/province 列 ⇒ 值=null",
|
|
|
|
|
|
|
+ Some(_) => "客户档案=按 customer_id 现查 customer 组装(只读关联,不冗余列);\
|
|
|
|
|
+ 识别号经平台解密后脱敏下发,dev 不credit_code/province 列 ⇒ 值=null",
|
|
|
None => "该合同挂的 customer_id 在 customer 查不到(已注销或脏引用)⇒ \
|
|
None => "该合同挂的 customer_id 在 customer 查不到(已注销或脏引用)⇒ \
|
|
|
- customer_profile=null,界面按「档案不可读」显示,⛔ 冒充「未登记」",
|
|
|
|
|
|
|
+ customer_profile=null,界面按「档案不可读」显示,不冒充「未登记」",
|
|
|
});
|
|
});
|
|
|
|
|
+ // 合同附件(2026-11-16):库里单值,两种形态——外部链接,或浏览器直传平台桶后回报的
|
|
|
|
|
+ // 对象键。对象键**只在读口现签**(签名⛔ 落库、⛔ 进日志),`attachment_url` 原值照回
|
|
|
|
|
+ // 供创建/编辑页回填,界面⛔ 把对象键当可直接打开的链接。
|
|
|
|
|
+ let kind = attachment_kind_of(r.attachment_url.as_deref());
|
|
|
|
|
+ v["attachment_kind"] = json!(kind);
|
|
|
|
|
+ v["attachment_view_url"] = Value::Null;
|
|
|
|
|
+ v["attachment_view_url_expires_at"] = Value::Null;
|
|
|
|
|
+ match kind {
|
|
|
|
|
+ "link" => v["attachment_view_url"] = v["attachment_url"].clone(),
|
|
|
|
|
+ "object" => match attachment_view_url(&state, &r.contract_id, r.attachment_url.as_deref())
|
|
|
|
|
+ .await
|
|
|
|
|
+ {
|
|
|
|
|
+ Ok(Some((url, expires_at))) => {
|
|
|
|
|
+ v["attachment_view_url"] = json!(url);
|
|
|
|
|
+ v["attachment_view_url_expires_at"] = json!(expires_at);
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(None) => {}
|
|
|
|
|
+ Err(e) => return json_err(e),
|
|
|
|
|
+ },
|
|
|
|
|
+ _ => {}
|
|
|
|
|
+ }
|
|
|
json_ok(v)
|
|
json_ok(v)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3440,7 +3763,7 @@ pub async fn customer_lookup(
|
|
|
Ok(None) => lookup_ok(
|
|
Ok(None) => lookup_ok(
|
|
|
Vec::new(),
|
|
Vec::new(),
|
|
|
"unconfigured",
|
|
"unconfigured",
|
|
|
- "主体号未命中(credit_code=customer_id 主键同义解释;dev ⛔ credit_code 列)",
|
|
|
|
|
|
|
+ "主体号未命中(credit_code=customer_id 主键同义解释;dev 不credit_code 列)",
|
|
|
),
|
|
),
|
|
|
Ok(Some(_)) => {
|
|
Ok(Some(_)) => {
|
|
|
// 存在 ⇒ 二次按可见性取明细;取不到=越权(与「不存在」分档=11104)。
|
|
// 存在 ⇒ 二次按可见性取明细;取不到=越权(与「不存在」分档=11104)。
|
|
@@ -3482,8 +3805,8 @@ pub async fn customer_lookup(
|
|
|
"identity" => {
|
|
"identity" => {
|
|
|
return json_err(BosError::klt(
|
|
return json_err(BosError::klt(
|
|
|
KltCode::S406,
|
|
KltCode::S406,
|
|
|
- "证件号检索通路未接线:dev customer.identity_no_hash ⛔ 写入点(HMAC 密钥通路未配置)\
|
|
|
|
|
- ⇒ ⛔ 回 matched:false 当作「查无此人」(KLT-S406);请改用 credit_code 或 keyword",
|
|
|
|
|
|
|
+ "证件号检索通路未接线:dev customer.identity_no_hash 无写入点(HMAC 密钥通路未配置)\
|
|
|
|
|
+ ⇒ 不回 matched:false 当作「查无此人」(KLT-S406);请改用 credit_code 或 keyword",
|
|
|
))
|
|
))
|
|
|
}
|
|
}
|
|
|
_ => {
|
|
_ => {
|
|
@@ -3511,11 +3834,11 @@ pub async fn customer_lookup(
|
|
|
Ok(rows) => {
|
|
Ok(rows) => {
|
|
|
let n = rows.len();
|
|
let n = rows.len();
|
|
|
let note = if n == 0 {
|
|
let note = if n == 0 {
|
|
|
- "名称模糊检索未命中(限当前账号可见范围,⛔ 越权客户不计数)".to_string()
|
|
|
|
|
|
|
+ "名称模糊检索未命中(限当前账号可见范围,不越权客户不计数)".to_string()
|
|
|
} else if n == 1 {
|
|
} else if n == 1 {
|
|
|
"名称唯一命中 ⇒ 可带入合同录入表单".to_string()
|
|
"名称唯一命中 ⇒ 可带入合同录入表单".to_string()
|
|
|
} else {
|
|
} else {
|
|
|
- format!("名称命中 {n} 条(本页上限 20)⇒ 需人工选定,⛔ 内联建档")
|
|
|
|
|
|
|
+ format!("名称命中 {n} 条(本页上限 20)⇒ 需人工选定,不内联建档")
|
|
|
};
|
|
};
|
|
|
lookup_ok(rows.into_iter().map(lookup_json).collect(), "unconfigured", ¬e)
|
|
lookup_ok(rows.into_iter().map(lookup_json).collect(), "unconfigured", ¬e)
|
|
|
}
|
|
}
|
|
@@ -3604,7 +3927,7 @@ pub async fn delete(
|
|
|
c,
|
|
c,
|
|
|
format!(
|
|
format!(
|
|
|
"{};【第一栏·订阅】{};【第二栏·工单】无(工单只读口未接线,\
|
|
"{};【第一栏·订阅】{};【第二栏·工单】无(工单只读口未接线,\
|
|
|
- ⛔ 不能作为中途放行的依据)",
|
|
|
|
|
|
|
+ 不能作为中途放行的依据)",
|
|
|
biz_msg(&e),
|
|
biz_msg(&e),
|
|
|
if refs.is_empty() {
|
|
if refs.is_empty() {
|
|
|
"无".to_string()
|
|
"无".to_string()
|
|
@@ -3713,8 +4036,8 @@ pub async fn delete(
|
|
|
"items_deleted": item_count,
|
|
"items_deleted": item_count,
|
|
|
"plans_downgraded_items": downgraded,
|
|
"plans_downgraded_items": downgraded,
|
|
|
"note": format!(
|
|
"note": format!(
|
|
|
- "工单侧只读口未接线({})⇒ 本结论仅覆盖订阅引用面,⛔ 作为「无阻塞」的定论;\
|
|
|
|
|
- 自定义档保留并降级为手工档(⛔ 级联删档)",
|
|
|
|
|
|
|
+ "工单侧只读口未接线({})⇒ 本结论仅覆盖订阅引用面,不作为「无阻塞」的定论;\
|
|
|
|
|
+ 自定义档保留并降级为手工档(不级联删档)",
|
|
|
blockers.note.unwrap_or_else(|| "无附加说明".to_string())
|
|
blockers.note.unwrap_or_else(|| "无附加说明".to_string())
|
|
|
),
|
|
),
|
|
|
}))
|
|
}))
|
|
@@ -3820,6 +4143,37 @@ mod tests {
|
|
|
assert!(check_ip_entries(true, &[row]).is_ok());
|
|
assert!(check_ip_entries(true, &[row]).is_ok());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ fn ip(line_exit: &str) -> IpIns {
|
|
|
|
|
+ IpIns { line_exit: line_exit.to_string(), tier: Some(5), count: 1 }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 固定IP出口必须落在服务构成已选出口内() {
|
|
|
|
|
+ let items = [json!(["美国", "日本"])];
|
|
|
|
|
+ let exits = items.iter().map(Some);
|
|
|
|
|
+ // 命中条目出口 ⇒ 过(归一化键比对:空白/大小写不敏感)。
|
|
|
|
|
+ assert!(check_ip_exits_in_items(&[ip("美国")], exits.clone()).is_ok());
|
|
|
|
|
+ assert!(check_ip_exits_in_items(&[ip(" 美 国 ")], exits.clone()).is_ok());
|
|
|
|
|
+ // 目录里配了但合同条目没选 ⇒ ⛔ 过(本判据不读目录)。
|
|
|
|
|
+ let e = check_ip_exits_in_items(&[ip("德国")], exits.clone())
|
|
|
|
|
+ .err()
|
|
|
|
|
+ .expect("未在服务构成中选过的出口必须失败");
|
|
|
|
|
+ assert!(matches!(e, BosError::Biz { code: 60004, .. }));
|
|
|
|
|
+ assert!(format!("{e}").contains("ip_entries[0].line_exit「德国」"));
|
|
|
|
|
+ // 空条目集合 ⇒ 任何出口都不过(⛔ 退化成放行)。
|
|
|
|
|
+ assert!(check_ip_exits_in_items(&[ip("美国")], std::iter::empty()).is_err());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 条目出口单元格兼容JSONB文本回传() {
|
|
|
|
|
+ // UDS 有时把 JSONB 整列回成字符串 ⇒ 必须解析后再比对,⛔ 当成「没选出口」。
|
|
|
|
|
+ let items = [Value::String(r#"["Hong Kong"]"#.to_string())];
|
|
|
|
|
+ assert!(check_ip_exits_in_items(&[ip("hong kong")], items.iter().map(Some)).is_ok());
|
|
|
|
|
+ // 单值字符串也认(不是 JSON 数组时按原文处理)。
|
|
|
|
|
+ let single = [Value::String("美国".to_string())];
|
|
|
|
|
+ assert!(check_ip_exits_in_items(&[ip("美国")], single.iter().map(Some)).is_ok());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[test]
|
|
#[test]
|
|
|
fn 套餐式条目带年价属字段串味_L216() {
|
|
fn 套餐式条目带年价属字段串味_L216() {
|
|
|
let plans = HashMap::from([(
|
|
let plans = HashMap::from([(
|
|
@@ -3912,7 +4266,7 @@ mod tests {
|
|
|
let c = item_params("CT-1", "SI-000037", &custom_item(Some("SI-000037")));
|
|
let c = item_params("CT-1", "SI-000037", &custom_item(Some("SI-000037")));
|
|
|
assert_eq!(c[5], json!("3"), "账号数=业主录入值(文本绑定,NULL 才走 Value::Null)");
|
|
assert_eq!(c[5], json!("3"), "账号数=业主录入值(文本绑定,NULL 才走 Value::Null)");
|
|
|
assert_eq!(c[10], json!("120000"));
|
|
assert_eq!(c[10], json!("120000"));
|
|
|
- assert_eq!(c[11], Value::Null, "业主未填=NULL,⛔ 默认「年价/12」入库");
|
|
|
|
|
|
|
+ assert_eq!(c[11], Value::Null, "业主未填=NULL,不默认「年价/12」入库");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
@@ -3932,7 +4286,7 @@ mod tests {
|
|
|
assert_eq!(plans[0].params[5], json!(1_000_003));
|
|
assert_eq!(plans[0].params[5], json!(1_000_003));
|
|
|
assert_eq!(plans[0].params[6], json!(83_333), "1_000_003÷12=83_333.58 ⇒ 向下舍到分");
|
|
assert_eq!(plans[0].params[6], json!(83_333), "1_000_003÷12=83_333.58 ⇒ 向下舍到分");
|
|
|
assert_eq!(plans[1].params[5], json!(600_000));
|
|
assert_eq!(plans[1].params[5], json!(600_000));
|
|
|
- assert_eq!(plans[1].params[6], json!(55_555), "业主填了⇒原样投影,⛔ 被 ÷12 改写");
|
|
|
|
|
|
|
+ assert_eq!(plans[1].params[6], json!(55_555), "业主填了⇒原样投影,不被 ÷12 改写");
|
|
|
|
|
|
|
|
// 覆盖态走 `PLAN_UPDATE_DERIVED`($3=年价、$4=月结算标准),口径同上
|
|
// 覆盖态走 `PLAN_UPDATE_DERIVED`($3=年价、$4=月结算标准),口径同上
|
|
|
let existing = HashMap::from([(
|
|
let existing = HashMap::from([(
|
|
@@ -4021,4 +4375,85 @@ mod tests {
|
|
|
assert_eq!(contract_source_label("operator_sync"), "运营商同步");
|
|
assert_eq!(contract_source_label("operator_sync"), "运营商同步");
|
|
|
assert_eq!(contract_source_label("db_direct"), "db_direct");
|
|
assert_eq!(contract_source_label("db_direct"), "db_direct");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // ══════════ 合同内联建档(CU-13/CU-41):入参装配与必填集 ══════════
|
|
|
|
|
+
|
|
|
|
|
+ fn inline_raw() -> CustomerInlineReq {
|
|
|
|
|
+ CustomerInlineReq {
|
|
|
|
|
+ customer_name: Some("张江芯创二期".to_string()),
|
|
|
|
|
+ subject_type: Some("enterprise".to_string()),
|
|
|
|
|
+ id_code: Some("91310000MA1FL7XX9K".to_string()),
|
|
|
|
|
+ contact_name: Some("王工".to_string()),
|
|
|
|
|
+ contact_mobile: Some("13800001116".to_string()),
|
|
|
|
|
+ address: Some("上海市浦东新区张江路 1 号".to_string()),
|
|
|
|
|
+ parent_node_id: Some("ND-310000".to_string()),
|
|
|
|
|
+ operator_id: Some("OP-01".to_string()),
|
|
|
|
|
+ ops_team_ids: Some(vec!["OPS-01".to_string()]),
|
|
|
|
|
+ license: None,
|
|
|
|
|
+ primary_username: None,
|
|
|
|
|
+ primary_mobile: None,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 内联建档装配成建档请求且影像可留空() {
|
|
|
|
|
+ let body = inline_customer_body(&inline_raw()).expect("必填齐全须放行");
|
|
|
|
|
+ assert_eq!(body.customer_name, "张江芯创二期");
|
|
|
|
|
+ assert_eq!(body.subject_type, "enterprise");
|
|
|
|
|
+ assert_eq!(body.operator_id, "OP-01");
|
|
|
|
|
+ assert_eq!(body.parent_node_id.as_deref(), Some("ND-310000"));
|
|
|
|
|
+ assert_eq!(body.ops_team_ids.as_deref(), Some(&["OPS-01".to_string()][..]));
|
|
|
|
|
+ assert!(body.mount_request_id.is_none(), "内联建档不走外部挂载申请号");
|
|
|
|
|
+ assert!(body.partner_id.is_none(), "CU-13:合伙人为空");
|
|
|
|
|
+ // 企业落库时由通道放开影像必填(见 customer::CreateChannel),本函数⛔ 自行造值。
|
|
|
|
|
+ assert!(body.license.is_none());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 内联建档缺识别号必须拒绝并点明幂等键() {
|
|
|
|
|
+ let mut raw = inline_raw();
|
|
|
|
|
+ raw.id_code = Some(" ".to_string());
|
|
|
|
|
+ let e = inline_customer_body(&raw).unwrap_err();
|
|
|
|
|
+ let m = biz_msg(&e);
|
|
|
|
|
+ assert!(m.contains("客户识别号"), "{m}");
|
|
|
|
|
+ assert!(m.contains("幂等键"), "须说明为何必填:{m}");
|
|
|
|
|
+ assert!(m.contains("11103"), "{m}");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 内联建档缺团队与区域分别拒绝() {
|
|
|
|
|
+ let mut raw = inline_raw();
|
|
|
|
|
+ raw.ops_team_ids = Some(vec![]);
|
|
|
|
|
+ assert!(biz_msg(&inline_customer_body(&raw).unwrap_err()).contains("运维团队"));
|
|
|
|
|
+ let mut raw = inline_raw();
|
|
|
|
|
+ raw.parent_node_id = None;
|
|
|
|
|
+ assert!(biz_msg(&inline_customer_body(&raw).unwrap_err()).contains("挂载区域"));
|
|
|
|
|
+ let mut raw = inline_raw();
|
|
|
|
|
+ raw.operator_id = Some(String::new());
|
|
|
|
|
+ assert!(biz_msg(&inline_customer_body(&raw).unwrap_err()).contains("归属运营商"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 内联建档团队去空白但不去重() {
|
|
|
|
|
+ let mut raw = inline_raw();
|
|
|
|
|
+ raw.ops_team_ids = Some(vec![" OPS-01 ".to_string(), String::new()]);
|
|
|
|
|
+ let body = inline_customer_body(&raw).expect("清洗后仍有 1 支");
|
|
|
|
|
+ assert_eq!(body.ops_team_ids.as_deref(), Some(&["OPS-01".to_string()][..]));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn 合同失败文案写明客户已建档并要求改引用() {
|
|
|
|
|
+ let info = json!({ "customer_name": "张江芯创二期" });
|
|
|
|
|
+ let e = inline_failure_note(
|
|
|
|
|
+ BosError::klt(KltCode::L212, "合同编号已存在"),
|
|
|
|
|
+ "KL-2026-000058",
|
|
|
|
|
+ &info,
|
|
|
|
|
+ );
|
|
|
|
|
+ let m = biz_msg(&e);
|
|
|
|
|
+ assert_eq!(klt_of(e), Some("KLT-L212"), "原错误码须原样保留");
|
|
|
|
|
+ assert!(m.contains("KL-2026-000058"), "{m}");
|
|
|
|
|
+ assert!(m.contains("张江芯创二期"), "{m}");
|
|
|
|
|
+ assert!(m.contains("customer_id"), "{m}");
|
|
|
|
|
+ assert!(m.contains("不再提交 customer_inline"), "{m}");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|