| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033 |
- /**
- * 册 5《工单与开停交付》接口面:**逐字对齐** 31 条路由(`src/modules/ops/src/router.rs`)
- * 与后端 `json!` 出参(`src/modules/ops/src/handlers/*.rs`)。
- *
- * ⚠️ 出参标量的形态由服务端 SQL 决定:除列表/队列行的 `overdue_7d` 与详情页 head 的
- * `overdue` 是**真布尔**外,其余由 `::text` 投影出来的列一律是**字符串**(含数字、日期、
- * `true`/`false`),页面判布尔用本文件的 [`isYes`],⛔ `if (row.closed_flag)`(字符串 "false" 是 truthy)。
- *
- * ⚠️ 列表族出参统一是 `{total,page,page_size,rows[]}`(键名 `rows`);分页 **1 基**
- * (`dbx::page_norm`:`page.unwrap_or(1)`,offset=`(page-1)*size`),UI 页码直接透传。
- *
- * ⛔ 在本文件做 camelCase 转换:网关按 openapi 声明的 operation_id 放行,字段名照抄 spec。
- */
- import { get, list, post } from "./http.ts";
- /* ══════════════ 枚举(domain.rs 常量,⛔ 自造第八种类型) ══════════════ */
- export const TICKET_TYPES = [
- "open",
- "service_open",
- "expiry_stop",
- "service_stop",
- // 2026-11-17 第七类主线类型:契约内逐条替换的升降配(系统专属,⛔ 手工建单)。
- "updown",
- "fault",
- "after_sale",
- // 第八类(2026-11-17):合同到期续签的商务跟踪单,不走开停与竣工回执。
- "renewal",
- ] as const;
- export type TicketType = (typeof TICKET_TYPES)[number] | string;
- /**
- * 运维团队/成员可承接的类型=八类去掉第八类 `renewal`(与后端 `domain::MAINTENANCE_TYPES` 同源)。
- *
- * 业主 2026-11-17:「续签工单就是由运营账号受理的」→「运维不可接续签工单」。
- * 团队可分配类型、成员工单类型的勾选项一律用本常量;⛔ 用 `TICKET_TYPES`——
- * 后端 `ops_team/*` 会以「续签只由运营账号受理」拒掉整次保存。
- */
- export const MAINTENANCE_TICKET_TYPES: readonly string[] = TICKET_TYPES.filter((code) => code !== "renewal");
- /**
- * 运营账号可承接类型里**不可取消**的一枚:`renewal`(与后端 `domain::T_RENEWAL` 同源)。
- *
- * 业主 2026-11-17:「默认仅续签且不可清空,运维不可接续签工单」——续签单只由运营账号受理,
- * 故运营账号清单恒含本枚;`ent_team/member_update@v1` 对不含它的清单直接拒。
- */
- export const OPS_ACCOUNT_REQUIRED_TYPE = "renewal";
- export const TICKET_STATUSES = [
- "unassigned",
- "pending",
- "processing",
- "completed",
- "rejected",
- "settled",
- "terminated",
- ] as const;
- export type TicketStatus = (typeof TICKET_STATUSES)[number] | string;
- /** 中文名与后端 `domain::type_name` 同源(列表页由服务端下发 `ticket_type_name`,详情页只有码)。 */
- export const TICKET_TYPE_NAMES: Record<string, string> = {
- open: "开户",
- service_open: "服务开通",
- expiry_stop: "到期停机",
- service_stop: "服务停用",
- // 第七类:契约内逐条替换的升降配(系统专属)。
- updown: "升降配",
- fault: "故障报修",
- after_sale: "售后服务",
- renewal: "续签",
- };
- export const TICKET_STATUS_NAMES: Record<string, string> = {
- unassigned: "待分派",
- pending: "待处理",
- processing: "处理中",
- completed: "已完成",
- rejected: "竣工驳回",
- settled: "已闭环",
- terminated: "已作废",
- };
- export const typeLabel = (v?: string | null) => (v ? TICKET_TYPE_NAMES[v] ?? v : "-");
- export const statusLabel = (v?: string | null) => (v ? TICKET_STATUS_NAMES[v] ?? v : "-");
- /** 详情页 11 动作位(`finish()` 的 `actions`,工单§3.7.3)。 */
- export type TicketActionKey =
- | "assign"
- | "backfill"
- | "check_done"
- | "mark_done"
- | "delegate"
- | "close"
- | "defer_open_stop"
- | "defer_ticket"
- | "withdraw"
- | "generate_completion"
- | "reject_completion"
- | "confirm_receipt"
- | "open_prep_save";
- /* ══════════════ 读侧出参 ══════════════ */
- /** `POST /ticket/list@v1` 行(`list_inner` 的 `json!`,键名逐字对齐)。 */
- export type TicketListItem = {
- /** 全局序号(按当页偏移现算) */
- seq_no?: number;
- ticket_id: string;
- ticket_no: string | null;
- ticket_type: TicketType;
- title: string | null;
- customer_id: string | null;
- customer_name: string | null;
- assign_team_id: string | null;
- team_name?: string | null;
- assignee_user_id: string | null;
- assignee_name?: string | null;
- status: TicketStatus;
- /** 回填来源(manual/unicom_feedback/mixed;NULL=未回填) */
- backfill_source: string | null;
- expected_done_date: string | null;
- /** 7 日内到期/已超期(真布尔;仅队列口下发) */
- overdue_7d?: boolean;
- /**
- * 执行锁(2026-11-17,服务端业务日现算):开通类三类
- * (`open`/`service_open`/`updown`)的计划执行日=订阅**服务开始日**,未到该日
- * ⇒ `true`:工单可见可分派,但回填/核对一律被 `KLT-G20403` 拒。
- *
- * ⚠️ ⛔ 前端按 `expected_done_date - 今天` 自行推断:业务日锚在 `Asia/Shanghai`,
- * 浏览器时钟与它不同源(跨零点会打架)。
- */
- execution_locked?: boolean;
- /** 计划执行日(=服务开始日;非开通类恒 `null`),可作日期输入的 `min`。 */
- execution_not_before?: string | null;
- created_at: string | null;
- completed_at?: string | null;
- /**
- * 提交方(`customer`=客户自报/`ops`=运营代建/`system`/`unicom`)。
- *
- * ⚠️ 声明成可选是事实而非猜测:`handlers/read.rs` 的 `LIST_COLS` 投影里**没有**这一列,
- * `list_inner` 的 `json!` 也不下发 ⇒ 列表行拿到这里通常是 `undefined`。
- * 客户侧「我的工单」据此判闸门(`customerLiveTicketActions`):`undefined`=还没取过详情,
- * ⛔ 凭空当作 `customer` 给「确认完成,关闭工单」按钮(运维代建的单点了必被 `KLT-G20401` 拒)。
- * 后端哪天补上这列,前端无需改动即可直接在同一行给出按钮。
- */
- submitter_type?: string | null;
- };
- export type TicketListResult = {
- rows: TicketListItem[];
- total: number;
- page: number;
- page_size: number;
- };
- /** 可分派候选人(`pending_queue` 行内 `candidates[]`,⛔ 前端再拼一份人名单)。 */
- export type AssignCandidate = {
- user_id: string;
- username: string | null;
- display_name: string | null;
- /** 该候选人手头未完成单量(自动分派按此最少先挑) */
- pending_count: number;
- /**
- * 候选来源(2026-11-17):`ops_account`=运营主/子账号(不是运维团队成员,
- * 按「客户在其负责范围内」入池),缺省=运维团队成员。承接后的可用动作不同
- * (运营账号没有成员档案),故页面必须标出来。
- */
- source?: "member" | "ops_account";
- };
- export type PendingQueueItem = TicketListItem & {
- candidates: AssignCandidate[];
- };
- export type PendingQueueResult = {
- rows: PendingQueueItem[];
- total: number;
- page: number;
- page_size: number;
- };
- /** `GET /ticket/todo_counts@v1`:四件套计数(口径写死在 SQL,`note` 是人读口径说明)。 */
- export type TodoCounts = {
- /** 件1:开户/到期停机/服务停用/升降配 ∧ 尚未回填出开停事实 ∧ 已超期(开通类=**超过**服务开始日才计入;停机类=建单日+7 当天计入;批准延期后按新期限) */
- item_1_pending_exec_overdue: number;
- /** 件2:服务开通工单(待分派/待处理/处理中)同口径筛超期,与件1 单集互斥 */
- item_2_service_open_incomplete: number;
- /** 件4:待处置报文(未归集+待确认),⛔ 与未回填合算 */
- item_4_message_pending: number;
- note: string;
- };
- /* ── 追溯 ── */
- /**
- * `GET /ticket/trace@v1`(§3.7.3):**单票**四段一次拉齐;查无/越权同回 `11104`(⛔ 拆穿存在性)。
- * 入参四键至少给一键:`ticket_no`/`unicom_order_no`/`completion_no`/`ticket_id`。
- */
- export type TraceIn = { ticket_no?: string; unicom_order_no?: string; completion_no?: string; ticket_id?: string };
- export type TraceResult = {
- ticket: {
- ticket_id: string;
- ticket_no: string | null;
- ticket_type: TicketType;
- status: TicketStatus;
- customer_id: string | null;
- unicom_order_no: string | null;
- title: string | null;
- };
- /** 开停载体行(`::text` 字符串布尔判 `isYes`) */
- open_stop: Record<string, string | null>[];
- /** 回填头(至多一行) */
- backfill: Record<string, string | null>[];
- /** 竣工件行 */
- completion: Record<string, string | null>[];
- messages: TicketMessage[];
- };
- /* ── 报文 ── */
- /** 报文出参(`message_json`:已脱敏,⛔ 期望拿到原文)。 */
- export type TicketMessage = {
- message_id: string;
- unicom_order_no: string | null;
- reported_ticket_no: string | null;
- action: string | null;
- status: string | null;
- external_date: string | null;
- received_at: string | null;
- effective_at: string | null;
- void_reason: string | null;
- conflict_note: string | null;
- customer_name: string | null;
- identity_no: string | null;
- contact_name: string | null;
- contact_phone: string | null;
- network_account_name: string | null;
- };
- export type MessagePendingResult = {
- rows: TicketMessage[];
- total: number;
- page: number;
- page_size: number;
- };
- /* ── 详情 ── */
- export type TicketHead = {
- ticket_id: string;
- ticket_no: string;
- ticket_type: TicketType;
- status: TicketStatus;
- title: string;
- detail: string | null;
- customer_id: string | null;
- subscription_id: string | null;
- reporter_account_id: string | null;
- unicom_order_no: string | null;
- submitter_type: string | null;
- submitter_user_id: string | null;
- assign_team_id: string | null;
- assignee_user_id: string | null;
- assignee_snapshot_name: string | null;
- /** 服务端把 *_user_id 解析成的姓名回填进这三键(无匹配 ⇒ 键缺席,保留 ID 值) */
- assign_team_name?: string | null;
- creator_name?: string | null;
- delegate_from_name?: string | null;
- assignee_name?: string | null;
- delegate_from_user_id: string | null;
- delegated_at: string | null;
- expected_done_date: string | null;
- /** 执行锁(2026-11-17):开通类未到服务开始日 ⇒ `true`(写侧同口径拒绝)。 */
- execution_locked?: boolean;
- /** 计划执行日=服务开始日(非开通类恒 `null`)。 */
- execution_not_before?: string | null;
- deferred_until: string | null;
- confirm_deadline: string | null;
- source_message_id: string | null;
- close_reason: string | null;
- completed_at: string | null;
- closed_at: string | null;
- settled_at: string | null;
- creator_user_id: string | null;
- created_at: string | null;
- updated_at: string | null;
- row_version: string;
- overdue: boolean;
- };
- export type OpenStopAccount = {
- id: string;
- sub_account_id: string | null;
- before_status: string | null;
- after_status: string | null;
- effective_date: string | null;
- source: string | null;
- display_name: string | null;
- net_account: string | null;
- };
- export type OpenStop = {
- open_stop_id: string;
- customer_id: string | null;
- subscription_id: string | null;
- action: string | null;
- exec_status: string | null;
- exec_date: string | null;
- effective_account_count: string | null;
- backfill_id: string | null;
- deferred_until: string | null;
- note: string | null;
- closed_flag: string | null;
- row_version: string;
- accounts: OpenStopAccount[];
- overdue: boolean;
- };
- export type RouteRow = {
- id: string;
- sub_account_id: string | null;
- network_account_name: string | null;
- intranet_ip: string | null;
- subnet_mask: string | null;
- gateway: string | null;
- vlan: string | null;
- vni: string | null;
- src_endpoint: string | null;
- dst_endpoint: string | null;
- egress_pop: string | null;
- down_mbps: string | null;
- up_mbps: string | null;
- };
- /** PIN/CPID 库里只有密文 ⇒ 只出"有没有登记"(`"true"`/`"false"` 字符串)。 */
- export type IpRow = {
- id: string;
- row_no: string;
- egress: string | null;
- overseas_ip: string | null;
- ip_type: string | null;
- bandwidth_mbps: string | null;
- pin_registered: string | null;
- cpid_registered: string | null;
- };
- export type Backfill = {
- backfill_id: string;
- exec_conclusion: string | null;
- conclusion_note: string | null;
- actual_opened_date: string | null;
- stop_done_date: string | null;
- builder_user_id: string | null;
- evidence_text: string | null;
- source: string | null;
- ip_rule_version: string | null;
- attempt_count: string | null;
- detail_empty_flag: string | null;
- row_version: string;
- created_at: string | null;
- routes: RouteRow[];
- ips: IpRow[];
- };
- /** 开通准备资料**报数量不报明细**(数据模型§2.2):五应用类别逐项数量。 */
- export type OpenPrepApp = {
- app_id: string;
- app_category: string | null;
- qty: string | null;
- };
- /**
- * 开通准备资料(开户单的回填前置登记块)。
- *
- * ⚠️ 2026-11-17 定案:境外 IP 明细已退役——工单不预申报境外 IP,实际分配的境外 IP
- * 只在「施工回填」逐条登记(`Backfill.ips`)。物理列 `handover_id` 是历史表名。
- */
- export type OpenPrep = {
- open_prep_id: string;
- declarant_name: string | null;
- declarant_org: string | null;
- declarant_contact: string | null;
- declaration_text: string | null;
- submitted_at: string | null;
- submitter_user_id: string | null;
- row_version: string;
- apps: OpenPrepApp[];
- submitted: boolean;
- };
- export type Completion = {
- completion_id: string;
- completion_no: string | null;
- action: string | null;
- exec_conclusion: string | null;
- mode: string | null;
- pushed_at: string | null;
- pushed_by: string | null;
- receipt_at: string | null;
- /** 回执**仍有效**(`"1"`/`"0"`)=`receipt_at` 非空且晚于最近一次受控回退;回退后回执失效但 `receipt_at` 仍是历史值。 */
- receipt_valid: string | null;
- receipt_user_id: string | null;
- receipt_remark: string | null;
- ip_rule_version: string | null;
- pdf_ready: string | null;
- row_version: string;
- created_at: string | null;
- };
- /** 处理记录=append-only 纯文本留痕(数据模型§2.9):⛔ `related_id` 之类的关联列。 */
- export type ProcessLog = {
- log_id: string;
- action: string | null;
- /**
- * 操作人平台主体号。⚠️ 服务端按角色下发:台账读侧五档给原值(要拿它对齐审计流水),
- * 客户侧/合作方侧置 `null`;`"0"`=系统/定时作业主体(署名应落「系统」)。
- */
- actor_user_id: string | null;
- /** 操作人姓名(服务端按 `bos_user_binding` 现查;查无或系统主体为 `null`)。 */
- actor_name?: string | null;
- actor_role: string | null;
- note: string | null;
- at: string | null;
- };
- /** ⛔ 期望 `oss_key`:下载走 `material_grant`,服务端不外泄对象键。 */
- export type TicketMaterial = {
- material_id: string;
- kind: string | null;
- file_name: string | null;
- size_bytes: string | null;
- uploaded_by: string | null;
- uploaded_at: string | null;
- };
- export type ServiceItem = {
- item_id: string;
- seq_no: string;
- item_name: string | null;
- spec_text: string | null;
- /**
- * 升降配(`updown`)的参数对照(2026-11-17 补列):`spec_before`=原档位参数摘要、
- * `spec_after`=新档位参数摘要(回收行写「停用(截止新订阅生效前一日)」);其余类型两列为 null。
- */
- spec_before: string | null;
- spec_after: string | null;
- expect_qty: string | null;
- check_result: string | null;
- checked_at: string | null;
- checked_by: string | null;
- note: string | null;
- };
- /**
- * 竣工驳回记录(`ticket_completion_reject`,工单§5.5.3,U-115)。
- *
- * ⚠️ 出参里**没有** `external_reject_no`:设计方案§5.1 把它列为门户/合伙人⛔ 回显字段,
- * 服务端直接把它排除在 SELECT 之外,前端⛔ 指望"拿到再隐藏"。
- */
- export type CompletionReject = {
- reject_seq: string;
- channel: string;
- completion_no: string;
- primary_code: string;
- reason_codes: string;
- reason_text: string;
- pushed_at: string | null;
- rejected_at: string | null;
- };
- /** `reject@v1` 应答:`data` 平铺(工单§5.5.3)。 */
- export type CompletionRejectResult = {
- data: {
- ticket_id: string;
- ticket_no?: string;
- ticket_status: string;
- reject_seq: string;
- completion_no: string;
- primary_code: string;
- reason_codes: string[];
- completion_channel?: string;
- external_wait_seconds?: number | null;
- row_version?: number | null;
- pathway?: string;
- idempotent_replay?: boolean;
- message: string;
- };
- };
- export type TicketDetail = {
- ticket: TicketHead;
- customer: {
- customer_id: string;
- customer_name: string | null;
- customer_code: string | null;
- contact_name: string | null;
- contact_mobile: string | null;
- address: string | null;
- } | null;
- order: {
- subscription_id: string;
- customer_id: string | null;
- plan_name: string | null;
- plan_kind: string | null;
- use_category: string | null;
- sub_mode: string | null;
- line_exits: string | null;
- order_no: string | null;
- term: string | null;
- start_date: string | null;
- status: string | null;
- actual_opened_at: string | null;
- } | null;
- service_items: ServiceItem[];
- open_stop: OpenStop | null;
- backfill: Backfill | null;
- open_prep: OpenPrep | null;
- completion: Completion | null;
- /** 驳回流水(旧→新)。门户/合伙人拿到的行集与运维侧同形,只是少了对外编号列。 */
- completion_rejects?: CompletionReject[];
- /** 「外部等待中」判据(工单§4.6 第六条):由服务端判,⛔ 前端用 `length > 0` 推导。 */
- reject_pending?: boolean;
- process_logs: ProcessLog[];
- materials: TicketMaterial[];
- messages: TicketMessage[];
- /** 缺口分组名(与 `required_groups` 同词典);空集=可出竣工 */
- gaps: string[];
- required_groups: string[];
- actions: Record<TicketActionKey, boolean>;
- read_advanced: boolean;
- };
- /* ══════════════ 写侧入参/出参 ══════════════ */
- /** 建单携带的材料:只有 `oss_key`(已直传、未登记),服务端补 file_name/size。 */
- export type CreateMaterialIn = { oss_key: string };
- export type TicketCreateResult = {
- ticket_id: string;
- ticket_no: string;
- status: TicketStatus;
- assign_team_id: string | null;
- /** 抑制分支才有:命中§3.3.1 同类未完成抑制时回「已并入既有工单」+既有单信息 */
- suppressed?: boolean;
- message?: string;
- existing_ticket_no?: string;
- existing_id?: string;
- };
- export type AssignResult = {
- ticket_id: string;
- assignee_user_id: string;
- assignee_snapshot_name: string;
- status: TicketStatus;
- };
- /** 自动分派回执(create.rs dispatch_auto_inner):dispatched/skipped 是明细数组,不是计数。 */
- export type DispatchedTicket = {
- ticket_id: string;
- ticket_no: string | null;
- assignee_user_id: string;
- assignee_snapshot_name: string | null;
- };
- export type DispatchSkipped = {
- ticket_id: string;
- ticket_no?: string | null;
- /** no_candidate=无合适成员;already_taken=并发下已被他人分派 */
- reason: string;
- message?: string;
- };
- export type DispatchResult = {
- team_id: string;
- scanned: number;
- dispatched: DispatchedTicket[];
- skipped: DispatchSkipped[];
- };
- export type DelegateResult = {
- ticket_id: string;
- assignee_user_id: string;
- assignee_snapshot_name: string;
- delegate_from_user_id: string;
- delegated_at: string;
- status: TicketStatus;
- };
- export type StartResult = {
- ticket_id: string;
- advanced: boolean;
- status: TicketStatus;
- /** `advanced:false` 时后端回的原因:非责任人/已被推进/并发。 */
- reason?: "not_assignee" | "already_advanced" | "concurrent";
- advanced_at?: string;
- audit_written?: boolean;
- };
- export type BackfillInRoute = {
- sub_account_id?: string | null;
- network_account_name?: string | null;
- intranet_ip?: string | null;
- subnet_mask?: string | null;
- gateway?: string | null;
- vlan?: string | null;
- vni?: string | null;
- src_endpoint?: string | null;
- dst_endpoint?: string | null;
- egress_pop?: string | null;
- down_mbps?: number | null;
- up_mbps?: number | null;
- open_this_time: boolean;
- };
- export type BackfillInIp = {
- egress?: string | null;
- overseas_ip?: string | null;
- ip_type?: string | null;
- bandwidth_mbps?: number | null;
- pin?: string | null;
- cpid?: string | null;
- };
- export type BackfillResult = {
- ticket_id: string;
- backfill_id: string;
- exec_conclusion: string;
- route_rows: number;
- ip_rows: number;
- ip_rule_version: string;
- open_stop_id: string | null;
- effective_account_count: number;
- apply_facts: unknown;
- status: TicketStatus;
- status_advanced: boolean;
- /** 仍缺的分组名:非空 ⇒ 已保存但未达闭环口径(页面点名,⛔ 报"保存失败") */
- missing_groups: string[];
- audit_written: boolean;
- };
- export type CheckDoneResult = {
- ticket_id: string;
- all_done: boolean;
- pending_rows: number;
- missing_item_ids: string[];
- audit_written: boolean;
- };
- export type MarkDoneResult = {
- ticket_id: string;
- status: TicketStatus;
- completed_at: string;
- biz_date: string;
- audit_written: boolean;
- };
- export type OpenPrepIn = {
- declarant_name?: string | null;
- declarant_org?: string | null;
- declarant_contact?: string | null;
- declaration_text?: string | null;
- apps?: { app_category: string; qty?: number | null }[];
- };
- export type OpenPrepSaveResult = {
- ticket_id: string;
- open_prep_id: string;
- overwritten: boolean;
- app_total: number;
- row_version: number;
- };
- export type FinalizeResult = {
- ticket_id: string;
- status: TicketStatus;
- closed_at?: string;
- open_stop_closed?: boolean;
- settled_at?: string;
- defer_scope?: string;
- deferred_until?: string;
- reverted_from?: string;
- untouched?: string[];
- audit_written: boolean;
- };
- export type CompletionGenerateResult = {
- ticket_id: string;
- ticket_status: TicketStatus;
- completion_id: string;
- completion_no: string;
- action: string;
- exec_conclusion: string;
- mode: string;
- pushed_at: string;
- pushed_by: string;
- pushed_by_name: string | null;
- ip_rule_version: string;
- pdf_oss_key: string | null;
- reissued: boolean;
- receipt_valid: boolean;
- audit_written: boolean;
- next_step: string;
- };
- export type CompletionReceiptResult = {
- ticket_id: string;
- ticket_status: TicketStatus;
- completion_no: string | null;
- receipt_at: string;
- receipt_user_id: string;
- receipt_user_name: string | null;
- settled_at: string;
- completed_at: string;
- audit_written: boolean;
- next_step: string;
- };
- export type MessageActionResult = {
- message_id: string;
- status: string;
- ticket_id: string;
- audit_written: boolean;
- next_step: string;
- };
- export type MaterialGrantResult = {
- purpose: string;
- kind: string;
- ticket_id: string;
- ticket_status: TicketStatus;
- file_name: string;
- oss_key: string;
- prefix: string;
- presign_endpoint: string;
- bucket: string;
- size_limit_bytes: number;
- next_step: string;
- };
- export type MaterialAttachResult = {
- ticket_id: string;
- material_id: string;
- file_name: string;
- audit_written: boolean;
- };
- export type ClosureConfig = {
- closure_mode: string;
- closure_mode_name: string;
- row_version: string;
- updated_at: string | null;
- updated_by: string | null;
- };
- export type ClosureConfigUpdateResult = {
- closure_mode: string;
- changed: boolean;
- /** 同档提交(changed=false)时服务端不回此键 */
- from?: string;
- row_version: number;
- updated_by: string;
- audit_written: boolean;
- next_step: string;
- };
- /* ══════════════ 工具 ══════════════ */
- /** 后端 `::text` 投影出来的布尔列(`"true"`/`"false"`/`"t"`/`"f"`)。列表页的真布尔走原值。 */
- export function isYes(v: unknown): boolean {
- if (typeof v === "boolean") return v;
- const s = `${v ?? ""}`.trim().toLowerCase();
- return s === "true" || s === "t" || s === "1" || s === "yes";
- }
- /** 乐观并发两种拼写并存:`handle`/`finalize` 族=`expected_version`,`completion`/`message`/`config` 族=`expect_version`。 */
- const q = (o: Record<string, string | number | undefined | null>) =>
- Object.entries(o)
- .filter(([, v]) => v !== undefined && v !== null && `${v}` !== "")
- .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
- .join("&");
- /* ══════════════ §6.1 读侧(7) ══════════════ */
- /** 工单列表 [实]。分页 **1 基**(`page_norm`),UI 页码直接透传。 */
- export const ticketList = (d: {
- ticket_types?: string[];
- statuses?: string[];
- /** 回填来源三值:manual/unicom_feedback/mixed */
- sources?: string[];
- date_from?: string;
- date_to?: string;
- keyword?: string;
- /** 订阅(订阅)过滤:订阅详情「关联工单」按本条订阅现查(P3-D6)。 */
- subscription_id?: string;
- /** 合同过滤:合同详情「关联工单」按合同下订阅集合现查(P3-D7)。 */
- contract_id?: string;
- /** 客户过滤:客户维度的工单台账。 */
- customer_id?: string;
- /**
- * 责任人过滤:**只有 `me` 一个取值**(服务端按会话解析,⛔ 收任意 user_id)。
- * 「我的待办」靠它把可见行集收窄到本人名下——运维成员的可见性本来就是本人,
- * 运营账号/团队主/总运营则是「先按可见范围取并集再筛本人」。
- */
- assignee?: string;
- page?: number;
- page_size?: number;
- }) => list<TicketListResult>("/ticket/list@v1", d, d);
- /** 工单详情定位入参 [实] —— 二选一(都给以 `ticket_id` 为准)。
- *
- * 客户门户⛔ 在 URL 里出现内部主键,故列表只回 `ticket_no`、详情按业务工单号定位;
- * 运营侧仍走 `ticket_id`(台账/队列/待办页手上有主键)。 */
- export type TicketDetailIn = { ticket_id?: string; ticket_no?: string; read_event?: boolean };
- /** 工单详情 [实] —— GET;`read_event=true` 才推进 pending→processing(终态返 KLT-G20401)。 */
- export const ticketDetail = (d: TicketDetailIn) =>
- get<TicketDetail>(
- `/ticket/detail@v1?${q({
- ticket_id: d.ticket_id,
- ticket_no: d.ticket_no,
- read_event: d.read_event ? "true" : undefined,
- })}`,
- );
- /** 待分派队列 [实] —— 逐行带 `candidates[]`(可分派候选人+手头量)。 */
- export const ticketPendingQueue = (d?: {
- ticket_types?: string[];
- assign_team_id?: string;
- keyword?: string;
- page?: number;
- page_size?: number;
- }) => list<PendingQueueResult>("/ticket/pending_queue@v1", d, d);
- /** 六档待办计数 [实] —— 红点/徽标唯一来源。 */
- export const ticketTodoCounts = () => get<TodoCounts>("/ticket/todo_counts@v1");
- /** 全链路追溯 [实] —— GET,四键至少一键(工单号/订单号/竣工单号/ticket_id)。 */
- export const ticketTrace = (d: TraceIn) => get<TraceResult>(`/ticket/trace@v1?${q({ ...d })}`);
- /** 报文待处置清单 [实] —— 仅 `unmatched`/`conflict`。 */
- export const messagePending = (d?: { page?: number; page_size?: number; status?: string }) =>
- list<MessagePendingResult>("/message/pending@v1", d, d);
- /* ══════════════ §6.2 建单与分派(4) ══════════════ */
- /**
- * 建单 [实] —— 客户侧/运营侧同一口,`submitter_type` 由服务端按身份定。
- * `ticket_type` 收 `fault`/`after_sale`/`service_stop`(create.rs `CREATE_TYPES`,
- * 2026-11-14 起「运营人工发起服务停用」也挂本口=工单§3.2.1);`title` 必填(≤128 字)。
- * `service_stop` 必带 `subscription_id` + `confirm:true`(二次确认),服务端同批登记
- * `ticket_open_stop`(`action=stop`、`exec_status=pending`),实际停机由回填执行。
- * 客户侧 ⛔ 带 `customer_id`(由会话派生);总运营必带;材料键须先落在
- * `提交材料/{customer_id}/` 前缀下——该前缀 ⛔ 在建单前取到(`material_grant` 要 `ticket_id`),
- * 所以门户建单 ⛔ 挂 attachments 假上传,材料在建单后走 `material_grant`+`material_attach`。
- */
- export const ticketCreate = (d: {
- ticket_type: string;
- customer_id?: string;
- title: string;
- detail?: string;
- subscription_id?: string;
- /** 仅 `service_stop` 用:人工发起停用的二次确认位,⛔ 由服务端默认放行。 */
- confirm?: boolean;
- materials?: CreateMaterialIn[];
- }) => post<TicketCreateResult>("/ticket/create@v1", d);
- /** 人工分派 [实] —— 候选人来自 `pending_queue` 行内 `candidates[]`。 */
- export const ticketAssign = (d: { ticket_id: string; assignee_user_id: string }) =>
- post<AssignResult>("/ticket/assign@v1", d);
- /** 自动分派 [实] —— 按团队批量。 */
- export const ticketDispatchAuto = (d: { team_id: string }) =>
- post<DispatchResult>("/ticket/dispatch_auto@v1", d);
- /** 转交代管 [实] —— 责任人本人把单交给同事代管。 */
- export const ticketDelegate = (d: { ticket_id: string; trustee_user_id: string }) =>
- post<DelegateResult>("/ticket/delegate@v1", d);
- /* ══════════════ §6.3 处理推进与回填(5) ══════════════ */
- /** 阅读推进 [实]——由详情口 `read_event=true` 内部调用,**无人工按钮**(工单§4.1.4,2026-11-04 定案)。 */
- export const ticketStart = (d: { ticket_id: string }) => post<StartResult>("/ticket/start@v1", d);
- /** 施工回填 [实] —— 停机类只录组四五项(契约 14.2),`route_rows`/`ip_rows` 传空数组。 */
- export const ticketBackfill = (d: {
- ticket_id: string;
- exec_conclusion?: string;
- conclusion_note?: string;
- actual_opened_date?: string;
- stop_done_date?: string;
- builder_user_id?: string;
- evidence_text?: string;
- route_rows?: BackfillInRoute[];
- ip_rows?: BackfillInIp[];
- expected_version?: number;
- }) => post<BackfillResult>("/ticket/backfill@v1", d);
- /** 服务开通条目核对 [实]。 */
- export const ticketCheckDone = (d: {
- ticket_id: string;
- item_ids?: string[];
- note?: string;
- /** 实际开通日(服务开通单三件套之一;服务开通单没有回填弹窗,这一列随核对登记)。 */
- actual_opened_date?: string;
- expected_version?: number;
- }) => post<CheckDoneResult>("/ticket/check_done@v1", d);
- /** 非主线单标记完成 [实]。 */
- export const ticketMarkDone = (d: { ticket_id: string; note?: string; expected_version?: number }) =>
- post<MarkDoneResult>("/ticket/mark_done@v1", d);
- /** 开通准备资料登记 [实] —— 一次开通一份,重复保存=整体覆盖(冲突 KLT-G20417)。 */
- export const ticketOpenPrepSave = (d: { ticket_id: string; open_prep: OpenPrepIn; expected_version?: number }) =>
- post<OpenPrepSaveResult>("/ticket/open_prep_save@v1", d);
- /* ══════════════ §6.4 终态收口与受控回退(5) ══════════════ */
- /** 关闭/作废 [实]。 */
- export const ticketClose = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
- post<FinalizeResult>("/ticket/close@v1", d);
- /** 客户侧撤回并关闭 [实]。 */
- export const ticketWithdraw = (d: { ticket_id: string; reason?: string }) =>
- post<FinalizeResult>("/ticket/withdraw@v1", d);
- /** 非主线单客户侧闭环确认 [实]。 */
- export const ticketConfirmClose = (d: { ticket_id: string; expected_version?: number }) =>
- post<FinalizeResult>("/ticket/confirm_close@v1", d);
- /** 延期提醒 [实] —— 载体两档:`open_stop`(开停记录)/`ticket`(工单本身);期限由服务端按超期天数推进。 */
- export const ticketDefer = (d: { ticket_id: string; defer_scope?: "open_stop" | "ticket" }) =>
- post<FinalizeResult>("/ticket/defer@v1", d);
- /** 受控回退(仅总运营) [实]。 */
- export const ticketRevert = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
- post<FinalizeResult>("/ticket/revert@v1", d);
- /* ══════════════ §6.5 竣工回传与回执(2) ══════════════ */
- /** 生成并回传竣工 [实] —— 缺口未清 ⇒ 服务端硬拦。 */
- export const completionGenerate = (d: { ticket_id: string }) =>
- post<CompletionGenerateResult>("/completion/generate@v1", d);
- /** 回执确认闭环 [实] —— 仅 admin/该团队主账号。 */
- export const completionReceipt = (d: {
- ticket_id: string;
- completion_no?: string;
- external_order_no?: string;
- receipt_remark?: string;
- expect_version?: number;
- /** 驳回态冲突纠正(设计方案§3.3):**仅 admin** 生效,非驳回态传了也⛔ 改变任何行为。 */
- override_state_conflict?: boolean;
- }) => post<CompletionReceiptResult>("/completion/receipt@v1", d);
- /**
- * 竣工驳回理由七枚(工单§5.5.3 批复④),**顺序=后端 `domain::REJECT_REASONS` 定义序**。
- *
- * ⚠️ 顺序有语义:服务端按本表下标归一化后落库,**主原因=归一化首位**(下标最小的那枚),
- * ⛔ 把"用户先点的那枚"当主原因——同一次勾选无论怎么点主原因都相同,报表「主原因分布」
- * 才不会被排列组合劈成几条(驳回抽屉的预览按这条口径回显)。
- */
- export const REJECT_REASONS: { code: string; name: string }[] = [
- { code: "doc_mismatch", name: "资料不符" },
- { code: "resource_unavailable", name: "端口或IP资源不可用" },
- { code: "duplicate", name: "重复申报" },
- { code: "out_of_scope", name: "超出受理范围" },
- { code: "doc_missing", name: "竣工资料缺失" },
- { code: "site_not_ready", name: "现场不具备条件" },
- { code: "other", name: "其他" },
- ];
- /** 一次驳回的枚数上限(`1 ≤ n ≤ 3`,超限/空选 ⇒ `KLT-G20422`)。 */
- export const REJECT_REASON_MAX = 3;
- /** 归一化主原因(本表下标最小者);未勾选回空串。 */
- export const rejectPrimaryReason = (codes: string[]) =>
- REJECT_REASONS.find((r) => codes.includes(r.code))?.name ?? "";
- /** 登记竣工驳回 [实](工单§5.5.3,U-115)——重复提交命中幂等回 `KLT-G20421`+既有 seq。 */
- export const completionReject = (d: {
- ticket_id: string;
- reason_codes: string[];
- reason_text: string;
- external_reject_no?: string;
- }) => post<CompletionRejectResult>("/completion/reject@v1", d);
- /* ══════════════ §6.6 报文人工处置(4) ══════════════ */
- /** 报文关联到工单 [实]。 */
- export const messageAttach = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
- post<MessageActionResult>("/message/attach@v1", d);
- /** 报文作废 [实] —— `void_reason` 服务端必填(缺失 ⇒ KLT-G20412),⛔ 空串提交。 */
- export const messageVoid = (d: { message_id: string; void_reason?: string; expect_version?: number }) =>
- post<MessageActionResult>("/message/void@v1", d);
- /** 冲突确认 [实] —— `as_is`=以现状为准归档(默认)/`apply_external`=按报文外部值生效。 */
- export const messageConfirmConflict = (d: {
- message_id: string;
- disposition?: "as_is" | "apply_external";
- note?: string;
- expect_version?: number;
- }) => post<MessageActionResult>("/message/confirm_conflict@v1", d);
- /** 报文改绑到另一单 [实]。 */
- export const messageRematch = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
- post<MessageActionResult>("/message/rematch@v1", d);
- /* ══════════════ §6.7 材料直传(2) ══════════════ */
- /** 申请直传凭证 [实] —— 拿 `oss_key` 后到 `presign_endpoint` 换签名直传,再 `material_attach` 登记。 */
- export const ticketMaterialGrant = (d: {
- ticket_id: string;
- kind: string;
- file_name?: string;
- purpose?: string;
- oss_key?: string;
- }) => post<MaterialGrantResult>("/ticket/material_grant@v1", d);
- /** 登记已直传材料 [实]。 */
- export const ticketMaterialAttach = (d: {
- ticket_id: string;
- kind: string;
- oss_key: string;
- file_name?: string;
- size_bytes?: number;
- }) => post<MaterialAttachResult>("/ticket/material_attach@v1", d);
- /* ══════════════ §6.8 闭环方式配置(2) ══════════════ */
- /** 读闭环方式 [实] —— 仅运营侧三类;交付侧 11104。 */
- export const ticketConfigGet = () => get<ClosureConfig>("/ticket/config_get@v1");
- /** 改闭环方式 [实] —— 仅总运营;`reason` 必填进审计。 */
- export const ticketConfigUpdate = (d: { closure_mode: string; expect_version?: number; reason?: string }) =>
- post<ClosureConfigUpdateResult>("/ticket/config_update@v1", d);
|