|
|
@@ -520,11 +520,19 @@ async fn list_inner(state: AppState, auth: AuthContext, body: ListReq) -> Result
|
|
|
fp.push(format!("t.assignee_user_id::text = {ph}::text"));
|
|
|
}
|
|
|
if let Some(v) = trim_opt(body.contract_id.as_deref()) {
|
|
|
+ // D-10:合同口径=订阅主挂 + 并单成员 + 续签来源/结果合同(renew_*),
|
|
|
+ // ⛔ 只用 `t.subscription_id IN (合同下订阅)`——续签单无订阅、并单成员不在主列会被漏。
|
|
|
+ // UDS ⛔ EXISTS 子查询 ⇒ 先把订阅/成员工单解成字面量再拼 OR。
|
|
|
#[derive(Deserialize)]
|
|
|
struct SubIdRow {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
subscription_id: String,
|
|
|
}
|
|
|
+ #[derive(Deserialize)]
|
|
|
+ struct TidRow {
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
+ ticket_id: String,
|
|
|
+ }
|
|
|
let mut q = Params::default();
|
|
|
let c = q.push(Value::String(v.to_string()));
|
|
|
let subs = state
|
|
|
@@ -538,12 +546,35 @@ async fn list_inner(state: AppState, auth: AuthContext, body: ListReq) -> Result
|
|
|
)
|
|
|
.await?;
|
|
|
let ids: Vec<String> = subs.into_iter().map(|r| r.subscription_id).collect();
|
|
|
- if ids.is_empty() {
|
|
|
- // 合同还没有订单:诚实空集,⛔ 退化成「不过滤」而把同客户别的单捞进来。
|
|
|
- fp.push("1 = 0".to_string());
|
|
|
- } else {
|
|
|
- fp.push(push_in(&mut p, "t.subscription_id::text", &ids, "text"));
|
|
|
+ let mut member_tids: Vec<String> = Vec::new();
|
|
|
+ if !ids.is_empty() {
|
|
|
+ let mut mq = Params::default();
|
|
|
+ let in_pred = push_in(&mut mq, "m.subscription_id::text", &ids, "text");
|
|
|
+ member_tids = state
|
|
|
+ .db
|
|
|
+ .query_all::<TidRow>(
|
|
|
+ &format!(
|
|
|
+ "SELECT DISTINCT m.ticket_id::text AS ticket_id \
|
|
|
+ FROM ticket_subscription m WHERE {in_pred}"
|
|
|
+ ),
|
|
|
+ mq.values(),
|
|
|
+ )
|
|
|
+ .await?
|
|
|
+ .into_iter()
|
|
|
+ .map(|r| r.ticket_id)
|
|
|
+ .collect();
|
|
|
+ }
|
|
|
+ let mut ors: Vec<String> = Vec::new();
|
|
|
+ if !ids.is_empty() {
|
|
|
+ ors.push(push_in(&mut p, "t.subscription_id::text", &ids, "text"));
|
|
|
}
|
|
|
+ if !member_tids.is_empty() {
|
|
|
+ ors.push(push_in(&mut p, "t.ticket_id::text", &member_tids, "text"));
|
|
|
+ }
|
|
|
+ let ph = p.push(Value::String(v.to_string()));
|
|
|
+ ors.push(format!("t.renew_from_contract_id = {ph}::text"));
|
|
|
+ ors.push(format!("t.renew_contract_id = {ph}::text"));
|
|
|
+ fp.push(format!("({})", ors.join(" OR ")));
|
|
|
}
|
|
|
let filter = fp.join(" AND ");
|
|
|
let outer = outer_where(&state, &auth, &mut p, &filter).await?;
|
|
|
@@ -1636,6 +1667,34 @@ pub(crate) fn sfield(v: &Value, key: &str) -> Option<String> {
|
|
|
.map(str::to_string)
|
|
|
}
|
|
|
|
|
|
+/// D-07:详情订阅带宽归一——承诺位真但上下行皆空 ⇒ 标 missing 并改写为不承诺。
|
|
|
+fn normalize_subscription_bandwidth(subscription: &mut Value) {
|
|
|
+ let Some(obj) = subscription.as_object_mut() else {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ let up = obj
|
|
|
+ .get("bandwidth_up_mbps")
|
|
|
+ .and_then(|x| x.as_str())
|
|
|
+ .map(str::trim)
|
|
|
+ .filter(|s| !s.is_empty());
|
|
|
+ let down = obj
|
|
|
+ .get("bandwidth_down_mbps")
|
|
|
+ .and_then(|x| x.as_str())
|
|
|
+ .map(str::trim)
|
|
|
+ .filter(|s| !s.is_empty());
|
|
|
+ let committed = obj
|
|
|
+ .get("bandwidth_committed")
|
|
|
+ .and_then(|x| x.as_str())
|
|
|
+ .map(|s| matches!(s.trim(), "true" | "1" | "t"))
|
|
|
+ .unwrap_or(false);
|
|
|
+ if committed && up.is_none() && down.is_none() {
|
|
|
+ obj.insert("bandwidth_committed".into(), json!("false"));
|
|
|
+ obj.insert("bandwidth_missing".into(), json!(true));
|
|
|
+ } else {
|
|
|
+ obj.insert("bandwidth_missing".into(), json!(false));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// 联系方式:像号码才按工单§5.3 遮蔽(前 3 后 4)。
|
|
|
///
|
|
|
/// 客户联系方式是自由文本(电话/分机/邮箱都可能),
|
|
|
@@ -1919,6 +1978,7 @@ async fn detail_inner(
|
|
|
.unwrap_or(Value::Null),
|
|
|
};
|
|
|
let sub_sql = "SELECT s.subscription_id::text AS subscription_id, s.customer_id, \
|
|
|
+ s.contract_id::text AS contract_id, \
|
|
|
s.plan_id, s.plan_name, s.plan_kind, s.plan_family, s.sub_mode, s.line_exits, \
|
|
|
s.order_no, s.term, s.quantity::text AS quantity, \
|
|
|
s.quota_slots::text AS quota_slots, \
|
|
|
@@ -1937,6 +1997,7 @@ async fn detail_inner(
|
|
|
.db
|
|
|
.query_one::<Value>(
|
|
|
// 施工指导需要档位带宽/席位/份数:join catalog_plan,快照列仍以订阅为准。
|
|
|
+ // D-10:投影 `contract_id`(工单表本身不存合同列,经订阅间接关联)。
|
|
|
&format!("{sub_sql} WHERE s.subscription_id = $1::text LIMIT 1"),
|
|
|
&[Value::String(s.to_string())],
|
|
|
)
|
|
|
@@ -1964,6 +2025,9 @@ async fn detail_inner(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // D-07:档位「承诺位=真但上下行皆空」是存量脏数据(迁移 20261120 口径=不承诺)。
|
|
|
+ // 须在订阅回落之后再归一,否则故障单的 fallback 订阅会漏标 `bandwidth_missing`。
|
|
|
+ normalize_subscription_bandwidth(&mut subscription);
|
|
|
/*
|
|
|
* P1(D-2/D-7):并单成员订阅(`ticket_subscription`)**平铺**出参。
|
|
|
*
|
|
|
@@ -2016,7 +2080,9 @@ async fn detail_inner(
|
|
|
.await?
|
|
|
}
|
|
|
};
|
|
|
- // D-07:停机类在尚未回填落 open_stop_account 时,回落客户在用分账号清单,告知「将停哪些」。
|
|
|
+ // D-07:停机类在尚未回填落 open_stop_account 时,回落客户分账号清单,告知「将停/已停哪些」。
|
|
|
+ // 优先 in_use(待停);若客户已全部停机(历史单/复测残留)再回落 stopped,避免空清单。
|
|
|
+ // ORDER BY 必须用投影别名(⛔ `sa.sub_account_id`)——DataFusion 会把限定列追加进投影并 13001。
|
|
|
let ticket_type_now = sfield(&head, "ticket_type").unwrap_or_default();
|
|
|
if os_accounts.is_empty()
|
|
|
&& matches!(ticket_type_now.as_str(), domain::T_EXPIRY_STOP | domain::T_SERVICE_STOP)
|
|
|
@@ -2029,7 +2095,52 @@ async fn detail_inner(
|
|
|
sa.status AS before_status, 'preview'::text AS source \
|
|
|
FROM sub_account sa \
|
|
|
WHERE sa.customer_id = $1::text AND sa.status = 'in_use' \
|
|
|
- ORDER BY sa.sub_account_id",
|
|
|
+ ORDER BY sub_account_id",
|
|
|
+ Value::String(cid.to_string()),
|
|
|
+ )
|
|
|
+ .await?;
|
|
|
+ if os_accounts.is_empty() {
|
|
|
+ os_accounts = rows_1(
|
|
|
+ state.db.as_ref(),
|
|
|
+ "SELECT sa.sub_account_id::text AS sub_account_id, sa.display_name, sa.net_account, \
|
|
|
+ sa.status AS before_status, 'preview'::text AS source \
|
|
|
+ FROM sub_account sa \
|
|
|
+ WHERE sa.customer_id = $1::text AND sa.status = 'stopped' \
|
|
|
+ ORDER BY sub_account_id",
|
|
|
+ Value::String(cid.to_string()),
|
|
|
+ )
|
|
|
+ .await?;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // D-07:开通类下发待开通分账号预览(not_opened),条数按本单套餐席位封顶——
|
|
|
+ // ⛔ 把客户名下全部未开通席一股脑倒出(同客户多合同会到上百行)。
|
|
|
+ let mut pending_accounts: Vec<Value> = Vec::new();
|
|
|
+ if matches!(
|
|
|
+ ticket_type_now.as_str(),
|
|
|
+ domain::T_OPEN | domain::T_SERVICE_OPEN | domain::T_UPDOWN
|
|
|
+ ) {
|
|
|
+ if let Some(cid) = customer_id.as_deref() {
|
|
|
+ let seat_cap = subscription
|
|
|
+ .get("quota_slots")
|
|
|
+ .and_then(|x| {
|
|
|
+ x.as_str()
|
|
|
+ .and_then(|s| s.parse::<i64>().ok())
|
|
|
+ .or_else(|| x.as_i64())
|
|
|
+ })
|
|
|
+ .filter(|&n| n > 0)
|
|
|
+ .unwrap_or(12);
|
|
|
+ // UDS 对 LIMIT 绑参偶发不稳 ⇒ 字面量封顶(席位上限与 PATH_SEAT_MAX 同量级)。
|
|
|
+ let lim = seat_cap.clamp(1, 50);
|
|
|
+ pending_accounts = rows_1(
|
|
|
+ state.db.as_ref(),
|
|
|
+ &format!(
|
|
|
+ "SELECT sa.sub_account_id::text AS sub_account_id, sa.display_name, sa.net_account, \
|
|
|
+ sa.status AS before_status, 'preview'::text AS source \
|
|
|
+ FROM sub_account sa \
|
|
|
+ WHERE sa.customer_id = $1::text AND sa.status = 'not_opened' \
|
|
|
+ ORDER BY sub_account_id LIMIT {lim}"
|
|
|
+ ),
|
|
|
Value::String(cid.to_string()),
|
|
|
)
|
|
|
.await?;
|
|
|
@@ -2072,7 +2183,8 @@ async fn detail_inner(
|
|
|
.await?;
|
|
|
let ip_binds = rows_1(
|
|
|
state.db.as_ref(),
|
|
|
- "SELECT a.backfill_ip_id::text AS backfill_ip_id, a.sub_account_id::text AS sub_account_id \
|
|
|
+ "SELECT a.id::text AS id, a.backfill_ip_id::text AS backfill_ip_id, \
|
|
|
+ a.sub_account_id::text AS sub_account_id \
|
|
|
FROM ticket_backfill_ip_account a WHERE a.ticket_id = $1::bigint ORDER BY id",
|
|
|
Value::String(id.clone()),
|
|
|
)
|
|
|
@@ -2258,6 +2370,23 @@ async fn detail_inner(
|
|
|
g.insert("subscription_missing".to_string(), json!(true));
|
|
|
g.insert("hint".to_string(), json!("无关联订阅"));
|
|
|
}
|
|
|
+ // D-07:开通类待开通席位清单(与停机 open_stop.accounts 对称)。
|
|
|
+ if !pending_accounts.is_empty() {
|
|
|
+ g.insert("pending_accounts".to_string(), json!(pending_accounts));
|
|
|
+ }
|
|
|
+ if subscription
|
|
|
+ .get("bandwidth_missing")
|
|
|
+ .and_then(|x| x.as_bool())
|
|
|
+ == Some(true)
|
|
|
+ {
|
|
|
+ g.insert("bandwidth_missing".to_string(), json!(true));
|
|
|
+ if g.get("hint").is_none() {
|
|
|
+ g.insert(
|
|
|
+ "hint".to_string(),
|
|
|
+ json!("套餐未配置上下行带宽(档位承诺位与兆数不一致),现场按合同/客户确认"),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
let backfill_draft = super::backfill_draft::load_for_detail(state.db.as_ref(), &id)
|
|
|
.await
|
|
|
@@ -2537,6 +2666,15 @@ async fn finish(
|
|
|
}
|
|
|
}
|
|
|
ticket["overdue"] = json!(overdue);
|
|
|
+ // D-10:工单表无 contract_id 列——主订阅合同投影到 ticket;续签单优先 renew_from。
|
|
|
+ if ticket.get("contract_id").and_then(|x| x.as_str()).map(str::trim).filter(|s| !s.is_empty()).is_none() {
|
|
|
+ if let Some(cid) = sfield(&p.subscription, "contract_id")
|
|
|
+ .or_else(|| sfield(&ticket, "renew_from_contract_id"))
|
|
|
+ .or_else(|| sfield(&ticket, "renew_contract_id"))
|
|
|
+ {
|
|
|
+ ticket["contract_id"] = json!(cid);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 执行锁与服务开始日(2026-11-17):前端据此显示「未到执行日」提示、把实际开通日的
|
|
|
// `min` 设成服务开始日;`execution_not_before` 对开通类恒有值(=`expected_done_date`)。
|
|
|
ticket["execution_locked"] = json!(exec_locked);
|