|
@@ -10,6 +10,8 @@
|
|
|
//! * 判据三「客户在成员解析后的负责范围内」=[`member_covers_customer`],
|
|
//! * 判据三「客户在成员解析后的负责范围内」=[`member_covers_customer`],
|
|
|
//! 几何一律复用组织册口径(Opt-8),⛔ 在本册重写区域子树。
|
|
//! 几何一律复用组织册口径(Opt-8),⛔ 在本册重写区域子树。
|
|
|
|
|
|
|
|
|
|
+use std::collections::HashMap;
|
|
|
|
|
+
|
|
|
use bos_core::{BosError, ErrorCode, KltCode};
|
|
use bos_core::{BosError, ErrorCode, KltCode};
|
|
|
use bos_platform::clients::uds::{de, UdsClient};
|
|
use bos_platform::clients::uds::{de, UdsClient};
|
|
|
use bos_scope::AuthContext;
|
|
use bos_scope::AuthContext;
|
|
@@ -48,8 +50,15 @@ pub const RECEIPT_SIDE: &[RoleKey] = &[RoleKey::Admin, RoleKey::TeamLead];
|
|
|
pub const CUSTOMER_SIDE: &[RoleKey] = &[RoleKey::Enterprise, RoleKey::Sub];
|
|
pub const CUSTOMER_SIDE: &[RoleKey] = &[RoleKey::Enterprise, RoleKey::Sub];
|
|
|
/// 运维团队成员档(`ops`):可接单的人,也是委托/标记已完成的主体。
|
|
/// 运维团队成员档(`ops`):可接单的人,也是委托/标记已完成的主体。
|
|
|
pub const MEMBER: &[RoleKey] = &[RoleKey::Ops];
|
|
pub const MEMBER: &[RoleKey] = &[RoleKey::Ops];
|
|
|
-/// 运维成员+团队主账号(交接单登记,工单§6.3 `handover_save` 表头;运营三类只读)。
|
|
|
|
|
-pub const MEMBER_OR_LEAD: &[RoleKey] = &[RoleKey::Ops, RoleKey::TeamLead];
|
|
|
|
|
|
|
+/// 登记交接单(工单§6.3 `handover_save`):运维成员+团队主账号,2026-11-17 起加**运营账号两档**
|
|
|
|
|
+/// ——运营主/子账号可以承接开户单,承接后要能登记施工交接单(没有这一档=按钮亮着点不动)。
|
|
|
|
|
+/// 真正的判权仍是 [`require_assignee`](非责任人一律拒)。
|
|
|
|
|
+pub const HANDOVER_SIDE: &[RoleKey] = &[
|
|
|
|
|
+ RoleKey::Ops,
|
|
|
|
|
+ RoleKey::TeamLead,
|
|
|
|
|
+ RoleKey::OpsMain,
|
|
|
|
|
+ RoleKey::OpsSub,
|
|
|
|
|
+];
|
|
|
/// 委托(工单§3.7.3 动作 6/用例 TK-14)。
|
|
/// 委托(工单§3.7.3 动作 6/用例 TK-14)。
|
|
|
///
|
|
///
|
|
|
/// TK-14 的出现条件是「**现任责任人本人** ∧ 处于可处理态」,主角色写的就是**运维子账号**
|
|
/// TK-14 的出现条件是「**现任责任人本人** ∧ 处于可处理态」,主角色写的就是**运维子账号**
|
|
@@ -468,6 +477,383 @@ pub async fn assignee_has_type(
|
|
|
db.query_one::<Value>(&sql, p.values()).await.map(|r| r.is_some())
|
|
db.query_one::<Value>(&sql, p.values()).await.map(|r| r.is_some())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// ── 运营账号承接工单(2026-11-17 业主口径)────────────────────────────────
|
|
|
|
|
+//
|
|
|
|
|
+// 业主口径:**运营主/子账号与运维团队主账号也应能承接工单**。团队主账号在册于
|
|
|
|
|
+// `ops_member.is_primary`,本来就落三判据;本段补的是**运营账号**——它不是任何运维团队的
|
|
|
|
|
+// 成员,没有成员档案,判据一(同团队)不适用,判据二(类型)与判据三(负责范围)照判:
|
|
|
|
|
+// * 判据二=[`ops_account_has_type`],真源 `ops_account_ticket_type`(2026-11-17 业主:
|
|
|
|
|
+// 「续签工单就是由运营账号受理的,需要补一份类型清单」)。零行=不接任何单
|
|
|
|
|
+// (与成员 `custom` 空集同口径),⛔ 把「没配清单」解释成「不限类型」;
|
|
|
|
|
+// * 判据三=[`ops_account_covers`](区域子树 ∨ 点客户清单,与成员判据三同源几何)。
|
|
|
|
|
+// 承接后回填/核对的权限前提见 [`assignee_can_execute`]。
|
|
|
|
|
+
|
|
|
|
|
+/// 运营账号的角色码(`bos_user_binding.role_code`,组织§5.4:主/子账号同批键面)。
|
|
|
|
|
+pub const OPS_ACCOUNT_ROLES: &[&str] = &["opsMain", "opsSub"];
|
|
|
|
|
+
|
|
|
|
|
+/// 运营账号档案(`bos_user_binding` 一行)。
|
|
|
|
|
+#[derive(Debug, Clone, Deserialize)]
|
|
|
|
|
+pub struct OpsAccountRow {
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ pub user_id: String,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ pub username: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ pub display_name: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ pub subject_id: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ pub role_code: Option<String>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+impl OpsAccountRow {
|
|
|
|
|
+ /// 展示名(本人自填名 → 登录名 → 账号 ID,与成员候选同一口径)。
|
|
|
|
|
+ pub fn label(&self) -> String {
|
|
|
|
|
+ self.display_name
|
|
|
|
|
+ .clone()
|
|
|
|
|
+ .filter(|s| !s.trim().is_empty())
|
|
|
|
|
+ .or_else(|| self.username.clone())
|
|
|
|
|
+ .unwrap_or_else(|| self.user_id.clone())
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 全部可用运营账号——分派候选池的「运营账号」半边。
|
|
|
|
|
+///
|
|
|
|
|
+/// 过滤:停用账号(`status='disabled'`)与录入人员(`entry_only`)不列,
|
|
|
|
|
+/// 与 `create.rs::team_candidates` 对成员的过滤同口径(派给一个登不进来的人没有意义)。
|
|
|
|
|
+pub async fn ops_accounts(db: &UdsClient) -> Result<Vec<OpsAccountRow>, BosError> {
|
|
|
|
|
+ ops_account_rows(db, None).await
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 按登录账号取运营账号档案;`Ok(None)`=不是运营账号(团队成员/客户/其它)。
|
|
|
|
|
+pub async fn ops_account_by_user(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ user_id: &str,
|
|
|
|
|
+) -> Result<Option<OpsAccountRow>, BosError> {
|
|
|
|
|
+ Ok(ops_account_rows(db, Some(user_id)).await?.into_iter().next())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async fn ops_account_rows(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ user_id: Option<&str>,
|
|
|
|
|
+) -> Result<Vec<OpsAccountRow>, BosError> {
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let roles = OPS_ACCOUNT_ROLES
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .map(|r| format!("'{r}'"))
|
|
|
|
|
+ .collect::<Vec<_>>()
|
|
|
|
|
+ .join(", ");
|
|
|
|
|
+ let mut pred = format!(
|
|
|
|
|
+ "b.entry_only IS NOT TRUE AND COALESCE(b.status, 'active') <> 'disabled' \
|
|
|
|
|
+ AND b.role_code IN ({roles})"
|
|
|
|
|
+ );
|
|
|
|
|
+ if let Some(u) = user_id.map(str::trim).filter(|s| !s.is_empty()) {
|
|
|
|
|
+ let a = p.text(u);
|
|
|
|
|
+ pred.push_str(&format!(" AND b.user_id::text = {a}::text"));
|
|
|
|
|
+ }
|
|
|
|
|
+ let sql = format!(
|
|
|
|
|
+ "SELECT b.user_id::text AS user_id, b.username, b.subject_id, b.role_code, \
|
|
|
|
|
+ COALESCE(NULLIF(TRIM(e.display_name), ''), b.username) AS display_name \
|
|
|
|
|
+ FROM bos_user_binding b LEFT JOIN bos_account_ext e ON e.user_id = b.user_id \
|
|
|
|
|
+ WHERE {pred} ORDER BY 1"
|
|
|
|
|
+ );
|
|
|
|
|
+ db.query_all::<OpsAccountRow>(&sql, p.values()).await
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 运营账号的负责范围是否覆盖该客户。
|
|
|
|
|
+///
|
|
|
|
|
+/// 几何与 [`member_covers_customer`] 的 `region` 形态同源(`dim_node_ancestor` 子树),
|
|
|
|
|
+/// 区别只有一条:运营账号的范围**不绑运维团队**(它没有 `team_id`),故不追加
|
|
|
|
|
+/// `customer_team_belong.team_id` 等值——只判「客户当期挂载点落在区域子树内 ∨ 点客户清单」。
|
|
|
|
|
+pub async fn ops_account_covers(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ acc: &OpsAccountRow,
|
|
|
|
|
+ customer_id: &str,
|
|
|
|
|
+) -> Result<bool, BosError> {
|
|
|
|
|
+ let holders = scope_holders_of_customers(db, &[customer_id.to_string()]).await?;
|
|
|
|
|
+ let subject = acc
|
|
|
|
|
+ .subject_id
|
|
|
|
|
+ .as_deref()
|
|
|
|
|
+ .map(str::trim)
|
|
|
|
|
+ .filter(|s| !s.is_empty());
|
|
|
|
|
+ Ok(holders.iter().any(|(cid, holder)| {
|
|
|
|
|
+ cid == customer_id && (holder == &acc.user_id || subject == Some(holder.as_str()))
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 运营账号的可承接工单类型清单(`ops_account_ticket_type`,判据二)。
|
|
|
|
|
+///
|
|
|
|
|
+/// **零行=不接任何单**(与成员 `custom` 空集同口径):⛔ 把「没配清单」读成「不限类型」,
|
|
|
|
|
+/// 那等于把业主这一轮补的清单又作废。存量账号由迁移 `20261117000006` 播种 `renewal`。
|
|
|
|
|
+pub async fn ops_account_types(db: &UdsClient, user_id: &str) -> Result<Vec<String>, BosError> {
|
|
|
|
|
+ let u = user_id.trim();
|
|
|
|
|
+ if u.is_empty() {
|
|
|
|
|
+ return Ok(Vec::new());
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut map = ops_account_type_map(db, &[u.to_string()]).await?;
|
|
|
|
|
+ Ok(map.remove(u).unwrap_or_default())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 一批运营账号 → 类型清单(候选池按页一次取回,⛔ 逐账号 N+1)。
|
|
|
|
|
+pub async fn ops_account_type_map(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ user_ids: &[String],
|
|
|
|
|
+) -> Result<HashMap<String, Vec<String>>, BosError> {
|
|
|
|
|
+ let mut out: HashMap<String, Vec<String>> = HashMap::new();
|
|
|
|
|
+ let ids: Vec<String> = user_ids
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .map(|s| s.trim().to_string())
|
|
|
|
|
+ .filter(|s| !s.is_empty())
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ if ids.is_empty() {
|
|
|
|
|
+ return Ok(out);
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let in_pred = push_in(&mut p, "user_id::text", &ids, "text");
|
|
|
|
|
+ let sql = format!(
|
|
|
|
|
+ "SELECT user_id::text AS user_id, ticket_type::text AS ticket_type \
|
|
|
|
|
+ FROM ops_account_ticket_type WHERE {in_pred} ORDER BY user_id, ticket_type"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ #[derive(Deserialize)]
|
|
|
|
|
+ struct Row {
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ user_id: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ ticket_type: String,
|
|
|
|
|
+ }
|
|
|
|
|
+ for r in db.query_all::<Row>(&sql, p.values()).await? {
|
|
|
|
|
+ out.entry(r.user_id).or_default().push(r.ticket_type);
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(out)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 类型清单是否放行该单类型(纯函数,表驱动单测的靶子)。
|
|
|
|
|
+///
|
|
|
|
|
+/// **空清单=不放行任何类型**(与成员 `custom` 空集同口径,⛔ 解释成「不限类型」);
|
|
|
|
|
+/// 逐字比较(`Renewal`/`renewal ` 这类脏值不算命中,与 `ops_member_ticket_type` 口径一致)。
|
|
|
|
|
+pub fn type_list_allows(types: &[String], ticket_type: &str) -> bool {
|
|
|
|
|
+ let t = ticket_type.trim();
|
|
|
|
|
+ !t.is_empty() && types.iter().any(|x| x.trim() == t)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 判据二(运营账号):类型清单是否含该单类型。
|
|
|
|
|
+pub async fn ops_account_has_type(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ user_id: &str,
|
|
|
|
|
+ ticket_type: &str,
|
|
|
|
|
+) -> Result<bool, BosError> {
|
|
|
|
|
+ let u = user_id.trim();
|
|
|
|
|
+ if u.is_empty() || ticket_type.trim().is_empty() {
|
|
|
|
|
+ return Ok(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let a = p.text(u);
|
|
|
|
|
+ let b = p.text(ticket_type.trim());
|
|
|
|
|
+ let sql = format!(
|
|
|
|
|
+ "SELECT 1 AS hit FROM ops_account_ticket_type WHERE user_id::text = {a}::text \
|
|
|
|
|
+ AND ticket_type::text = {b}::text LIMIT 1"
|
|
|
|
|
+ );
|
|
|
|
|
+ db.query_one::<Value>(&sql, p.values()).await.map(|r| r.is_some())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 一批客户 → **覆盖它们的范围持有者**(`(customer_id, holder_id)` 对)。
|
|
|
|
|
+///
|
|
|
|
|
+/// `holder_id` 是 `bos_data_scope.holder_id` 原值:运营账号既可能以 `user_id` 落行,也可能
|
|
|
|
|
+/// 以团队主体号(`ent_team_id`)落行,故两键都回,调用方按 `user_id/subject_id` 对(同
|
|
|
|
|
+/// [`has_scope_rows`] 的双键口径)。**一次查一页**:逐账号逐客户打库会把一页 100 行放大成
|
|
|
|
|
+/// 几百趟 UDS 往返(候选池要按行过滤,⛔ 每行一套几何)。
|
|
|
|
|
+pub async fn scope_holders_of_customers(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ customers: &[String],
|
|
|
|
|
+) -> Result<Vec<(String, String)>, BosError> {
|
|
|
|
|
+ if customers.is_empty() {
|
|
|
|
|
+ return Ok(Vec::new());
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let picked = push_in(&mut p, "s.target_id", customers, "text");
|
|
|
|
|
+ let mounted = push_in(&mut p, "m.customer_id", customers, "text");
|
|
|
|
|
+ // 两条 `SELECT … JOIN` 的 `UNION`(⛔ 相关 `EXISTS`:UDS 的 DataFusion 直接 13001)。
|
|
|
|
|
+ let sql = format!(
|
|
|
|
|
+ "SELECT s.target_id AS customer_id, s.holder_id AS holder_id FROM bos_data_scope s \
|
|
|
|
|
+ WHERE s.holder_type IN ('user','ent_team') AND s.target_type = 'customer' AND {picked} \
|
|
|
|
|
+ UNION \
|
|
|
|
|
+ SELECT m.customer_id AS customer_id, s2.holder_id AS holder_id FROM bos_data_scope s2 \
|
|
|
|
|
+ JOIN dim_node_ancestor a ON a.ancestor_id = s2.target_id \
|
|
|
|
|
+ JOIN customer_region_mount m ON m.parent_node_id = a.node_id \
|
|
|
|
|
+ WHERE s2.holder_type IN ('user','ent_team') AND s2.target_type = 'region' \
|
|
|
|
|
+ AND {mounted}"
|
|
|
|
|
+ );
|
|
|
|
|
+ let rows = db.query_all::<HolderRow>(&sql, p.values()).await?;
|
|
|
|
|
+ Ok(rows
|
|
|
|
|
+ .into_iter()
|
|
|
|
|
+ .map(|r| (r.customer_id, r.holder_id))
|
|
|
|
|
+ .collect())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// `(customer_id, holder_id)` 行([`scope_holders_of_customers`] 的出参形状)。
|
|
|
|
|
+#[derive(Debug, Deserialize)]
|
|
|
|
|
+struct HolderRow {
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ customer_id: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ holder_id: String,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 分派复核的失败原因(机器可读,`detail.reason` 与工单§3.4.2 的判据名一一对应)。
|
|
|
|
|
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
+pub enum AssignBlocker {
|
|
|
|
|
+ NotSameTeam,
|
|
|
|
|
+ TypeNotAllowed,
|
|
|
|
|
+ OutOfScope,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+impl AssignBlocker {
|
|
|
|
|
+ pub fn reason(self) -> &'static str {
|
|
|
|
|
+ match self {
|
|
|
|
|
+ Self::NotSameTeam => "not_same_team",
|
|
|
|
|
+ Self::TypeNotAllowed => "type_not_allowed",
|
|
|
|
|
+ Self::OutOfScope => "out_of_scope",
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 分派复核的通过项。
|
|
|
|
|
+#[derive(Debug, Clone)]
|
|
|
|
|
+pub struct Assignee {
|
|
|
|
|
+ /// 运维团队成员档案号;运营账号承接时为空(没有成员档案)。
|
|
|
|
|
+ pub member_id: Option<String>,
|
|
|
|
|
+ /// 承接人是运营账号(`opsMain`/`opsSub`)——判据一不适用,判据二查类型清单、判据三查负责范围。
|
|
|
|
|
+ pub is_ops_account: bool,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 分派复核(工单§3.4.2 的**唯一一把尺子**,`assign`/续签指派共用)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 两条通路:
|
|
|
|
|
+/// * 承接人在 `ops_member` 里 ⇒ 照旧走三判据(同团队/类型/负责范围);
|
|
|
|
|
+/// * 不在册 ⇒ 再看是不是运营账号([`ops_account_by_user`]):是则判据一不适用,
|
|
|
|
|
+/// 判据二=[`ops_account_has_type`](`ops_account_ticket_type` 清单),
|
|
|
|
|
+/// 判据三=客户在其负责范围内;不是则按判据一失败。
|
|
|
|
|
+///
|
|
|
|
|
+/// 返回 `Ok(Err(..))`=账号本身合法但判据不通过(调用方转 `KLT-G20402` + `reason`);
|
|
|
|
|
+/// `Err(..)`=取数失败。
|
|
|
|
|
+#[allow(clippy::type_complexity)]
|
|
|
|
|
+pub async fn resolve_assignee(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ user_id: &str,
|
|
|
|
|
+ ticket_type: &str,
|
|
|
|
|
+ ticket_team: Option<&str>,
|
|
|
|
|
+ customer_id: Option<&str>,
|
|
|
|
|
+) -> Result<Result<Assignee, (AssignBlocker, String)>, BosError> {
|
|
|
|
|
+ if let Some(m) = member_by_user(db, user_id).await? {
|
|
|
|
|
+ if !same_team(Some(&m.team_id), ticket_team) {
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::NotSameTeam,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "账号 {user_id} 不是团队 {} 的在册成员(工单§3.4.2 判据一)",
|
|
|
|
|
+ ticket_team.unwrap_or_default()
|
|
|
|
|
+ ),
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ if !member_has_type(db, &m.member_id, ticket_type).await? {
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::TypeNotAllowed,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "成员档案「{}」的可接类型不含本单类型「{}」(工单§3.4.2 判据二)",
|
|
|
|
|
+ m.member_id,
|
|
|
|
|
+ domain::type_name(ticket_type)
|
|
|
|
|
+ ),
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ if let Some(cust) = customer_id {
|
|
|
|
|
+ if !member_covers_customer(db, &m, cust).await? {
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::OutOfScope,
|
|
|
|
|
+ "客户不在该成员解析后的负责范围内(工单§3.4.2 判据三,区域几何走组织册)"
|
|
|
|
|
+ .to_string(),
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return Ok(Ok(Assignee {
|
|
|
|
|
+ member_id: Some(m.member_id),
|
|
|
|
|
+ is_ops_account: false,
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+ match ops_account_by_user(db, user_id).await? {
|
|
|
|
|
+ Some(acc) => {
|
|
|
|
|
+ // 判据二:运营账号自己的类型清单(`ops_account_ticket_type`)。零行=不接单,
|
|
|
|
|
+ // ⛔ 当成「不限类型」——业主 2026-11-17 补清单就是为了收口这一处。
|
|
|
|
|
+ if !ops_account_has_type(db, &acc.user_id, ticket_type).await? {
|
|
|
|
|
+ let own = ops_account_types(db, &acc.user_id).await?;
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::TypeNotAllowed,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "运营账号「{}」的可承接类型清单{}不含本单类型「{}」\
|
|
|
|
|
+ (判据二;清单在运营团队账号管理页维护)",
|
|
|
|
|
+ acc.label(),
|
|
|
|
|
+ if own.is_empty() {
|
|
|
|
|
+ "为空(=不接单,未配任何类型)".to_string()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ format!("({})", own.iter().map(|t| domain::type_name(t)).collect::<Vec<_>>().join("/"))
|
|
|
|
|
+ },
|
|
|
|
|
+ domain::type_name(ticket_type)
|
|
|
|
|
+ ),
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ let Some(cust) = customer_id.map(str::trim).filter(|s| !s.is_empty()) else {
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::OutOfScope,
|
|
|
|
|
+ "工单缺 customer_id(数据异常),无法校验运营账号的负责范围".to_string(),
|
|
|
|
|
+ )));
|
|
|
|
|
+ };
|
|
|
|
|
+ if !ops_account_covers(db, &acc, cust).await? {
|
|
|
|
|
+ return Ok(Err((
|
|
|
|
|
+ AssignBlocker::OutOfScope,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "客户 {cust} 不在运营账号「{}」的负责范围内(判据三;判据一「同团队」对运营账号不适用)",
|
|
|
|
|
+ acc.label()
|
|
|
|
|
+ ),
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(Ok(Assignee {
|
|
|
|
|
+ member_id: None,
|
|
|
|
|
+ is_ops_account: true,
|
|
|
|
|
+ }))
|
|
|
|
|
+ }
|
|
|
|
|
+ None => Ok(Err((
|
|
|
|
|
+ AssignBlocker::NotSameTeam,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "账号 {user_id} 既不是团队 {} 的在册成员,也不是运营账号(opsMain/opsSub)\
|
|
|
|
|
+ (工单§3.4.2 判据一)",
|
|
|
|
|
+ ticket_team.unwrap_or_default()
|
|
|
|
|
+ ),
|
|
|
|
|
+ ))),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 责任人能否执行本单的回填/清单核对/交接单登记。
|
|
|
|
|
+///
|
|
|
|
|
+/// * 在 `ops_member` 里 ⇒ 与 [`assignee_has_type`] 同一问(档案含本单类型);
|
|
|
|
|
+/// * 不在册 ⇒ 是运营账号即按**它自己的类型清单**判([`ops_account_has_type`])——
|
|
|
|
|
+/// 运营账号没有成员档案,判据二改查 `ops_account_ticket_type`;⛔ 再无条件放行
|
|
|
|
|
+/// (那样清单只拦分派、拦不住承接后的动作,等于没补)。
|
|
|
|
|
+pub async fn assignee_can_execute(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ assignee_user_id: Option<&str>,
|
|
|
|
|
+ ticket_type: &str,
|
|
|
|
|
+) -> Result<bool, BosError> {
|
|
|
|
|
+ let Some(u) = assignee_user_id.map(str::trim).filter(|s| !s.is_empty()) else {
|
|
|
|
|
+ return Ok(false);
|
|
|
|
|
+ };
|
|
|
|
|
+ if assignee_has_type(db, Some(u), ticket_type).await? {
|
|
|
|
|
+ return Ok(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ match ops_account_by_user(db, u).await? {
|
|
|
|
|
+ Some(acc) => ops_account_has_type(db, &acc.user_id, ticket_type).await,
|
|
|
|
|
+ None => Ok(false),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 成员档案头(判据一/三都要用它把 `user_id` 翻成 `member_id`+`scope_mode`)。
|
|
/// 成员档案头(判据一/三都要用它把 `user_id` 翻成 `member_id`+`scope_mode`)。
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
pub struct MemberRow {
|
|
pub struct MemberRow {
|
|
@@ -781,6 +1167,31 @@ pub async fn team_coverage_customer_ids(
|
|
|
mod tests {
|
|
mod tests {
|
|
|
use super::*;
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
+ /// 运营账号类型清单(2026-11-17 业主「续签工单就是由运营账号受理的,需要补一份类型清单」):
|
|
|
|
|
+ /// 空清单=不接任何单(⛔ 解释成「不限类型」);逐字命中,脏值不放行。
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn ops_account_type_list_table() {
|
|
|
|
|
+ let renewal_only = vec![domain::T_RENEWAL.to_string()];
|
|
|
|
|
+ let table: [(&[String], &str, bool); 9] = [
|
|
|
|
|
+ (&renewal_only, domain::T_RENEWAL, true),
|
|
|
|
|
+ (&renewal_only, domain::T_OPEN, false),
|
|
|
|
|
+ (&renewal_only, domain::T_FAULT, false),
|
|
|
|
|
+ (&renewal_only, "", false),
|
|
|
|
|
+ (&renewal_only, "Renewal", false),
|
|
|
|
|
+ (&renewal_only, " renewal ", true),
|
|
|
|
|
+ (&[], domain::T_RENEWAL, false),
|
|
|
|
|
+ (&[], domain::T_OPEN, false),
|
|
|
|
|
+ (&[], "", false),
|
|
|
|
|
+ ];
|
|
|
|
|
+ for (types, ttype, allowed) in table {
|
|
|
|
|
+ assert_eq!(
|
|
|
|
|
+ type_list_allows(types, ttype),
|
|
|
|
|
+ allowed,
|
|
|
|
|
+ "清单 {types:?} 对类型 {ttype:?} 的放行口径不对"
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// 建单闸门表驱动(手册 P7「运维代建」):`ops` 只放进故障/售后两类,主线四类与
|
|
/// 建单闸门表驱动(手册 P7「运维代建」):`ops` 只放进故障/售后两类,主线四类与
|
|
|
/// 表外脏值一律留在 [`CREATE_SIDE`](运维成员⛔ 借道建主线单)。
|
|
/// 表外脏值一律留在 [`CREATE_SIDE`](运维成员⛔ 借道建主线单)。
|
|
|
#[test]
|
|
#[test]
|