|
|
@@ -1,4 +1,7 @@
|
|
|
-//! 工单§6.3 处理推进与回填:`start`/`backfill`/`check_done`/`mark_done`/`open_prep_save`。
|
|
|
+//! 工单§6.3 处理推进与回填:`start`/`backfill`/`check_done`/`mark_done`。
|
|
|
+//!
|
|
|
+//! ⚠️ 原 `open_prep_save`(开通准备资料)自 2026-11-17 起整块退役:开户单不再单独登记,
|
|
|
+//! 该动作、接口与详情区块一并下线;存量 `ticket_handover`/`ticket_handover_app` 数据留库备查。
|
|
|
//!
|
|
|
//! 本文件延续§6.2 的三条纪律(条件写+条件插成对、抑制用 DB 级断言、发号在幂等判定之后),
|
|
|
//! 另加两条只在本组接口生效的口径:
|
|
|
@@ -1482,7 +1485,7 @@ pub(crate) async fn open_stop_apply(
|
|
|
Ok(plan)
|
|
|
}
|
|
|
|
|
|
-/// 覆盖式主行的两个数:稳定标识(`backfill_id`,开通准备资料为 `handover_id` 物理列)与乐观并发锚点。
|
|
|
+/// 覆盖式主行的两个数:稳定标识(`backfill_id`)与乐观并发锚点。
|
|
|
#[derive(Deserialize)]
|
|
|
struct HeadRow {
|
|
|
#[serde(default, deserialize_with = "bos_platform::clients::uds::de::as_opt_string")]
|
|
|
@@ -2123,273 +2126,6 @@ async fn mark_done_inner(state: &AppState, auth: &AuthContext, body: MarkDoneReq
|
|
|
}))
|
|
|
}
|
|
|
|
|
|
-// ══ 5. open_prep_save:开通准备资料整体覆盖 ═════════════════════════════════
|
|
|
-
|
|
|
-#[derive(Debug, Default, Deserialize)]
|
|
|
-pub struct AppIn {
|
|
|
- #[serde(default)]
|
|
|
- pub app_category: String,
|
|
|
- #[serde(default)]
|
|
|
- pub qty: Option<i64>,
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Debug, Default, Deserialize)]
|
|
|
-pub struct OpenPrepIn {
|
|
|
- #[serde(default)]
|
|
|
- pub declarant_name: Option<String>,
|
|
|
- #[serde(default)]
|
|
|
- pub declarant_org: Option<String>,
|
|
|
- #[serde(default)]
|
|
|
- pub declarant_contact: Option<String>,
|
|
|
- #[serde(default)]
|
|
|
- pub declaration_text: Option<String>,
|
|
|
- #[serde(default)]
|
|
|
- pub apps: Vec<AppIn>,
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Deserialize)]
|
|
|
-pub struct OpenPrepReq {
|
|
|
- pub ticket_id: String,
|
|
|
- pub open_prep: OpenPrepIn,
|
|
|
- #[serde(default)]
|
|
|
- pub expected_version: Option<i64>,
|
|
|
-}
|
|
|
-
|
|
|
-/// `bos.ticket/open_prep_save@v1`——TK-09:一次开通一份、重复登记=整体覆盖。
|
|
|
-///
|
|
|
-/// 登记内容=**五类应用及数量 + 声明人三要素 + 声明原文**。⚠️ 2026-11-17 定案:
|
|
|
-/// 「境外 IP(国家/带宽/条数)」不再是本区块的登记项——工单不预申报境外 IP,实际分配的
|
|
|
-/// 境外 IP 只在「施工回填」逐条登记(`ticket_backfill_ip`),合同侧也只是「档位所含 IP × 份数」。
|
|
|
-///
|
|
|
-/// ⚠️ ⛔ 静默合并(C62):整体覆盖语义下合并会造出一份谁都没填过的开通准备资料,
|
|
|
-/// 后保存者拿 `KLT-G20417` 重取最新一份再改。本区块**不阻塞任何事**(不计价、不挡回填)。
|
|
|
-pub async fn open_prep_save(
|
|
|
- State(state): State<AppState>,
|
|
|
- RequireAuth(auth): RequireAuth,
|
|
|
- DataBody(body): DataBody<OpenPrepReq>,
|
|
|
-) -> Response {
|
|
|
- match open_prep_inner(&state, &auth, body).await {
|
|
|
- Ok(v) => json_ok(v),
|
|
|
- Err(e) => e.render(),
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-async fn open_prep_inner(state: &AppState, auth: &AuthContext, body: OpenPrepReq) -> Result<Value, Fail> {
|
|
|
- let db = state.db.as_ref();
|
|
|
- let (tid, t) = ticket(db, &body.ticket_id).await?;
|
|
|
- if t.ticket_type != domain::T_OPEN {
|
|
|
- return Err(Fail::from(BosError::klt(
|
|
|
- KltCode::G20401,
|
|
|
- format!(
|
|
|
- "开通准备资料只挂在开户工单上(工单§2.5),「{}」没有这一区块",
|
|
|
- domain::type_name(&t.ticket_type)
|
|
|
- ),
|
|
|
- )));
|
|
|
- }
|
|
|
- if domain::is_terminal(&t.status) {
|
|
|
- return Err(Fail::from(BosError::klt(
|
|
|
- KltCode::G20401,
|
|
|
- format!("工单 {} 已终态,开通准备资料不覆盖(工单§3.1)", tid),
|
|
|
- )));
|
|
|
- }
|
|
|
- // 工单§6.3 `open_prep_save` 表头只放行 `ops`/`teamLead`,且**都要是责任人本人**:
|
|
|
- // 团队主账号"能看本团队"是读侧口径,登记声明人是写侧动作,⛔ 借团队身份代填别人的单。
|
|
|
- // 2026-11-17:运营账号(opsMain/opsSub)承接开户单后同样要能登记——它们不是团队成员,
|
|
|
- // 但已是该单责任人;非责任人仍被下一行 `require_assignee` 拦掉。
|
|
|
- guard::gate(auth, guard::OPEN_PREP_SIDE, "登记开通准备资料")?;
|
|
|
- guard::require_assignee(auth, &t).map_err(Fail::from)?;
|
|
|
-
|
|
|
- let h = &body.open_prep;
|
|
|
- let trim = |v: Option<&str>| v.map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
|
|
|
- let mut fields: Vec<String> = Vec::new();
|
|
|
- let name = trim(h.declarant_name.as_deref());
|
|
|
- if name.is_none() {
|
|
|
- fields.push("declarant_name".to_string());
|
|
|
- }
|
|
|
- let org = trim(h.declarant_org.as_deref());
|
|
|
- if org.is_none() {
|
|
|
- fields.push("declarant_org".to_string());
|
|
|
- }
|
|
|
- let contact = trim(h.declarant_contact.as_deref());
|
|
|
- if contact.is_none() {
|
|
|
- fields.push("declarant_contact".to_string());
|
|
|
- }
|
|
|
- let text = trim(h.declaration_text.as_deref());
|
|
|
- if text.is_none() {
|
|
|
- fields.push("declaration_text".to_string());
|
|
|
- }
|
|
|
- if !fields.is_empty() {
|
|
|
- return Err(Fail::fields(
|
|
|
- &fields,
|
|
|
- "声明人、声明单位、联系方式与声明原文逐项必填(工单§4.4/§7.2 声明页)",
|
|
|
- ));
|
|
|
- }
|
|
|
-
|
|
|
- let mut cats: Vec<String> = Vec::new();
|
|
|
- let mut sum = 0i64;
|
|
|
- for a in &h.apps {
|
|
|
- let c = a.app_category.trim();
|
|
|
- if !domain::APP_CATEGORIES.contains(&c) {
|
|
|
- return Err(Fail::fields(
|
|
|
- &["open_prep.apps".to_string(), "app_category".to_string()],
|
|
|
- format!(
|
|
|
- "应用类别「{c}」不在字典内(工单§2.5:{})",
|
|
|
- domain::APP_CATEGORIES.join("/")
|
|
|
- ),
|
|
|
- ));
|
|
|
- }
|
|
|
- if cats.iter().any(|x| x == c) {
|
|
|
- return Err(Fail::fields(
|
|
|
- &["open_prep.apps".to_string()],
|
|
|
- format!("应用类别「{c}」重复登记,数量请合并到一行"),
|
|
|
- ));
|
|
|
- }
|
|
|
- let q = a.qty.unwrap_or(0);
|
|
|
- if q <= 0 {
|
|
|
- return Err(Fail::fields(
|
|
|
- &["open_prep.apps".to_string(), "qty".to_string()],
|
|
|
- format!("「{c}」数量必须是正整数(要 0 就别登记这一类)"),
|
|
|
- ));
|
|
|
- }
|
|
|
- cats.push(c.to_string());
|
|
|
- sum += q;
|
|
|
- }
|
|
|
- // 五类全 0=这份开通准备资料什么都没声明 ⇒ KLT-G20408(跨行"或"条件,CHECK 表达不了)。
|
|
|
- if let Err(e) = domain::open_prep_validate(sum) {
|
|
|
- return Err(Fail::new(
|
|
|
- e,
|
|
|
- json!({"reason": "open_prep_all_zero", "categories": domain::APP_CATEGORIES}),
|
|
|
- ));
|
|
|
- }
|
|
|
-
|
|
|
- let cur = open_prep_head(db, &tid).await?;
|
|
|
- let covered = cur.is_some();
|
|
|
- let cur_version = cur.as_ref().map(HeadRow::version).unwrap_or(0);
|
|
|
- if let Some(v) = body.expected_version {
|
|
|
- if v != cur_version {
|
|
|
- return Err(version_fail("开通准备资料", v, cur_version));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let actor = auth.user_id.to_string();
|
|
|
- let hid = cur
|
|
|
- .as_ref()
|
|
|
- .and_then(|c| c.head_id.clone())
|
|
|
- .unwrap_or_else(|| ids::snowflake().to_string());
|
|
|
- let idn = dbx::as_num(&tid);
|
|
|
- let hidn = dbx::as_num(&hid);
|
|
|
- let mut stmts: Vec<DmlStatement> = Vec::new();
|
|
|
- // 状态守卫:子表的明细插只锚"准备资料头在不在",⛔ 挡不住"单在两次点之间被结案了"。
|
|
|
- stmts.push(guard_stmt(
|
|
|
- "status IN ('pending', 'processing')",
|
|
|
- "ticket",
|
|
|
- "ticket_id = $1::bigint",
|
|
|
- std::slice::from_ref(&idn),
|
|
|
- ));
|
|
|
- if covered {
|
|
|
- if let Some(v) = body.expected_version {
|
|
|
- stmts.push(guard_stmt(
|
|
|
- "coalesce(row_version, 0) = $1::bigint",
|
|
|
- "ticket_handover",
|
|
|
- "handover_id = $2::bigint",
|
|
|
- &[Value::from(v), hidn.clone()],
|
|
|
- ));
|
|
|
- }
|
|
|
- stmts.push(DmlStatement::new(
|
|
|
- "UPDATE ticket_handover SET declarant_name = $1::text, declarant_org = $2::text, \
|
|
|
- declarant_contact = $3::text, declaration_text = $4::text, \
|
|
|
- submitter_user_id = $5::bigint, submitted_at = now(), \
|
|
|
- row_version = coalesce(row_version, 0) + 1, updated_at = now() \
|
|
|
- WHERE handover_id = $6::bigint"
|
|
|
- .to_string(),
|
|
|
- vec![
|
|
|
- Value::String(name.clone().unwrap_or_default()),
|
|
|
- Value::String(org.clone().unwrap_or_default()),
|
|
|
- Value::String(contact.clone().unwrap_or_default()),
|
|
|
- Value::String(text.clone().unwrap_or_default()),
|
|
|
- dbx::as_num(&actor),
|
|
|
- hidn.clone(),
|
|
|
- ],
|
|
|
- ));
|
|
|
- } else {
|
|
|
- // 首发:条件插锚在 `ticket` 上,`NOT EXISTS` 挡并发下的第二张单(物理唯一键 `uq_handover_ticket`)。
|
|
|
- stmts.push(DmlStatement::new(
|
|
|
- "INSERT INTO ticket_handover (handover_id, ticket_id, declarant_name, declarant_org, \
|
|
|
- declarant_contact, declaration_text, submitted_at, submitter_user_id, \
|
|
|
- row_version, updated_at) \
|
|
|
- SELECT $1::bigint, $2::bigint, $3::text, $4::text, $5::text, $6::text, \
|
|
|
- now(), $7::bigint, 1, now() FROM ticket tt WHERE tt.ticket_id = $2::bigint \
|
|
|
- AND NOT EXISTS (SELECT 1 FROM ticket_handover hh WHERE hh.ticket_id = $2::bigint)"
|
|
|
- .to_string(),
|
|
|
- vec![
|
|
|
- hidn.clone(),
|
|
|
- idn.clone(),
|
|
|
- Value::String(name.clone().unwrap_or_default()),
|
|
|
- Value::String(org.clone().unwrap_or_default()),
|
|
|
- Value::String(contact.clone().unwrap_or_default()),
|
|
|
- Value::String(text.clone().unwrap_or_default()),
|
|
|
- dbx::as_num(&actor),
|
|
|
- ],
|
|
|
- ));
|
|
|
- }
|
|
|
- // 整体覆盖=同一批里先删子表再插(工单§4.4,⛔ 追加成第二份草稿)。
|
|
|
- // ⚠️ 子表⛔ `ticket_id` 列,删除只能按 `handover_id` 走。
|
|
|
- stmts.push(DmlStatement::new(
|
|
|
- "DELETE FROM ticket_handover_app WHERE handover_id = $1::bigint".to_string(),
|
|
|
- vec![hidn.clone()],
|
|
|
- ));
|
|
|
- // 明细的条件插锚在**准备资料头**上:头没落成就一条明细也不插(工单§6.2 纪律 3)。
|
|
|
- for a in &h.apps {
|
|
|
- stmts.push(DmlStatement::new(
|
|
|
- "INSERT INTO ticket_handover_app (id, handover_id, app_category, qty) \
|
|
|
- SELECT $1::bigint, $2::bigint, $3::varchar, $4::int FROM ticket_handover th \
|
|
|
- WHERE th.handover_id = $2::bigint"
|
|
|
- .to_string(),
|
|
|
- vec![
|
|
|
- dbx::as_num(&ids::snowflake().to_string()),
|
|
|
- hidn.clone(),
|
|
|
- Value::String(a.app_category.trim().to_string()),
|
|
|
- Value::from(a.qty.unwrap_or(0)),
|
|
|
- ],
|
|
|
- ));
|
|
|
- }
|
|
|
-
|
|
|
- dbx::batch(db, &stmts).await?;
|
|
|
- // 工单§8.1:开通准备资料**只写审计流水、⛔ 写处理记录**——台账时间线上不该出现这一跳。
|
|
|
- let audit_written = dbx::audit(
|
|
|
- db,
|
|
|
- &audit_ev(
|
|
|
- &actor,
|
|
|
- domain::AUD_OPEN_PREP,
|
|
|
- &tid,
|
|
|
- json!({"open_prep_id": hid, "app_classes": cats.len(), "app_total": sum}),
|
|
|
- ),
|
|
|
- )
|
|
|
- .await;
|
|
|
- Ok(json!({
|
|
|
- "ticket_id": tid,
|
|
|
- "open_prep_id": hid,
|
|
|
- "overwritten": covered,
|
|
|
- "app_total": sum,
|
|
|
- "row_version": cur_version + 1,
|
|
|
- "audit_written": audit_written,
|
|
|
- }))
|
|
|
-}
|
|
|
-
|
|
|
-/// 当前开通准备资料头行(存在=本次是覆盖,⛔ 另起一张草稿)。
|
|
|
-async fn open_prep_head(db: &UdsClient, tid: &str) -> Result<Option<HeadRow>, BosError> {
|
|
|
- let mut p = Params::default();
|
|
|
- let id = p.text(tid);
|
|
|
- db.query_one::<HeadRow>(
|
|
|
- &format!(
|
|
|
- "SELECT handover_id::text AS head_id, coalesce(row_version, 0)::text AS row_version \
|
|
|
- FROM ticket_handover WHERE ticket_id = {id}::bigint LIMIT 1"
|
|
|
- ),
|
|
|
- p.values(),
|
|
|
- )
|
|
|
- .await
|
|
|
-}
|
|
|
-
|
|
|
// ───────────────────────── 单元测试 ─────────────────────────
|
|
|
|
|
|
#[cfg(test)]
|