| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- /**
- * 册 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";
- /* ══════════════ 读侧出参 ══════════════ */
- /**
- * 「卡在别人手里」的对家与催办读数(`waiting.rs::to_json`,列表 `rows[].waiting` 与详情 `waiting` 同形)。
- *
- * * `kind`:`receipt`=等运营商回执(v1.62 起对家=**该客户所属运营商的账号**);
- * `customer`=等客户确认(对家=提交方账号)。
- * * `counterparty_user_id` 为 `null` =主体档案在但**没有可用账号**(运营商账号未创建/已停用):
- * 行内仍写「等{运营商}回执」,但前端⛔ 给催办入口(发给没人读的信箱=假成功)。
- * * `org_name`:所属主体名(运营商取所在省份、客户取客户名),行内括号用它。
- * * `urge.eligible` 是**纯时长+对家**口径(⛔ 角色权限位):`true` 只说明「现在可以催」,
- * 服务端写口还会按角色与对象再判一次。
- * * `urge.reason` 取值:`no_counterparty`/`self`/`no_completed_at`/`waiting_lt_min`/
- * `already_sent_today`(`already_sent_today` 是**幂等成功**,不是错误)。
- */
- export type TicketWaiting = {
- kind: "receipt" | "customer" | string;
- /** 服务端中文主文案(「等运营商回执」/「等客户确认」),⛔ 前端再拼一份。 */
- label: string;
- counterparty_user_id: string | null;
- counterparty_name: string | null;
- counterparty_role: string | null;
- /** 所属主体名(运营商所在地/客户名);无值时不加括号。 */
- org_name: string | null;
- since: string | null;
- hours: number | null;
- urge: {
- eligible: boolean;
- reason: string | null;
- sent_today: boolean;
- last_sent_at: string | null;
- min_hours: number;
- };
- };
- /** `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;
- /**
- * 延期后的**生效期限**(`YYYY-MM-DD`;无延期=`null`/`undefined`)。
- *
- * 服务端 `handlers/read.rs` 已按 `os.deferred_until` → `t.deferred_until` 折算后下发
- * (与 `overdue_7d` 同一优先级)。行内日期、分组与「还剩 N 天」都用它,⛔ 再用
- * `expected_done_date`——那会让延期单显示「已超 N 天」而页顶「已超期」不数它。
- */
- deferred_until?: 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;
- /**
- * 「卡在别人手里」的对家与催办读数(2026-11-18,服务端 `waiting.rs`)。
- *
- * 只在**能看台账的五档**(admin/运主/运子/团队主/`ops`)下发;客户侧与续签单、非
- * `completed` 行恒 `null`/`undefined`。对家姓名由服务端解析,⛔ 前端按类型猜
- * (主线=承接团队的团队主账号,故障/售后=提交方账号,续签没有对家)。
- */
- waiting?: TicketWaiting | 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[];
- };
- 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_account_ext.display_name` 优先、未自填回落登录名现查;查无或系统主体为 `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;
- 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;
- /** 「卡在别人手里」的对家与催办读数(非 `completed`/客户侧恒 `null`)。 */
- waiting?: TicketWaiting | null;
- };
- /* ══════════════ 写侧入参/出参 ══════════════ */
- /** 建单携带的材料:只有 `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 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;
- };
- /** 上传分支:服务端派生的对象键与前缀(直传完成后必须原样交给 `material_attach`)。 */
- export type MaterialGrantUpload = {
- purpose: "upload";
- 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 MaterialGrantDownload = {
- purpose: "download";
- material_id: string;
- kind: string;
- ticket_id: string;
- ticket_status: TicketStatus;
- file_name: string;
- download_url: string;
- expires_at: string | null;
- };
- export type MaterialGrantResult = MaterialGrantUpload | MaterialGrantDownload;
- export type MaterialAttachResult = {
- ticket_id: string;
- material_id: string;
- kind: string;
- file_name: string;
- size_bytes: string | null;
- audit_written: boolean;
- next_step: string;
- };
- 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);
- /* ══════════════ §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);
- /**
- * 站内催办 [实](2026-11-18,需求§7.5.2)——向「卡在别人手里」的对家投递一封催办信。
- *
- * 收件人/信体/业务日一律服务端取(⛔ 传 `to_user_id`:那等于开了任意发信通路)。
- * **一单一天一封**:同一业务日重复调用回 `created=false`/`reason=already_sent_today`
- * ——那是**幂等成功**,UI 按「今日已催」呈现,⛔ 报错。
- * 前置不满足(非 `completed`/未满 24 小时/对家=本人)回 `KLT-G20424`,`detail.reason`
- * 与 `waiting.urge.reason` 同词典。
- */
- export type TicketUrgeResult = {
- ticket_id: string;
- /** `true`=本轮真的投递了一封;`false`=当日已发过(幂等去重)或并发已投。 */
- created: boolean;
- reason: string | null;
- message_id?: string | null;
- business_date: string;
- counterparty?: { user_id: string; name: string; role: string; org_name: string | null };
- waiting: TicketWaiting;
- audit_written?: boolean;
- next_step: string;
- };
- export const ticketUrge = (d: { ticket_id: string }) =>
- post<TicketUrgeResult>("/ticket/urge@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?: "upload" | "download";
- material_id?: string;
- oss_key?: string;
- }) => post<MaterialGrantResult>("/ticket/material_grant@v1", d);
- /**
- * 换一条材料下载地址 [实]。
- *
- * `detail@v1` 刻意不下发对象键 ⇒ 页面只能按 `material_id` 现签;签名由服务端向平台取,
- * ⛔ 不经浏览器拼路径、⛔ 缓存地址(短时效)。
- */
- export const ticketMaterialDownload = (d: { ticket_id: string; kind: string; material_id: string }) =>
- post<MaterialGrantDownload>("/ticket/material_grant@v1", {
- ticket_id: d.ticket_id,
- kind: d.kind,
- material_id: d.material_id,
- purpose: "download",
- });
- /** 登记已直传材料 [实]。 */
- 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);
|