ticket.ts 34 KB

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