ticket.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /**
  2. * 册 5《工单与开停交付》接口面:**逐字对齐** 31 条路由(`src/modules/ops/src/router.rs`)
  3. * 与后端 `json!` 出参(`src/modules/ops/src/handlers/*.rs`)。
  4. *
  5. * ⚠️ 出参标量的形态由服务端 SQL 决定:除列表/队列行的 `overdue_7d` 与详情页 head 的
  6. * `overdue` 是**真布尔**外,其余由 `::text` 投影出来的列一律是**字符串**(含数字、日期、
  7. * `true`/`false`),页面判布尔用本文件的 [`isYes`],⛔ `if (row.closed_flag)`(字符串 "false" 是 truthy)。
  8. *
  9. * ⚠️ 列表族出参统一是 `{total,page,page_size,rows[]}`(键名 `rows`);分页 **1 基**
  10. * (`dbx::page_norm`:`page.unwrap_or(1)`,offset=`(page-1)*size`),UI 页码直接透传。
  11. *
  12. * ⛔ 在本文件做 camelCase 转换:网关按 openapi 声明的 operation_id 放行,字段名照抄 spec。
  13. */
  14. import { get, list, post } from "./http.ts";
  15. /* ══════════════ 枚举(domain.rs 常量,⛔ 自造第六种类型) ══════════════ */
  16. export const TICKET_TYPES = [
  17. "open",
  18. "service_open",
  19. "expiry_stop",
  20. "service_stop",
  21. "fault",
  22. "after_sale",
  23. ] as const;
  24. export type TicketType = (typeof TICKET_TYPES)[number] | string;
  25. export const TICKET_STATUSES = [
  26. "unassigned",
  27. "pending",
  28. "processing",
  29. "completed",
  30. "rejected",
  31. "settled",
  32. "terminated",
  33. ] as const;
  34. export type TicketStatus = (typeof TICKET_STATUSES)[number] | string;
  35. /** 中文名与后端 `domain::type_name` 同源(列表页由服务端下发 `ticket_type_name`,详情页只有码)。 */
  36. export const TICKET_TYPE_NAMES: Record<string, string> = {
  37. open: "开户",
  38. service_open: "服务开通",
  39. expiry_stop: "到期停机",
  40. service_stop: "服务停用",
  41. fault: "故障报修",
  42. after_sale: "售后服务",
  43. };
  44. export const TICKET_STATUS_NAMES: Record<string, string> = {
  45. unassigned: "待分派",
  46. pending: "待处理",
  47. processing: "处理中",
  48. completed: "已完成",
  49. rejected: "竣工驳回",
  50. settled: "已闭环",
  51. terminated: "已作废",
  52. };
  53. export const typeLabel = (v?: string | null) => (v ? TICKET_TYPE_NAMES[v] ?? v : "-");
  54. export const statusLabel = (v?: string | null) => (v ? TICKET_STATUS_NAMES[v] ?? v : "-");
  55. /** 详情页 11 动作位(`finish()` 的 `actions`,工单§3.7.3)。 */
  56. export type TicketActionKey =
  57. | "assign"
  58. | "backfill"
  59. | "check_done"
  60. | "mark_done"
  61. | "delegate"
  62. | "close"
  63. | "defer_open_stop"
  64. | "defer_ticket"
  65. | "withdraw"
  66. | "generate_completion"
  67. | "reject_completion"
  68. | "confirm_receipt"
  69. | "handover_save";
  70. /* ══════════════ 读侧出参 ══════════════ */
  71. /** `POST /ticket/list@v1` 行(`list_inner` 的 `json!`,键名逐字对齐)。 */
  72. export type TicketListItem = {
  73. /** 全局序号(按当页偏移现算) */
  74. seq_no?: number;
  75. ticket_id: string;
  76. ticket_no: string | null;
  77. ticket_type: TicketType;
  78. title: string | null;
  79. customer_id: string | null;
  80. customer_name: string | null;
  81. assign_team_id: string | null;
  82. team_name?: string | null;
  83. assignee_user_id: string | null;
  84. assignee_name?: string | null;
  85. status: TicketStatus;
  86. /** 回填来源(manual/unicom_feedback/mixed;NULL=未回填) */
  87. backfill_source: string | null;
  88. expected_done_date: string | null;
  89. /** 7 日内到期/已超期(真布尔;仅队列口下发) */
  90. overdue_7d?: boolean;
  91. created_at: string | null;
  92. completed_at?: string | null;
  93. /**
  94. * 提交方(`customer`=客户自报/`ops`=运营代建/`system`/`unicom`)。
  95. *
  96. * ⚠️ 声明成可选是事实而非猜测:`handlers/read.rs` 的 `LIST_COLS` 投影里**没有**这一列,
  97. * `list_inner` 的 `json!` 也不下发 ⇒ 列表行拿到这里通常是 `undefined`。
  98. * 客户侧「我的工单」据此判闸门(`customerLiveTicketActions`):`undefined`=还没取过详情,
  99. * ⛔ 凭空当作 `customer` 给「确认完成,关闭工单」按钮(运维代建的单点了必被 `KLT-G20401` 拒)。
  100. * 后端哪天补上这列,前端无需改动即可直接在同一行给出按钮。
  101. */
  102. submitter_type?: string | null;
  103. };
  104. export type TicketListResult = {
  105. rows: TicketListItem[];
  106. total: number;
  107. page: number;
  108. page_size: number;
  109. };
  110. /** 可分派候选人(`pending_queue` 行内 `candidates[]`,⛔ 前端再拼一份人名单)。 */
  111. export type AssignCandidate = {
  112. user_id: string;
  113. username: string | null;
  114. display_name: string | null;
  115. /** 该候选人手头未完成单量(自动分派按此最少先挑) */
  116. pending_count: number;
  117. };
  118. export type PendingQueueItem = TicketListItem & {
  119. candidates: AssignCandidate[];
  120. };
  121. export type PendingQueueResult = {
  122. rows: PendingQueueItem[];
  123. total: number;
  124. page: number;
  125. page_size: number;
  126. };
  127. /** `GET /ticket/todo_counts@v1`:四件套计数(口径写死在 SQL,`note` 是人读口径说明)。 */
  128. export type TodoCounts = {
  129. /** 件1:开户/到期停机/服务停用 ∧ 尚未回填出开停事实 ∧ 期限日(建单日+7,批准延期后按新期限)已过 */
  130. item_1_pending_exec_overdue: number;
  131. /** 件2:服务开通工单(待分派/待处理/处理中)同口径筛超期,与件1 单集互斥 */
  132. item_2_service_open_incomplete: number;
  133. /** 件4:待处置报文(未归集+待确认),⛔ 与未回填合算 */
  134. item_4_message_pending: number;
  135. note: string;
  136. };
  137. /* ── 追溯 ── */
  138. /**
  139. * `GET /ticket/trace@v1`(§3.7.3):**单票**四段一次拉齐;查无/越权同回 `11104`(⛔ 拆穿存在性)。
  140. * 入参四键至少给一键:`ticket_no`/`unicom_order_no`/`completion_no`/`ticket_id`。
  141. */
  142. export type TraceIn = { ticket_no?: string; unicom_order_no?: string; completion_no?: string; ticket_id?: string };
  143. export type TraceResult = {
  144. ticket: {
  145. ticket_id: string;
  146. ticket_no: string | null;
  147. ticket_type: TicketType;
  148. status: TicketStatus;
  149. customer_id: string | null;
  150. unicom_order_no: string | null;
  151. title: string | null;
  152. };
  153. /** 开停载体行(`::text` 字符串布尔判 `isYes`) */
  154. open_stop: Record<string, string | null>[];
  155. /** 回填头(至多一行) */
  156. backfill: Record<string, string | null>[];
  157. /** 竣工件行 */
  158. completion: Record<string, string | null>[];
  159. messages: TicketMessage[];
  160. };
  161. /* ── 报文 ── */
  162. /** 报文出参(`message_json`:已脱敏,⛔ 期望拿到原文)。 */
  163. export type TicketMessage = {
  164. message_id: string;
  165. unicom_order_no: string | null;
  166. reported_ticket_no: string | null;
  167. action: string | null;
  168. status: string | null;
  169. external_date: string | null;
  170. received_at: string | null;
  171. effective_at: string | null;
  172. void_reason: string | null;
  173. conflict_note: string | null;
  174. customer_name: string | null;
  175. identity_no: string | null;
  176. contact_name: string | null;
  177. contact_phone: string | null;
  178. network_account_name: string | null;
  179. };
  180. export type MessagePendingResult = {
  181. rows: TicketMessage[];
  182. total: number;
  183. page: number;
  184. page_size: number;
  185. };
  186. /* ── 详情 ── */
  187. export type TicketHead = {
  188. ticket_id: string;
  189. ticket_no: string;
  190. ticket_type: TicketType;
  191. status: TicketStatus;
  192. title: string;
  193. detail: string | null;
  194. customer_id: string | null;
  195. subscription_id: string | null;
  196. reporter_account_id: string | null;
  197. unicom_order_no: string | null;
  198. submitter_type: string | null;
  199. submitter_user_id: string | null;
  200. assign_team_id: string | null;
  201. assignee_user_id: string | null;
  202. assignee_snapshot_name: string | null;
  203. /** 服务端把 *_user_id 解析成的姓名回填进这三键(无匹配 ⇒ 键缺席,保留 ID 值) */
  204. assign_team_name?: string | null;
  205. creator_name?: string | null;
  206. delegate_from_name?: string | null;
  207. assignee_name?: string | null;
  208. delegate_from_user_id: string | null;
  209. delegated_at: string | null;
  210. expected_done_date: string | null;
  211. deferred_until: string | null;
  212. confirm_deadline: string | null;
  213. source_message_id: string | null;
  214. close_reason: string | null;
  215. completed_at: string | null;
  216. closed_at: string | null;
  217. settled_at: string | null;
  218. creator_user_id: string | null;
  219. created_at: string | null;
  220. updated_at: string | null;
  221. row_version: string;
  222. overdue: boolean;
  223. };
  224. export type OpenStopAccount = {
  225. id: string;
  226. sub_account_id: string | null;
  227. before_status: string | null;
  228. after_status: string | null;
  229. effective_date: string | null;
  230. source: string | null;
  231. display_name: string | null;
  232. net_account: string | null;
  233. };
  234. export type OpenStop = {
  235. open_stop_id: string;
  236. customer_id: string | null;
  237. subscription_id: string | null;
  238. action: string | null;
  239. exec_status: string | null;
  240. exec_date: string | null;
  241. effective_account_count: string | null;
  242. backfill_id: string | null;
  243. deferred_until: string | null;
  244. note: string | null;
  245. closed_flag: string | null;
  246. row_version: string;
  247. accounts: OpenStopAccount[];
  248. overdue: boolean;
  249. };
  250. export type RouteRow = {
  251. id: string;
  252. sub_account_id: string | null;
  253. network_account_name: string | null;
  254. intranet_ip: string | null;
  255. subnet_mask: string | null;
  256. gateway: string | null;
  257. vlan: string | null;
  258. vni: string | null;
  259. src_endpoint: string | null;
  260. dst_endpoint: string | null;
  261. egress_pop: string | null;
  262. down_mbps: string | null;
  263. up_mbps: string | null;
  264. };
  265. /** PIN/CPID 库里只有密文 ⇒ 只出"有没有登记"(`"true"`/`"false"` 字符串)。 */
  266. export type IpRow = {
  267. id: string;
  268. row_no: string;
  269. egress: string | null;
  270. overseas_ip: string | null;
  271. ip_type: string | null;
  272. bandwidth_mbps: string | null;
  273. pin_registered: string | null;
  274. cpid_registered: string | null;
  275. };
  276. export type Backfill = {
  277. backfill_id: string;
  278. exec_conclusion: string | null;
  279. conclusion_note: string | null;
  280. actual_opened_date: string | null;
  281. stop_done_date: string | null;
  282. builder_user_id: string | null;
  283. evidence_text: string | null;
  284. source: string | null;
  285. ip_rule_version: string | null;
  286. attempt_count: string | null;
  287. detail_empty_flag: string | null;
  288. row_version: string;
  289. created_at: string | null;
  290. routes: RouteRow[];
  291. ips: IpRow[];
  292. };
  293. /** 交接单**报数量不报明细**(数据模型§2.2):五应用类别逐项数量。 */
  294. export type HandoverApp = {
  295. app_id: string;
  296. app_category: string | null;
  297. qty: string | null;
  298. };
  299. /** 境外 IP 固定 4 行=国家+带宽档位+IP 数量(⛔ 具体 IP 段,明细在组三回填)。 */
  300. export type HandoverIp = {
  301. ip_id: string;
  302. row_no: string;
  303. country: string | null;
  304. bandwidth_mbps: string | null;
  305. ip_count: string | null;
  306. };
  307. export type Handover = {
  308. handover_id: string;
  309. declarant_name: string | null;
  310. declarant_org: string | null;
  311. declarant_contact: string | null;
  312. declaration_text: string | null;
  313. ip_rule_version: string | null;
  314. submitted_at: string | null;
  315. submitter_user_id: string | null;
  316. row_version: string;
  317. apps: HandoverApp[];
  318. overseas_ips: HandoverIp[];
  319. submitted: boolean;
  320. };
  321. export type Completion = {
  322. completion_id: string;
  323. completion_no: string | null;
  324. action: string | null;
  325. exec_conclusion: string | null;
  326. mode: string | null;
  327. pushed_at: string | null;
  328. pushed_by: string | null;
  329. receipt_at: string | null;
  330. /** 回执**仍有效**(`"1"`/`"0"`)=`receipt_at` 非空且晚于最近一次受控回退;回退后回执失效但 `receipt_at` 仍是历史值。 */
  331. receipt_valid: string | null;
  332. receipt_user_id: string | null;
  333. receipt_remark: string | null;
  334. ip_rule_version: string | null;
  335. pdf_ready: string | null;
  336. row_version: string;
  337. created_at: string | null;
  338. };
  339. /** 处理记录=append-only 纯文本留痕(数据模型§2.9):⛔ `related_id` 之类的关联列。 */
  340. export type ProcessLog = {
  341. log_id: string;
  342. action: string | null;
  343. /**
  344. * 操作人平台主体号。⚠️ 服务端按角色下发:台账读侧五档给原值(要拿它对齐审计流水),
  345. * 客户侧/合作方侧置 `null`;`"0"`=系统/定时作业主体(署名应落「系统」)。
  346. */
  347. actor_user_id: string | null;
  348. /** 操作人姓名(服务端按 `bos_user_binding` 现查;查无或系统主体为 `null`)。 */
  349. actor_name?: string | null;
  350. actor_role: string | null;
  351. note: string | null;
  352. at: string | null;
  353. };
  354. /** ⛔ 期望 `oss_key`:下载走 `material_grant`,服务端不外泄对象键。 */
  355. export type TicketMaterial = {
  356. material_id: string;
  357. kind: string | null;
  358. file_name: string | null;
  359. size_bytes: string | null;
  360. uploaded_by: string | null;
  361. uploaded_at: string | null;
  362. };
  363. export type ServiceItem = {
  364. item_id: string;
  365. seq_no: string;
  366. item_name: string | null;
  367. spec_text: string | null;
  368. expect_qty: string | null;
  369. check_result: string | null;
  370. checked_at: string | null;
  371. checked_by: string | null;
  372. note: string | null;
  373. };
  374. /**
  375. * 竣工驳回记录(`ticket_completion_reject`,工单§5.5.3,U-115)。
  376. *
  377. * ⚠️ 出参里**没有** `external_reject_no`:设计方案§5.1 把它列为门户/合伙人⛔ 回显字段,
  378. * 服务端直接把它排除在 SELECT 之外,前端⛔ 指望"拿到再隐藏"。
  379. */
  380. export type CompletionReject = {
  381. reject_seq: string;
  382. channel: string;
  383. completion_no: string;
  384. primary_code: string;
  385. reason_codes: string;
  386. reason_text: string;
  387. pushed_at: string | null;
  388. rejected_at: string | null;
  389. };
  390. /** `reject@v1` 应答:`data` 平铺(工单§5.5.3)。 */
  391. export type CompletionRejectResult = {
  392. data: {
  393. ticket_id: string;
  394. ticket_no?: string;
  395. ticket_status: string;
  396. reject_seq: string;
  397. completion_no: string;
  398. primary_code: string;
  399. reason_codes: string[];
  400. completion_channel?: string;
  401. external_wait_seconds?: number | null;
  402. row_version?: number | null;
  403. pathway?: string;
  404. idempotent_replay?: boolean;
  405. message: string;
  406. };
  407. };
  408. export type TicketDetail = {
  409. ticket: TicketHead;
  410. customer: {
  411. customer_id: string;
  412. customer_name: string | null;
  413. customer_code: string | null;
  414. contact_name: string | null;
  415. contact_mobile: string | null;
  416. address: string | null;
  417. } | null;
  418. order: {
  419. subscription_id: string;
  420. customer_id: string | null;
  421. plan_name: string | null;
  422. plan_kind: string | null;
  423. use_category: string | null;
  424. sub_mode: string | null;
  425. line_exits: string | null;
  426. order_no: string | null;
  427. term: string | null;
  428. start_date: string | null;
  429. status: string | null;
  430. actual_opened_at: string | null;
  431. } | null;
  432. service_items: ServiceItem[];
  433. open_stop: OpenStop | null;
  434. backfill: Backfill | null;
  435. handover: Handover | null;
  436. completion: Completion | null;
  437. /** 驳回流水(旧→新)。门户/合伙人拿到的行集与运维侧同形,只是少了对外编号列。 */
  438. completion_rejects?: CompletionReject[];
  439. /** 「外部等待中」判据(工单§4.6 第六条):由服务端判,⛔ 前端用 `length > 0` 推导。 */
  440. reject_pending?: boolean;
  441. process_logs: ProcessLog[];
  442. materials: TicketMaterial[];
  443. messages: TicketMessage[];
  444. /** 缺口分组名(与 `required_groups` 同词典);空集=可出竣工 */
  445. gaps: string[];
  446. required_groups: string[];
  447. actions: Record<TicketActionKey, boolean>;
  448. read_advanced: boolean;
  449. };
  450. /* ══════════════ 写侧入参/出参 ══════════════ */
  451. /** 建单携带的材料:只有 `oss_key`(已直传、未登记),服务端补 file_name/size。 */
  452. export type CreateMaterialIn = { oss_key: string };
  453. export type TicketCreateResult = {
  454. ticket_id: string;
  455. ticket_no: string;
  456. status: TicketStatus;
  457. assign_team_id: string | null;
  458. /** 抑制分支才有:命中§3.3.1 同类未完成抑制时回「已并入既有工单」+既有单信息 */
  459. suppressed?: boolean;
  460. message?: string;
  461. existing_ticket_no?: string;
  462. existing_id?: string;
  463. };
  464. export type AssignResult = {
  465. ticket_id: string;
  466. assignee_user_id: string;
  467. assignee_snapshot_name: string;
  468. status: TicketStatus;
  469. };
  470. /** 自动分派回执(create.rs dispatch_auto_inner):dispatched/skipped 是明细数组,不是计数。 */
  471. export type DispatchedTicket = {
  472. ticket_id: string;
  473. ticket_no: string | null;
  474. assignee_user_id: string;
  475. assignee_snapshot_name: string | null;
  476. };
  477. export type DispatchSkipped = {
  478. ticket_id: string;
  479. ticket_no?: string | null;
  480. /** no_candidate=无合适成员;already_taken=并发下已被他人分派 */
  481. reason: string;
  482. message?: string;
  483. };
  484. export type DispatchResult = {
  485. team_id: string;
  486. scanned: number;
  487. dispatched: DispatchedTicket[];
  488. skipped: DispatchSkipped[];
  489. };
  490. export type DelegateResult = {
  491. ticket_id: string;
  492. assignee_user_id: string;
  493. assignee_snapshot_name: string;
  494. delegate_from_user_id: string;
  495. delegated_at: string;
  496. status: TicketStatus;
  497. };
  498. export type StartResult = {
  499. ticket_id: string;
  500. advanced: boolean;
  501. status: TicketStatus;
  502. /** `advanced:false` 时后端回的原因:非责任人/已被推进/并发。 */
  503. reason?: "not_assignee" | "already_advanced" | "concurrent";
  504. advanced_at?: string;
  505. audit_written?: boolean;
  506. };
  507. export type BackfillInRoute = {
  508. sub_account_id?: string | null;
  509. network_account_name?: string | null;
  510. intranet_ip?: string | null;
  511. subnet_mask?: string | null;
  512. gateway?: string | null;
  513. vlan?: string | null;
  514. vni?: string | null;
  515. src_endpoint?: string | null;
  516. dst_endpoint?: string | null;
  517. egress_pop?: string | null;
  518. down_mbps?: number | null;
  519. up_mbps?: number | null;
  520. open_this_time: boolean;
  521. };
  522. export type BackfillInIp = {
  523. egress?: string | null;
  524. overseas_ip?: string | null;
  525. ip_type?: string | null;
  526. bandwidth_mbps?: number | null;
  527. pin?: string | null;
  528. cpid?: string | null;
  529. };
  530. export type BackfillResult = {
  531. ticket_id: string;
  532. backfill_id: string;
  533. exec_conclusion: string;
  534. route_rows: number;
  535. ip_rows: number;
  536. ip_rule_version: string;
  537. open_stop_id: string | null;
  538. effective_account_count: number;
  539. apply_facts: unknown;
  540. status: TicketStatus;
  541. status_advanced: boolean;
  542. /** 仍缺的分组名:非空 ⇒ 已保存但未达闭环口径(页面点名,⛔ 报"保存失败") */
  543. missing_groups: string[];
  544. audit_written: boolean;
  545. };
  546. export type CheckDoneResult = {
  547. ticket_id: string;
  548. all_done: boolean;
  549. pending_rows: number;
  550. missing_item_ids: string[];
  551. audit_written: boolean;
  552. };
  553. export type MarkDoneResult = {
  554. ticket_id: string;
  555. status: TicketStatus;
  556. completed_at: string;
  557. biz_date: string;
  558. audit_written: boolean;
  559. };
  560. export type HandoverIn = {
  561. declarant_name?: string | null;
  562. declarant_org?: string | null;
  563. declarant_contact?: string | null;
  564. declaration_text?: string | null;
  565. apps?: { app_category: string; qty?: number | null }[];
  566. ips?: { country: string; bandwidth_mbps?: number | null; ip_count?: number | null }[];
  567. };
  568. export type HandoverSaveResult = {
  569. ticket_id: string;
  570. handover_id: string;
  571. overwritten: boolean;
  572. app_total: number;
  573. row_version: number;
  574. };
  575. export type FinalizeResult = {
  576. ticket_id: string;
  577. status: TicketStatus;
  578. closed_at?: string;
  579. open_stop_closed?: boolean;
  580. settled_at?: string;
  581. defer_scope?: string;
  582. deferred_until?: string;
  583. reverted_from?: string;
  584. untouched?: string[];
  585. audit_written: boolean;
  586. };
  587. export type CompletionGenerateResult = {
  588. ticket_id: string;
  589. ticket_status: TicketStatus;
  590. completion_id: string;
  591. completion_no: string;
  592. action: string;
  593. exec_conclusion: string;
  594. mode: string;
  595. pushed_at: string;
  596. pushed_by: string;
  597. pushed_by_name: string | null;
  598. ip_rule_version: string;
  599. pdf_oss_key: string | null;
  600. reissued: boolean;
  601. receipt_valid: boolean;
  602. audit_written: boolean;
  603. next_step: string;
  604. };
  605. export type CompletionReceiptResult = {
  606. ticket_id: string;
  607. ticket_status: TicketStatus;
  608. completion_no: string | null;
  609. receipt_at: string;
  610. receipt_user_id: string;
  611. receipt_user_name: string | null;
  612. settled_at: string;
  613. completed_at: string;
  614. audit_written: boolean;
  615. next_step: string;
  616. };
  617. export type MessageActionResult = {
  618. message_id: string;
  619. status: string;
  620. ticket_id: string;
  621. audit_written: boolean;
  622. next_step: string;
  623. };
  624. export type MaterialGrantResult = {
  625. purpose: string;
  626. kind: string;
  627. ticket_id: string;
  628. ticket_status: TicketStatus;
  629. file_name: string;
  630. oss_key: string;
  631. prefix: string;
  632. presign_endpoint: string;
  633. bucket: string;
  634. size_limit_bytes: number;
  635. next_step: string;
  636. };
  637. export type MaterialAttachResult = {
  638. ticket_id: string;
  639. material_id: string;
  640. file_name: string;
  641. audit_written: boolean;
  642. };
  643. export type ClosureConfig = {
  644. closure_mode: string;
  645. closure_mode_name: string;
  646. row_version: string;
  647. updated_at: string | null;
  648. updated_by: string | null;
  649. };
  650. export type ClosureConfigUpdateResult = {
  651. closure_mode: string;
  652. changed: boolean;
  653. /** 同档提交(changed=false)时服务端不回此键 */
  654. from?: string;
  655. row_version: number;
  656. updated_by: string;
  657. audit_written: boolean;
  658. next_step: string;
  659. };
  660. /* ══════════════ 工具 ══════════════ */
  661. /** 后端 `::text` 投影出来的布尔列(`"true"`/`"false"`/`"t"`/`"f"`)。列表页的真布尔走原值。 */
  662. export function isYes(v: unknown): boolean {
  663. if (typeof v === "boolean") return v;
  664. const s = `${v ?? ""}`.trim().toLowerCase();
  665. return s === "true" || s === "t" || s === "1" || s === "yes";
  666. }
  667. /** 乐观并发两种拼写并存:`handle`/`finalize` 族=`expected_version`,`completion`/`message`/`config` 族=`expect_version`。 */
  668. const q = (o: Record<string, string | number | undefined | null>) =>
  669. Object.entries(o)
  670. .filter(([, v]) => v !== undefined && v !== null && `${v}` !== "")
  671. .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
  672. .join("&");
  673. /* ══════════════ §6.1 读侧(7) ══════════════ */
  674. /** 工单列表 [实]。分页 **1 基**(`page_norm`),UI 页码直接透传。 */
  675. export const ticketList = (d: {
  676. ticket_types?: string[];
  677. statuses?: string[];
  678. /** 回填来源三值:manual/unicom_feedback/mixed */
  679. sources?: string[];
  680. date_from?: string;
  681. date_to?: string;
  682. keyword?: string;
  683. /** 订单(订阅)过滤:订单详情「关联工单」按本条订单现查(P3-D6)。 */
  684. subscription_id?: string;
  685. /** 合同过滤:合同详情「关联工单」按合同下订单集合现查(P3-D7)。 */
  686. contract_id?: string;
  687. /** 客户过滤:客户维度的工单台账。 */
  688. customer_id?: string;
  689. page?: number;
  690. page_size?: number;
  691. }) => list<TicketListResult>("/ticket/list@v1", d, d);
  692. /** 工单详情定位入参 [实] —— 二选一(都给以 `ticket_id` 为准)。
  693. *
  694. * 客户门户⛔ 在 URL 里出现内部主键,故列表只回 `ticket_no`、详情按业务工单号定位;
  695. * 运营侧仍走 `ticket_id`(台账/队列/待办页手上有主键)。 */
  696. export type TicketDetailIn = { ticket_id?: string; ticket_no?: string; read_event?: boolean };
  697. /** 工单详情 [实] —— GET;`read_event=true` 才推进 pending→processing(终态返 KLT-G20401)。 */
  698. export const ticketDetail = (d: TicketDetailIn) =>
  699. get<TicketDetail>(
  700. `/ticket/detail@v1?${q({
  701. ticket_id: d.ticket_id,
  702. ticket_no: d.ticket_no,
  703. read_event: d.read_event ? "true" : undefined,
  704. })}`,
  705. );
  706. /** 待分派队列 [实] —— 逐行带 `candidates[]`(可分派候选人+手头量)。 */
  707. export const ticketPendingQueue = (d?: {
  708. ticket_types?: string[];
  709. assign_team_id?: string;
  710. keyword?: string;
  711. page?: number;
  712. page_size?: number;
  713. }) => list<PendingQueueResult>("/ticket/pending_queue@v1", d, d);
  714. /** 六档待办计数 [实] —— 红点/徽标唯一来源。 */
  715. export const ticketTodoCounts = () => get<TodoCounts>("/ticket/todo_counts@v1");
  716. /** 全链路追溯 [实] —— GET,四键至少一键(工单号/订单号/竣工单号/ticket_id)。 */
  717. export const ticketTrace = (d: TraceIn) => get<TraceResult>(`/ticket/trace@v1?${q({ ...d })}`);
  718. /** 报文待处置清单 [实] —— 仅 `unmatched`/`conflict`。 */
  719. export const messagePending = (d?: { page?: number; page_size?: number; status?: string }) =>
  720. list<MessagePendingResult>("/message/pending@v1", d, d);
  721. /* ══════════════ §6.2 建单与分派(4) ══════════════ */
  722. /**
  723. * 建单 [实] —— 客户侧/运营侧同一口,`submitter_type` 由服务端按身份定。
  724. * `ticket_type` 收 `fault`/`after_sale`/`service_stop`(create.rs `CREATE_TYPES`,
  725. * 2026-11-14 起「运营人工发起服务停用」也挂本口=工单§3.2.1);`title` 必填(≤128 字)。
  726. * `service_stop` 必带 `subscription_id` + `confirm:true`(二次确认),服务端同批登记
  727. * `ticket_open_stop`(`action=stop`、`exec_status=pending`),实际停机由回填执行。
  728. * 客户侧 ⛔ 带 `customer_id`(由会话派生);总运营必带;材料键须先落在
  729. * `提交材料/{customer_id}/` 前缀下——该前缀 ⛔ 在建单前取到(`material_grant` 要 `ticket_id`),
  730. * 所以门户建单 ⛔ 挂 attachments 假上传,材料在建单后走 `material_grant`+`material_attach`。
  731. */
  732. export const ticketCreate = (d: {
  733. ticket_type: string;
  734. customer_id?: string;
  735. title: string;
  736. detail?: string;
  737. subscription_id?: string;
  738. /** 仅 `service_stop` 用:人工发起停用的二次确认位,⛔ 由服务端默认放行。 */
  739. confirm?: boolean;
  740. materials?: CreateMaterialIn[];
  741. }) => post<TicketCreateResult>("/ticket/create@v1", d);
  742. /** 人工分派 [实] —— 候选人来自 `pending_queue` 行内 `candidates[]`。 */
  743. export const ticketAssign = (d: { ticket_id: string; assignee_user_id: string }) =>
  744. post<AssignResult>("/ticket/assign@v1", d);
  745. /** 自动分派 [实] —— 按团队批量。 */
  746. export const ticketDispatchAuto = (d: { team_id: string }) =>
  747. post<DispatchResult>("/ticket/dispatch_auto@v1", d);
  748. /** 转交代管 [实] —— 责任人本人把单交给同事代管。 */
  749. export const ticketDelegate = (d: { ticket_id: string; trustee_user_id: string }) =>
  750. post<DelegateResult>("/ticket/delegate@v1", d);
  751. /* ══════════════ §6.3 处理推进与回填(5) ══════════════ */
  752. /** 开始处理 [实]。 */
  753. export const ticketStart = (d: { ticket_id: string }) => post<StartResult>("/ticket/start@v1", d);
  754. /** 施工回填 [实] —— 停机类只录组四五项(契约 14.2),`route_rows`/`ip_rows` 传空数组。 */
  755. export const ticketBackfill = (d: {
  756. ticket_id: string;
  757. exec_conclusion?: string;
  758. conclusion_note?: string;
  759. actual_opened_date?: string;
  760. stop_done_date?: string;
  761. builder_user_id?: string;
  762. evidence_text?: string;
  763. route_rows?: BackfillInRoute[];
  764. ip_rows?: BackfillInIp[];
  765. expected_version?: number;
  766. }) => post<BackfillResult>("/ticket/backfill@v1", d);
  767. /** 服务开通条目核对 [实]。 */
  768. export const ticketCheckDone = (d: { ticket_id: string; item_ids?: string[]; note?: string; expected_version?: number }) =>
  769. post<CheckDoneResult>("/ticket/check_done@v1", d);
  770. /** 非主线单标记完成 [实]。 */
  771. export const ticketMarkDone = (d: { ticket_id: string; note?: string; expected_version?: number }) =>
  772. post<MarkDoneResult>("/ticket/mark_done@v1", d);
  773. /** 交接单登记 [实] —— 一次开通一份,重复保存=整体覆盖(冲突 KLT-G20417)。 */
  774. export const ticketHandoverSave = (d: { ticket_id: string; handover: HandoverIn; expected_version?: number }) =>
  775. post<HandoverSaveResult>("/ticket/handover_save@v1", d);
  776. /* ══════════════ §6.4 终态收口与受控回退(5) ══════════════ */
  777. /** 关闭/作废 [实]。 */
  778. export const ticketClose = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
  779. post<FinalizeResult>("/ticket/close@v1", d);
  780. /** 客户侧撤回并关闭 [实]。 */
  781. export const ticketWithdraw = (d: { ticket_id: string; reason?: string }) =>
  782. post<FinalizeResult>("/ticket/withdraw@v1", d);
  783. /** 非主线单客户侧闭环确认 [实]。 */
  784. export const ticketConfirmClose = (d: { ticket_id: string; expected_version?: number }) =>
  785. post<FinalizeResult>("/ticket/confirm_close@v1", d);
  786. /** 延期提醒 [实] —— 载体两档:`open_stop`(开停记录)/`ticket`(工单本身);期限由服务端按超期天数推进。 */
  787. export const ticketDefer = (d: { ticket_id: string; defer_scope?: "open_stop" | "ticket" }) =>
  788. post<FinalizeResult>("/ticket/defer@v1", d);
  789. /** 受控回退(仅总运营) [实]。 */
  790. export const ticketRevert = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
  791. post<FinalizeResult>("/ticket/revert@v1", d);
  792. /* ══════════════ §6.5 竣工回传与回执(2) ══════════════ */
  793. /** 生成并回传竣工 [实] —— 缺口未清 ⇒ 服务端硬拦。 */
  794. export const completionGenerate = (d: { ticket_id: string }) =>
  795. post<CompletionGenerateResult>("/completion/generate@v1", d);
  796. /** 回执确认闭环 [实] —— 仅 admin/该团队主账号。 */
  797. export const completionReceipt = (d: {
  798. ticket_id: string;
  799. completion_no?: string;
  800. external_order_no?: string;
  801. receipt_remark?: string;
  802. expect_version?: number;
  803. /** 驳回态冲突纠正(设计方案§3.3):**仅 admin** 生效,非驳回态传了也⛔ 改变任何行为。 */
  804. override_state_conflict?: boolean;
  805. }) => post<CompletionReceiptResult>("/completion/receipt@v1", d);
  806. /**
  807. * 竣工驳回理由七枚(工单§5.5.3 批复④),**顺序=后端 `domain::REJECT_REASONS` 定义序**。
  808. *
  809. * ⚠️ 顺序有语义:服务端按本表下标归一化后落库,**主原因=归一化首位**(下标最小的那枚),
  810. * ⛔ 把"用户先点的那枚"当主原因——同一次勾选无论怎么点主原因都相同,报表「主原因分布」
  811. * 才不会被排列组合劈成几条(驳回抽屉的预览按这条口径回显)。
  812. */
  813. export const REJECT_REASONS: { code: string; name: string }[] = [
  814. { code: "doc_mismatch", name: "资料不符" },
  815. { code: "resource_unavailable", name: "端口或IP资源不可用" },
  816. { code: "duplicate", name: "重复申报" },
  817. { code: "out_of_scope", name: "超出受理范围" },
  818. { code: "doc_missing", name: "竣工资料缺失" },
  819. { code: "site_not_ready", name: "现场不具备条件" },
  820. { code: "other", name: "其他" },
  821. ];
  822. /** 一次驳回的枚数上限(`1 ≤ n ≤ 3`,超限/空选 ⇒ `KLT-G20422`)。 */
  823. export const REJECT_REASON_MAX = 3;
  824. /** 归一化主原因(本表下标最小者);未勾选回空串。 */
  825. export const rejectPrimaryReason = (codes: string[]) =>
  826. REJECT_REASONS.find((r) => codes.includes(r.code))?.name ?? "";
  827. /** 登记竣工驳回 [实](工单§5.5.3,U-115)——重复提交命中幂等回 `KLT-G20421`+既有 seq。 */
  828. export const completionReject = (d: {
  829. ticket_id: string;
  830. reason_codes: string[];
  831. reason_text: string;
  832. external_reject_no?: string;
  833. }) => post<CompletionRejectResult>("/completion/reject@v1", d);
  834. /* ══════════════ §6.6 报文人工处置(4) ══════════════ */
  835. /** 报文关联到工单 [实]。 */
  836. export const messageAttach = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
  837. post<MessageActionResult>("/message/attach@v1", d);
  838. /** 报文作废 [实] —— `void_reason` 服务端必填(缺失 ⇒ KLT-G20412),⛔ 空串提交。 */
  839. export const messageVoid = (d: { message_id: string; void_reason?: string; expect_version?: number }) =>
  840. post<MessageActionResult>("/message/void@v1", d);
  841. /** 冲突确认 [实] —— `as_is`=以现状为准归档(默认)/`apply_external`=按报文外部值生效。 */
  842. export const messageConfirmConflict = (d: {
  843. message_id: string;
  844. disposition?: "as_is" | "apply_external";
  845. note?: string;
  846. expect_version?: number;
  847. }) => post<MessageActionResult>("/message/confirm_conflict@v1", d);
  848. /** 报文改绑到另一单 [实]。 */
  849. export const messageRematch = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
  850. post<MessageActionResult>("/message/rematch@v1", d);
  851. /* ══════════════ §6.7 材料直传(2) ══════════════ */
  852. /** 申请直传凭证 [实] —— 拿 `oss_key` 后到 `presign_endpoint` 换签名直传,再 `material_attach` 登记。 */
  853. export const ticketMaterialGrant = (d: {
  854. ticket_id: string;
  855. kind: string;
  856. file_name?: string;
  857. purpose?: string;
  858. oss_key?: string;
  859. }) => post<MaterialGrantResult>("/ticket/material_grant@v1", d);
  860. /** 登记已直传材料 [实]。 */
  861. export const ticketMaterialAttach = (d: {
  862. ticket_id: string;
  863. kind: string;
  864. oss_key: string;
  865. file_name?: string;
  866. size_bytes?: number;
  867. }) => post<MaterialAttachResult>("/ticket/material_attach@v1", d);
  868. /* ══════════════ §6.8 闭环方式配置(2) ══════════════ */
  869. /** 读闭环方式 [实] —— 仅运营侧三类;交付侧 11104。 */
  870. export const ticketConfigGet = () => get<ClosureConfig>("/ticket/config_get@v1");
  871. /** 改闭环方式 [实] —— 仅总运营;`reason` 必填进审计。 */
  872. export const ticketConfigUpdate = (d: { closure_mode: string; expect_version?: number; reason?: string }) =>
  873. post<ClosureConfigUpdateResult>("/ticket/config_update@v1", d);