| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992 |
- /**
- * 册 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",
- ] as const;
- export type TicketType = (typeof TICKET_TYPES)[number] | string;
- 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: "售后服务",
- };
- 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"
- | "handover_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;
- 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;
- };
- 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;
- 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 HandoverApp = {
- app_id: string;
- app_category: string | null;
- qty: string | null;
- };
- /** 境外 IP 固定 4 行=国家+带宽档位+IP 数量(⛔ 具体 IP 段,明细在组三回填)。 */
- export type HandoverIp = {
- ip_id: string;
- row_no: string;
- country: string | null;
- bandwidth_mbps: string | null;
- ip_count: string | null;
- };
- export type Handover = {
- handover_id: string;
- declarant_name: string | null;
- declarant_org: string | null;
- declarant_contact: string | null;
- declaration_text: string | null;
- ip_rule_version: string | null;
- submitted_at: string | null;
- submitter_user_id: string | null;
- row_version: string;
- apps: HandoverApp[];
- overseas_ips: HandoverIp[];
- 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;
- handover: Handover | 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 HandoverIn = {
- declarant_name?: string | null;
- declarant_org?: string | null;
- declarant_contact?: string | null;
- declaration_text?: string | null;
- apps?: { app_category: string; qty?: number | null }[];
- ips?: { country: string; bandwidth_mbps?: number | null; ip_count?: number | null }[];
- };
- export type HandoverSaveResult = {
- ticket_id: string;
- handover_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;
- 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 ticketHandoverSave = (d: { ticket_id: string; handover: HandoverIn; expected_version?: number }) =>
- post<HandoverSaveResult>("/ticket/handover_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);
|