ticket.ts 37 KB

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