ticket.ts 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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 第七类主线类型:契约内逐条替换的变更协议(码值 updown,系统专属,⛔ 手工建单)。
  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. // 第七类:契约内逐条替换的变更协议(码值 updown,系统专属)。
  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` 原名「已闭环」(2026-11-18 业务化改名):它跟财务结算无关,只是流程收口,
  73. // 所以⛔ 译成「已结算」;与 `terminated`(已关闭=作废结案)并列时语义才清楚——
  74. // 一个「办成了」,一个「关掉了」。
  75. settled: "已办结",
  76. terminated: "已作废",
  77. };
  78. /**
  79. * 主线五类(与后端 `domain::MAINLINE` 同源,2026-11-17 起含第七类 `updown`):
  80. * 这五类停在 `completed` 等的是**竣工回传+运营商回执**(工单§4.1.2 通路 6)。
  81. */
  82. const MAINLINE_TICKET_TYPES = new Set(["open", "service_open", "expiry_stop", "service_stop", "updown"]);
  83. /**
  84. * 主线(服务交付类)`completed` 的展示名(2026-11-18 业主补充定案)。
  85. *
  86. * ⚠️ 主线停在 `completed` 时施工已完、**回执还没有**(通路 6 要运营商确认后才 `settled`):
  87. * 只叫「已完成」会让运维和运营商都以为单子已经收口,实际上还压着一次回执确认。
  88. */
  89. export const COMPLETED_AWAITING_RECEIPT_LABEL = "已完成待确认";
  90. /**
  91. * 非主线(故障/售后)`completed` 的展示名(2026-11-18 业主定案)。
  92. *
  93. * ⚠️ 该态**不是终态**(工单§4.1.1「待确认态」):处理已做完,等提交方在门户确认
  94. * 或 `AUTO-CLOSE` 满 7 天自动闭环(通路 7)。只叫「已完成」会让客户和运维都以为单子已结束,
  95. * 而实际上它还压着一次确认动作。
  96. */
  97. export const COMPLETED_PENDING_CONFIRM_LABEL = "已处理待确认";
  98. export const typeLabel = (v?: string | null) => (v ? TICKET_TYPE_NAMES[v] ?? v : "-");
  99. /**
  100. * 是否主线(服务交付类)工单:`completed` 之后走「竣工回传+运营商回执」(通路 6),
  101. * 而非主线的 `completed` 走「提交方确认/超时自动闭环」(通路 7)。
  102. * ⚠️ 与后端 `domain::MAINLINE` 同源;页面拿它区分**谁该动手**(主线是本方确认回执,
  103. * 非主线只能等客户),⛔ 用它判权限。
  104. */
  105. export const isMainlineTicketType = (v?: string | null): boolean => Boolean(v && MAINLINE_TICKET_TYPES.has(v));
  106. /**
  107. * 状态中文名。`ticketType` **只影响 `completed` 一档**——该档在两类单上都不是终态,
  108. * 只是**等谁确认**不同:
  109. * * 主线(服务交付类)⇒「已完成待确认」:施工已完,等运营商回执(通路 6);
  110. * * 故障/售后 ⇒「已处理待确认」:处理已完,等提交方确认或超时自动闭环(通路 7)。
  111. *
  112. * ⚠️ 不传类型时仍取「已完成」——那是对**状态码**的叫法(跨类型的状态筛选器、状态 Tab、
  113. * 以及续签等没有 `completed` 边的类型)。行内徽标一律把 `ticket_type` 传进来。
  114. * ⚠️ 只分叉展示名,状态码仍是一个 `completed`(⛔ 新增第八态,⛔ 改服务端档位)。
  115. */
  116. const statusNameOf = (v?: string | null, kind: "mainline" | "nonmainline" | null = null) => {
  117. if (!v) return "-";
  118. if (v === "completed" && kind === "mainline") return COMPLETED_AWAITING_RECEIPT_LABEL;
  119. if (v === "completed" && kind === "nonmainline") return COMPLETED_PENDING_CONFIRM_LABEL;
  120. return TICKET_STATUS_NAMES[v] ?? v;
  121. };
  122. export const statusLabel = (v?: string | null, ticketType?: string | null) =>
  123. statusNameOf(v, ticketType ? (isMainlineTicketType(ticketType) ? "mainline" : "nonmainline") : null);
  124. /**
  125. * 只受理故障/售后的页面(客户自助门户,EP-03)用的状态名:`completed` 一律按非主线叫法。
  126. * ⚠️ 与 [`statusLabel`] 同源,⛔ 在页面里另抄一份中文名。
  127. */
  128. export const nonMainlineStatusLabel = (v?: string | null) => statusNameOf(v, "nonmainline");
  129. /**
  130. * 跨类型视图里 `completed` 的**筛选名**(2026-11-18 业主二次定案:Tab 只写「待确认」)。
  131. *
  132. * 一个选项要同时覆盖主线与故障/售后两类,故⛔ 只写其中一半;但两半全名拼在 Tab 上
  133. * 长达 15 字(「已完成待确认/已处理待确认」),实测把 Tab 行撑破。定案:筛选维度只写
  134. * 「待确认」,两半的叫法留在**行内徽标**(按 `ticket_type` 分叉)与悬停说明里。
  135. */
  136. export const COMPLETED_CROSS_TYPE_LABEL = "待确认";
  137. /**
  138. * 状态**筛选维度**的中文名(状态 Tab/状态下拉/当前视图 chip)。与行内徽标不同:
  139. * 这里的选项没有 `ticket_type`、一个取值要覆盖全部类型,故 `completed` 走跨类型短名
  140. * 「待确认」(见 [`COMPLETED_CROSS_TYPE_LABEL`])。
  141. * ⚠️ 行内徽标仍用 [`statusLabel`](按类型只给一个名字);⛔ 两处混用。
  142. */
  143. export const statusFilterLabel = (v?: string | null) => (v === "completed" ? COMPLETED_CROSS_TYPE_LABEL : statusLabel(v));
  144. /** 详情页动作位(`finish()` 的 `actions`,工单§3.7.3)。 */
  145. export type TicketActionKey =
  146. | "assign"
  147. | "backfill"
  148. | "check_done"
  149. | "check_and_backfill"
  150. | "mark_done"
  151. | "delegate"
  152. | "close"
  153. | "defer_open_stop"
  154. | "defer_ticket"
  155. | "withdraw"
  156. | "generate_completion"
  157. | "reject_completion"
  158. | "confirm_receipt"
  159. /**
  160. * 退回重办(工单§4.2):2026-11-22 起由服务端下发(=总运营 ∨ 该单承接团队的团队主账号
  161. * ∧ 状态 ∈ `REVERTABLE`)。它按页面契约§14 不进右栏分组,⛔ 前端按 `identity.role` 自推。
  162. */
  163. | "revert";
  164. /* ══════════════ 读侧出参 ══════════════ */
  165. /**
  166. * 「卡在别人手里」的对家与催办读数(`waiting.rs::to_json`,列表 `rows[].waiting` 与详情 `waiting` 同形)。
  167. *
  168. * * `kind`:`receipt`=等运营商回执(v1.62 起对家=**该客户所属运营商的账号**);
  169. * `customer`=等客户确认(对家=提交方账号)。
  170. * * `counterparty_user_id` 为 `null` =主体档案在但**没有可用账号**(运营商账号未创建/已停用):
  171. * 行内仍写「等{运营商}回执」,但前端⛔ 给催办入口(发给没人读的信箱=假成功)。
  172. * * `org_name`:所属主体名(运营商取所在省份、客户取客户名),行内括号用它。
  173. * * `urge.eligible` 是**纯时长+对家**口径(⛔ 角色权限位):`true` 只说明「现在可以催」,
  174. * 服务端写口还会按角色与对象再判一次。
  175. * * `urge.reason` 取值:`no_counterparty`/`self`/`no_completed_at`/`waiting_lt_min`/
  176. * `already_sent_today`(`already_sent_today` 是**幂等成功**,不是错误)。
  177. */
  178. export type TicketWaiting = {
  179. kind: "receipt" | "customer" | string;
  180. /** 服务端中文主文案(「等运营商回执」/「等客户确认」),⛔ 前端再拼一份。 */
  181. label: string;
  182. counterparty_user_id: string | null;
  183. counterparty_name: string | null;
  184. counterparty_role: string | null;
  185. /** 所属主体名(运营商所在地/客户名);无值时不加括号。 */
  186. org_name: string | null;
  187. since: string | null;
  188. hours: number | null;
  189. urge: {
  190. eligible: boolean;
  191. reason: string | null;
  192. sent_today: boolean;
  193. last_sent_at: string | null;
  194. min_hours: number;
  195. };
  196. };
  197. /** `POST /ticket/list@v1` 行(`list_inner` 的 `json!`,键名逐字对齐)。 */
  198. export type TicketListItem = {
  199. /** 全局序号(按当页偏移现算) */
  200. seq_no?: number;
  201. ticket_id: string;
  202. ticket_no: string | null;
  203. ticket_type: TicketType;
  204. title: string | null;
  205. customer_id: string | null;
  206. customer_name: string | null;
  207. assign_team_id: string | null;
  208. team_name?: string | null;
  209. assignee_user_id: string | null;
  210. assignee_name?: string | null;
  211. status: TicketStatus;
  212. /** 回填来源(manual/unicom_feedback/mixed;NULL=未回填) */
  213. backfill_source: string | null;
  214. expected_done_date: string | null;
  215. /**
  216. * 延期后的**生效期限**(`YYYY-MM-DD`;无延期=`null`/`undefined`)。
  217. *
  218. * 服务端 `handlers/read.rs` 已按 `os.deferred_until` → `t.deferred_until` 折算后下发
  219. * (与 `overdue_7d` 同一优先级)。行内日期、分组与「还剩 N 天」都用它,⛔ 再用
  220. * `expected_done_date`——那会让延期单显示「已超 N 天」而页顶「已超期」不数它。
  221. */
  222. deferred_until?: string | null;
  223. /** 7 日内到期/已超期(真布尔;仅队列口下发) */
  224. overdue_7d?: boolean;
  225. /**
  226. * 执行锁(2026-11-17,服务端业务日现算):开通类三类
  227. * (`open`/`service_open`/`updown`)的计划执行日=订阅**服务开始日**,未到该日
  228. * ⇒ `true`:工单可见可分派,但回填/核对一律被 `KLT-G20403` 拒。
  229. *
  230. * ⚠️ ⛔ 前端按 `expected_done_date - 今天` 自行推断:业务日锚在 `Asia/Shanghai`,
  231. * 浏览器时钟与它不同源(跨零点会打架)。
  232. */
  233. execution_locked?: boolean;
  234. /** 计划执行日(=服务开始日;非开通类恒 `null`),可作日期输入的 `min`。 */
  235. execution_not_before?: string | null;
  236. created_at: string | null;
  237. completed_at?: string | null;
  238. /**
  239. * 「卡在别人手里」的对家与催办读数(2026-11-18,服务端 `waiting.rs`)。
  240. *
  241. * 只在**能看台账的五档**(admin/运主/运子/团队主/`ops`)下发;客户侧与续签单、非
  242. * `completed` 行恒 `null`/`undefined`。对家姓名由服务端解析,⛔ 前端按类型猜
  243. * (主线=承接团队的团队主账号,故障/售后=提交方账号,续签没有对家)。
  244. */
  245. waiting?: TicketWaiting | null;
  246. /**
  247. * 提交方(`customer`=客户自报/`ops`=运营代建/`system`/`unicom`)。
  248. *
  249. * ⚠️ 声明成可选是事实而非猜测:`handlers/read.rs` 的 `LIST_COLS` 投影里**没有**这一列,
  250. * `list_inner` 的 `json!` 也不下发 ⇒ 列表行拿到这里通常是 `undefined`。
  251. * 客户侧「我的工单」据此判闸门(`customerLiveTicketActions`):`undefined`=还没取过详情,
  252. * ⛔ 凭空当作 `customer` 给「确认完成,关闭工单」按钮(运维代建的单点了必被 `KLT-G20401` 拒)。
  253. * 后端哪天补上这列,前端无需改动即可直接在同一行给出按钮。
  254. */
  255. submitter_type?: string | null;
  256. };
  257. export type TicketListResult = {
  258. rows: TicketListItem[];
  259. total: number;
  260. page: number;
  261. page_size: number;
  262. };
  263. /** 可分派候选人(`pending_queue` 行内 `candidates[]`,⛔ 前端再拼一份人名单)。 */
  264. export type AssignCandidate = {
  265. user_id: string;
  266. username: string | null;
  267. display_name: string | null;
  268. /** 该候选人手头未完成单量(自动分派按此最少先挑) */
  269. pending_count: number;
  270. /**
  271. * 候选来源(2026-11-17):`ops_account`=运营主/子账号(不是运维团队成员,
  272. * 按「客户在其负责范围内」入池),缺省=运维团队成员。承接后的可用动作不同
  273. * (运营账号没有成员档案),故页面必须标出来。
  274. */
  275. source?: "member" | "ops_account";
  276. };
  277. export type PendingQueueItem = TicketListItem & {
  278. candidates: AssignCandidate[];
  279. };
  280. export type PendingQueueResult = {
  281. rows: PendingQueueItem[];
  282. total: number;
  283. page: number;
  284. page_size: number;
  285. };
  286. /** `GET /ticket/todo_counts@v1`:四件套计数(口径写死在 SQL,`note` 是人读口径说明)。 */
  287. export type TodoCounts = {
  288. /** 件1:开户/到期停机/服务停用/升降配 ∧ 尚未回填出开停事实 ∧ 已超期(开通类=**超过**服务开始日才计入;停机类=建单日+7 当天计入;批准延期后按新期限) */
  289. item_1_pending_exec_overdue: number;
  290. /** 件2:服务开通工单(待分派/待处理/处理中)同口径筛超期,与件1 单集互斥 */
  291. item_2_service_open_incomplete: number;
  292. /** 件4:待处置报文(未归集+待确认),⛔ 与未回填合算 */
  293. item_4_message_pending: number;
  294. note: string;
  295. };
  296. /* ── 追溯 ── */
  297. /**
  298. * `GET /ticket/trace@v1`(§3.7.3):**单票**四段一次拉齐;查无/越权同回 `11104`(⛔ 拆穿存在性)。
  299. * 入参四键至少给一键:`ticket_no`/`carrier_order_no`/`completion_no`/`ticket_id`。
  300. */
  301. export type TraceIn = { ticket_no?: string; carrier_order_no?: string; completion_no?: string; ticket_id?: string };
  302. export type TraceResult = {
  303. ticket: {
  304. ticket_id: string;
  305. ticket_no: string | null;
  306. ticket_type: TicketType;
  307. status: TicketStatus;
  308. customer_id: string | null;
  309. carrier_order_no: string | null;
  310. title: string | null;
  311. };
  312. /** 开停载体行(`::text` 字符串布尔判 `isYes`) */
  313. open_stop: Record<string, string | null>[];
  314. /** 回填头(至多一行) */
  315. backfill: Record<string, string | null>[];
  316. /** 竣工件行 */
  317. completion: Record<string, string | null>[];
  318. messages: TicketMessage[];
  319. };
  320. /* ── 报文 ── */
  321. /** 报文出参(`message_json`:已脱敏,⛔ 期望拿到原文)。 */
  322. export type TicketMessage = {
  323. message_id: string;
  324. carrier_order_no: string | null;
  325. reported_ticket_no: string | null;
  326. action: string | null;
  327. status: string | null;
  328. external_date: string | null;
  329. received_at: string | null;
  330. effective_at: string | null;
  331. void_reason: string | null;
  332. conflict_note: string | null;
  333. customer_name: string | null;
  334. identity_no: string | null;
  335. contact_name: string | null;
  336. contact_phone: string | null;
  337. network_account_name: string | null;
  338. };
  339. export type MessagePendingResult = {
  340. rows: TicketMessage[];
  341. total: number;
  342. page: number;
  343. page_size: number;
  344. };
  345. /* ── 详情 ── */
  346. export type TicketHead = {
  347. ticket_id: string;
  348. ticket_no: string;
  349. ticket_type: TicketType;
  350. status: TicketStatus;
  351. title: string;
  352. detail: string | null;
  353. customer_id: string | null;
  354. subscription_id: string | null;
  355. reporter_account_id: string | null;
  356. carrier_order_no: string | null;
  357. submitter_type: string | null;
  358. submitter_user_id: string | null;
  359. assign_team_id: string | null;
  360. assignee_user_id: string | null;
  361. assignee_snapshot_name: string | null;
  362. /** 服务端把 *_user_id 解析成的姓名回填进这三键(无匹配 ⇒ 键缺席,保留 ID 值) */
  363. assign_team_name?: string | null;
  364. creator_name?: string | null;
  365. delegate_from_name?: string | null;
  366. assignee_name?: string | null;
  367. delegate_from_user_id: string | null;
  368. delegated_at: string | null;
  369. expected_done_date: string | null;
  370. /** 执行锁(2026-11-17):开通类未到服务开始日 ⇒ `true`(写侧同口径拒绝)。 */
  371. execution_locked?: boolean;
  372. /** 计划执行日=服务开始日(非开通类恒 `null`)。 */
  373. execution_not_before?: string | null;
  374. deferred_until: string | null;
  375. confirm_deadline: string | null;
  376. source_message_id: string | null;
  377. close_reason: string | null;
  378. completed_at: string | null;
  379. closed_at: string | null;
  380. settled_at: string | null;
  381. creator_user_id: string | null;
  382. created_at: string | null;
  383. updated_at: string | null;
  384. row_version: string;
  385. overdue: boolean;
  386. };
  387. export type OpenStopAccount = {
  388. id: string;
  389. sub_account_id: string | null;
  390. before_status: string | null;
  391. after_status: string | null;
  392. effective_date: string | null;
  393. source: string | null;
  394. display_name: string | null;
  395. net_account: string | null;
  396. };
  397. export type OpenStop = {
  398. open_stop_id: string;
  399. customer_id: string | null;
  400. subscription_id: string | null;
  401. action: string | null;
  402. exec_status: string | null;
  403. exec_date: string | null;
  404. effective_account_count: string | null;
  405. backfill_id: string | null;
  406. deferred_until: string | null;
  407. note: string | null;
  408. closed_flag: string | null;
  409. row_version: string;
  410. accounts: OpenStopAccount[];
  411. overdue: boolean;
  412. };
  413. export type RouteRow = {
  414. id: string;
  415. sub_account_id: string | null;
  416. network_account_name: string | null;
  417. intranet_ip: string | null;
  418. subnet_mask: string | null;
  419. gateway: string | null;
  420. vlan: string | null;
  421. tunnel_encap?: string | null;
  422. vni: string | null;
  423. src_endpoint: string | null;
  424. dst_endpoint: string | null;
  425. egress_pop: string | null;
  426. down_mbps: string | null;
  427. up_mbps: string | null;
  428. proxy_host?: string | null;
  429. proxy_port?: string | null;
  430. pin_registered?: string | null;
  431. cpid_registered?: string | null;
  432. };
  433. /** PIN/CPID 库里只有密文 ⇒ 只出"有没有登记"(`"true"`/`"false"` 字符串)。 */
  434. export type IpRow = {
  435. id: string;
  436. row_no: string;
  437. egress: string | null;
  438. overseas_ip: string | null;
  439. ip_type: string | null;
  440. bandwidth_mbps: string | null;
  441. pin_registered: string | null;
  442. cpid_registered: string | null;
  443. /** P1(D-14):行级动作 `allocate`/`release`;释放行只定位旧 IP,不再要求重填凭据。 */
  444. action?: string | null;
  445. /** P1(D-4):该 IP 映射到的分账号主键(`fixed_ip` 恒 1 个、`nat_forward` 1..N 个)。 */
  446. sub_account_ids?: string[];
  447. };
  448. /** 扩展表单字段(模板 schema.fields[])。 */
  449. /** 命名格式规则(与后端 FORMAT_RULES 同源;⛔ 自定义正则)。 */
  450. export const FORM_FIELD_FORMATS = ["ipv4", "vlan", "digits", "alnum"] as const;
  451. export type FormFieldFormat = (typeof FORM_FIELD_FORMATS)[number];
  452. export const FORM_FIELD_FORMAT_NAMES: Record<FormFieldFormat, string> = {
  453. ipv4: "IPv4 地址",
  454. vlan: "VLAN(1–4094)",
  455. digits: "纯数字",
  456. alnum: "字母或数字",
  457. };
  458. export type FormFieldSchema = {
  459. key: string;
  460. label: string;
  461. type: string;
  462. required?: boolean;
  463. options?: { value: string; label: string }[];
  464. help?: string;
  465. /** 文本类长度上限:text/material_ref ≤200,textarea ≤2000。 */
  466. maxLength?: number;
  467. /** number 最小值。 */
  468. min?: number;
  469. /** number 最大值。 */
  470. max?: number;
  471. /** number 步长(>0);相对 min(缺省 0)对齐。 */
  472. step?: number;
  473. /** 文本类命名格式规则。 */
  474. format?: FormFieldFormat | string;
  475. /** 本字段跨列数(1..=layout.columns);缺省 1。 */
  476. span?: number;
  477. };
  478. export type FormSchema = {
  479. fields: FormFieldSchema[];
  480. /** 布局列数:1/2/3。 */
  481. layout?: { columns?: number };
  482. };
  483. /** 详情 `backfill.ext`/回填提交 `ext`。 */
  484. export type FormExtPayload = {
  485. template_id?: string | null;
  486. template_version?: number | string | null;
  487. schema?: FormSchema | null;
  488. values?: Record<string, unknown> | null;
  489. };
  490. export type Backfill = {
  491. backfill_id?: string | null;
  492. exec_conclusion: string | null;
  493. conclusion_note: string | null;
  494. actual_opened_date: string | null;
  495. stop_done_date: string | null;
  496. builder_user_id: string | null;
  497. evidence_text: string | null;
  498. source: string | null;
  499. ip_rule_version: string | null;
  500. attempt_count: string | null;
  501. detail_empty_flag: string | null;
  502. row_version: string;
  503. created_at: string | null;
  504. routes: RouteRow[];
  505. ips: IpRow[];
  506. /** 扩展表单:无模板为 null;有 published 未填时 values 为空对象。 */
  507. ext?: FormExtPayload | null;
  508. /** PIN 绑定模式:shared/per_account。 */
  509. pin_bind_mode?: string | null;
  510. };
  511. /** 模板管理口(§6.8.1)单条版本行。 */
  512. export type FormTemplateRow = {
  513. template_id: string;
  514. ticket_type: string;
  515. ticket_type_name?: string;
  516. version: string | number;
  517. status: string;
  518. schema: FormSchema;
  519. row_version: string | number;
  520. published_at?: string | null;
  521. created_at?: string | null;
  522. };
  523. export type FormTemplateBundle = {
  524. ticket_type: string;
  525. ticket_type_name?: string;
  526. published: FormTemplateRow | null;
  527. draft: FormTemplateRow | null;
  528. versions: FormTemplateRow[];
  529. };
  530. export type Completion = {
  531. completion_id: string;
  532. completion_no: string | null;
  533. action: string | null;
  534. exec_conclusion: string | null;
  535. mode: string | null;
  536. pushed_at: string | null;
  537. pushed_by: string | null;
  538. receipt_at: string | null;
  539. /** 回执**仍有效**(`"1"`/`"0"`)=`receipt_at` 非空且晚于最近一次退回重办;退回后回执失效但 `receipt_at` 仍是历史值。 */
  540. receipt_valid: string | null;
  541. receipt_user_id: string | null;
  542. receipt_remark: string | null;
  543. ip_rule_version: string | null;
  544. pdf_ready: string | null;
  545. row_version: string;
  546. created_at: string | null;
  547. };
  548. /** 处理记录=append-only 纯文本留痕(数据模型§2.9):⛔ `related_id` 之类的关联列。 */
  549. export type ProcessLog = {
  550. log_id: string;
  551. action: string | null;
  552. /**
  553. * 操作人平台主体号。⚠️ 服务端按角色下发:台账读侧五档给原值(要拿它对齐审计流水),
  554. * 客户侧/合作方侧置 `null`;`"0"`=系统/定时作业主体(署名应落「系统」)。
  555. */
  556. actor_user_id: string | null;
  557. /** 操作人姓名/展示名(服务端按 `bos_account_ext.display_name` 优先、未自填回落登录名现查;查无或系统主体为 `null`)。 */
  558. actor_name?: string | null;
  559. actor_role: string | null;
  560. note: string | null;
  561. at: string | null;
  562. };
  563. /** ⛔ 期望 `oss_key`:下载走 `material_grant`,服务端不外泄对象键。 */
  564. export type TicketMaterial = {
  565. material_id: string;
  566. kind: string | null;
  567. file_name: string | null;
  568. size_bytes: string | null;
  569. uploaded_by: string | null;
  570. uploaded_at: string | null;
  571. };
  572. export type ServiceItem = {
  573. item_id: string;
  574. seq_no: string;
  575. item_name: string | null;
  576. spec_text: string | null;
  577. /**
  578. * 升降配(`updown`)的参数对照(2026-11-17 补列):`spec_before`=原档位参数摘要、
  579. * `spec_after`=新档位参数摘要(回收行写「停用(截止新订阅生效前一日)」);其余类型两列为 null。
  580. */
  581. spec_before: string | null;
  582. spec_after: string | null;
  583. expect_qty: string | null;
  584. check_result: string | null;
  585. checked_at: string | null;
  586. checked_by: string | null;
  587. note: string | null;
  588. };
  589. /**
  590. * 竣工驳回记录(`ticket_completion_reject`,工单§5.5.3,U-115)。
  591. *
  592. * ⚠️ 出参里**没有** `external_reject_no`:设计方案§5.1 把它列为门户/合伙人⛔ 回显字段,
  593. * 服务端直接把它排除在 SELECT 之外,前端⛔ 指望"拿到再隐藏"。
  594. */
  595. export type CompletionReject = {
  596. reject_seq: string;
  597. channel: string;
  598. completion_no: string;
  599. primary_code: string;
  600. reason_codes: string;
  601. reason_text: string;
  602. pushed_at: string | null;
  603. rejected_at: string | null;
  604. };
  605. /** `reject@v1` 应答:`data` 平铺(工单§5.5.3)。 */
  606. export type CompletionRejectResult = {
  607. data: {
  608. ticket_id: string;
  609. ticket_no?: string;
  610. ticket_status: string;
  611. reject_seq: string;
  612. completion_no: string;
  613. primary_code: string;
  614. reason_codes: string[];
  615. completion_channel?: string;
  616. external_wait_seconds?: number | null;
  617. row_version?: number | null;
  618. pathway?: string;
  619. idempotent_replay?: boolean;
  620. message: string;
  621. };
  622. };
  623. /** 并单成员订阅(P1,`ticket_subscription`):只承载**本单交付**的附加订阅,平铺呈现。 */
  624. export type TicketMemberSubscription = {
  625. subscription_id: string;
  626. plan_name?: string | null;
  627. plan_family?: string | null;
  628. status?: string | null;
  629. /** 指向父链路订阅;非空即界面上标「叠加于 SUB-xxx」。 */
  630. parent_subscription_id?: string | null;
  631. };
  632. export type TicketDetail = { ticket: TicketHead;
  633. customer: {
  634. customer_id: string;
  635. customer_name: string | null;
  636. customer_code: string | null;
  637. contact_name: string | null;
  638. contact_mobile: string | null;
  639. address: string | null;
  640. } | null;
  641. order: {
  642. subscription_id: string;
  643. customer_id: string | null;
  644. plan_id?: string | null;
  645. plan_name: string | null;
  646. plan_kind: string | null;
  647. plan_family: string | null;
  648. sub_mode: string | null;
  649. line_exits: string | string[] | null;
  650. order_no: string | null;
  651. term: string | null;
  652. start_date: string | null;
  653. status: string | null;
  654. actual_opened_at: string | null;
  655. quantity?: string | number | null;
  656. quota_slots?: string | number | null;
  657. sub_account_quota?: string | number | null;
  658. bandwidth_up_mbps?: string | number | null;
  659. bandwidth_down_mbps?: string | number | null;
  660. bandwidth_committed?: string | boolean | null;
  661. replaces_subscription_id?: string | null;
  662. /** P1(D-9):本单主订阅若是增量叠加服务,这里指向它叠加的既有链路订阅。 */
  663. parent_subscription_id?: string | null;
  664. } | null;
  665. service_items: ServiceItem[];
  666. /**
  667. * P1(D-2/D-7):并单成员订阅(`ticket_subscription`,只装本单交付的附加订阅)。
  668. * 主订阅仍唯一落在 `order`;本数组**永远平铺**,附加成员靠 `parent_subscription_id` 标「叠加于」。
  669. */
  670. subscriptions?: TicketMemberSubscription[];
  671. open_stop: OpenStop | null;
  672. backfill: Backfill | null;
  673. completion: Completion | null;
  674. /** 驳回流水(旧→新)。门户/合伙人拿到的行集与运维侧同形,只是少了对外编号列。 */
  675. completion_rejects?: CompletionReject[];
  676. /** 「外部等待中」判据(工单§4.6 第六条):由服务端判,⛔ 前端用 `length > 0` 推导。 */
  677. reject_pending?: boolean;
  678. process_logs: ProcessLog[];
  679. materials: TicketMaterial[];
  680. messages: TicketMessage[];
  681. /** 缺口分组名(与 `required_groups` 同词典);空集=可出竣工 */
  682. gaps: string[];
  683. required_groups: string[];
  684. actions: Record<TicketActionKey, boolean>;
  685. read_advanced: boolean;
  686. /** 「卡在别人手里」的对家与催办读数(非 `completed`/客户侧恒 `null`)。 */
  687. waiting?: TicketWaiting | null;
  688. /** 施工指导只读包(套餐/变更对照/历史开通参数)。 */
  689. construction_guide?: ConstructionGuide | null;
  690. /** 服务端回填草稿(无则 null;PIN/CPID 只出是否已暂存)。 */
  691. backfill_draft?: BackfillDraft | null;
  692. };
  693. /** 套餐/订阅施工参考摘要。 */
  694. export type ConstructionPlanSummary = {
  695. subscription_id?: string | null;
  696. plan_id?: string | null;
  697. plan_name?: string | null;
  698. plan_kind?: string | null;
  699. plan_family?: string | null;
  700. quantity?: number | null;
  701. sub_account_quota?: number | null;
  702. quota_slots?: number | null;
  703. bandwidth_up_mbps?: number | null;
  704. bandwidth_down_mbps?: number | null;
  705. bandwidth_committed?: boolean | null;
  706. line_exits?: string[] | string | null;
  707. status?: string | null;
  708. parent_subscription_id?: string | null;
  709. replaces_subscription_id?: string | null;
  710. summary?: string | null;
  711. items?: ServiceItem[];
  712. };
  713. export type ConstructionGuideDefaults = {
  714. line_exits?: string[] | null;
  715. suggest_down_mbps?: number | null;
  716. suggest_up_mbps?: number | null;
  717. suggest_ip_bandwidth_mbps?: number | null;
  718. suggest_seat_count?: number | null;
  719. };
  720. export type PriorActivation = {
  721. ticket_id?: string | null;
  722. ticket_no?: string | null;
  723. actual_opened_date?: string | null;
  724. pin_bind_mode?: string | null;
  725. routes?: RouteRow[];
  726. ips?: IpRow[];
  727. ip_binds?: { backfill_ip_id?: string; sub_account_id?: string }[];
  728. };
  729. export type ConstructionGuide = {
  730. ticket_type?: string;
  731. plan?: ConstructionPlanSummary | null;
  732. member_plans?: ConstructionPlanSummary[];
  733. defaults?: ConstructionGuideDefaults | null;
  734. prior_activation?: PriorActivation | null;
  735. plan_before?: ConstructionPlanSummary | null;
  736. plan_after?: ConstructionPlanSummary | null;
  737. };
  738. export type BackfillDraft = {
  739. ticket_id?: string;
  740. exec_conclusion?: string | null;
  741. conclusion_note?: string | null;
  742. actual_opened_date?: string | null;
  743. stop_done_date?: string | null;
  744. evidence_text?: string | null;
  745. pin_bind_mode?: string | null;
  746. route_rows?: BackfillInRoute[] | null;
  747. ip_rows?: Array<Partial<BackfillInIp> & { pin_registered?: string; cpid_registered?: string }> | null;
  748. ext_values?: Record<string, unknown> | null;
  749. ext_template_id?: string | null;
  750. ext_template_version?: string | number | null;
  751. evidence_material_ids?: string[] | null;
  752. check_item_ids?: string[] | null;
  753. check_note?: string | null;
  754. row_version?: string | number;
  755. updated_at?: string | null;
  756. };
  757. /* ══════════════ 写侧入参/出参 ══════════════ */
  758. /** 建单携带的材料:只有 `oss_key`(已直传、未登记),服务端补 file_name/size。 */
  759. export type CreateMaterialIn = { oss_key: string };
  760. export type TicketCreateResult = {
  761. ticket_id: string;
  762. ticket_no: string;
  763. status: TicketStatus;
  764. assign_team_id: string | null;
  765. /** 随单登记的材料条数(2026-11-18 起建单不再有「同类未完成并入」分支) */
  766. materials?: number;
  767. };
  768. export type AssignResult = {
  769. ticket_id: string;
  770. assignee_user_id: string;
  771. assignee_snapshot_name: string;
  772. status: TicketStatus;
  773. };
  774. /** 自动分派回执(create.rs dispatch_auto_inner):dispatched/skipped 是明细数组,不是计数。 */
  775. export type DispatchedTicket = {
  776. ticket_id: string;
  777. ticket_no: string | null;
  778. assignee_user_id: string;
  779. assignee_snapshot_name: string | null;
  780. };
  781. export type DispatchSkipped = {
  782. ticket_id: string;
  783. ticket_no?: string | null;
  784. /** no_candidate=无合适成员;already_taken=并发下已被他人分派 */
  785. reason: string;
  786. message?: string;
  787. };
  788. export type DispatchResult = {
  789. team_id: string;
  790. scanned: number;
  791. dispatched: DispatchedTicket[];
  792. skipped: DispatchSkipped[];
  793. };
  794. export type DelegateResult = {
  795. ticket_id: string;
  796. assignee_user_id: string;
  797. assignee_snapshot_name: string;
  798. delegate_from_user_id: string;
  799. delegated_at: string;
  800. status: TicketStatus;
  801. };
  802. export type StartResult = {
  803. ticket_id: string;
  804. advanced: boolean;
  805. status: TicketStatus;
  806. /** `advanced:false` 时后端回的原因:非责任人/已被推进/并发。 */
  807. reason?: "not_assignee" | "already_advanced" | "concurrent";
  808. advanced_at?: string;
  809. audit_written?: boolean;
  810. };
  811. export type BackfillInRoute = {
  812. sub_account_id?: string | null;
  813. network_account_name?: string | null;
  814. intranet_ip?: string | null;
  815. subnet_mask?: string | null;
  816. gateway?: string | null;
  817. vlan?: string | null;
  818. tunnel_encap?: string | null;
  819. vni?: string | null;
  820. src_endpoint?: string | null;
  821. dst_endpoint?: string | null;
  822. egress_pop?: string | null;
  823. down_mbps?: number | null;
  824. up_mbps?: number | null;
  825. proxy_host?: string | null;
  826. proxy_port?: number | null;
  827. pin?: string | null;
  828. cpid?: string | null;
  829. require_cpid?: boolean | null;
  830. share_credential_of?: string | null;
  831. open_this_time: boolean;
  832. };
  833. export type BackfillInIp = {
  834. egress?: string | null;
  835. overseas_ip?: string | null;
  836. ip_type?: string | null;
  837. bandwidth_mbps?: number | null;
  838. pin?: string | null;
  839. cpid?: string | null;
  840. /** P1(D-14):行级动作,缺省 `allocate`;换绑单的旧 IP 行填 `release`。 */
  841. action?: "allocate" | "release";
  842. /** P1(D-4):该 IP 映射的分账号(`fixed_ip` 恒 1 个、`nat_forward` 至少 1 个)。 */
  843. sub_account_ids?: string[];
  844. };
  845. export type BackfillResult = {
  846. ticket_id: string;
  847. backfill_id: string;
  848. exec_conclusion: string;
  849. route_rows: number;
  850. ip_rows: number;
  851. ip_rule_version: string;
  852. open_stop_id: string | null;
  853. effective_account_count: number;
  854. apply_facts: unknown;
  855. status: TicketStatus;
  856. status_advanced: boolean;
  857. /** 仍缺的分组名:非空 ⇒ 已保存但未达闭环口径(页面点名,⛔ 报"保存失败") */
  858. missing_groups: string[];
  859. audit_written: boolean;
  860. };
  861. export type CheckDoneResult = {
  862. ticket_id: string;
  863. all_done: boolean;
  864. pending_rows: number;
  865. missing_item_ids: string[];
  866. audit_written: boolean;
  867. };
  868. export type MarkDoneResult = {
  869. ticket_id: string;
  870. status: TicketStatus;
  871. completed_at: string;
  872. biz_date: string;
  873. audit_written: boolean;
  874. };
  875. export type FinalizeResult = {
  876. ticket_id: string;
  877. status: TicketStatus;
  878. closed_at?: string;
  879. open_stop_closed?: boolean;
  880. settled_at?: string;
  881. defer_scope?: string;
  882. deferred_until?: string;
  883. reverted_from?: string;
  884. untouched?: string[];
  885. audit_written: boolean;
  886. };
  887. export type CompletionGenerateResult = {
  888. ticket_id: string;
  889. ticket_status: TicketStatus;
  890. completion_id: string;
  891. completion_no: string;
  892. action: string;
  893. exec_conclusion: string;
  894. mode: string;
  895. pushed_at: string;
  896. pushed_by: string;
  897. pushed_by_name: string | null;
  898. ip_rule_version: string;
  899. pdf_oss_key: string | null;
  900. reissued: boolean;
  901. receipt_valid: boolean;
  902. audit_written: boolean;
  903. next_step: string;
  904. };
  905. export type CompletionReceiptResult = {
  906. ticket_id: string;
  907. ticket_status: TicketStatus;
  908. completion_no: string | null;
  909. receipt_at: string;
  910. receipt_user_id: string;
  911. receipt_user_name: string | null;
  912. settled_at: string;
  913. completed_at: string;
  914. audit_written: boolean;
  915. next_step: string;
  916. };
  917. export type MessageActionResult = {
  918. message_id: string;
  919. status: string;
  920. ticket_id: string;
  921. audit_written: boolean;
  922. next_step: string;
  923. };
  924. /** 上传分支:服务端派生的对象键与前缀(直传完成后必须原样交给 `material_attach`)。 */
  925. export type MaterialGrantUpload = {
  926. purpose: "upload";
  927. kind: string;
  928. ticket_id: string;
  929. ticket_status: TicketStatus;
  930. file_name: string;
  931. oss_key: string;
  932. prefix: string;
  933. presign_endpoint: string;
  934. bucket: string;
  935. size_limit_bytes: number;
  936. next_step: string;
  937. };
  938. /** 下载分支:⚠️ 对象键⛔ 下发,只给一条平台现签的短时效地址。 */
  939. export type MaterialGrantDownload = {
  940. purpose: "download";
  941. material_id: string;
  942. kind: string;
  943. ticket_id: string;
  944. ticket_status: TicketStatus;
  945. file_name: string;
  946. download_url: string;
  947. expires_at: string | null;
  948. };
  949. export type MaterialGrantResult = MaterialGrantUpload | MaterialGrantDownload;
  950. export type MaterialAttachResult = {
  951. ticket_id: string;
  952. material_id: string;
  953. kind: string;
  954. file_name: string;
  955. size_bytes: string | null;
  956. audit_written: boolean;
  957. next_step: string;
  958. };
  959. export type ClosureConfig = {
  960. closure_mode: string;
  961. closure_mode_name: string;
  962. row_version: string;
  963. updated_at: string | null;
  964. updated_by: string | null;
  965. };
  966. export type ClosureConfigUpdateResult = {
  967. closure_mode: string;
  968. changed: boolean;
  969. /** 同档提交(changed=false)时服务端不回此键 */
  970. from?: string;
  971. row_version: number;
  972. updated_by: string;
  973. audit_written: boolean;
  974. next_step: string;
  975. };
  976. /* ══════════════ 工具 ══════════════ */
  977. /** 后端 `::text` 投影出来的布尔列(`"true"`/`"false"`/`"t"`/`"f"`)。列表页的真布尔走原值。 */
  978. export function isYes(v: unknown): boolean {
  979. if (typeof v === "boolean") return v;
  980. const s = `${v ?? ""}`.trim().toLowerCase();
  981. return s === "true" || s === "t" || s === "1" || s === "yes";
  982. }
  983. /** 乐观并发两种拼写并存:`handle`/`finalize` 族=`expected_version`,`completion`/`message`/`config` 族=`expect_version`。 */
  984. const q = (o: Record<string, string | number | undefined | null>) =>
  985. Object.entries(o)
  986. .filter(([, v]) => v !== undefined && v !== null && `${v}` !== "")
  987. .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
  988. .join("&");
  989. /* ══════════════ §6.1 读侧(7) ══════════════ */
  990. /** 工单列表 [实]。分页 **1 基**(`page_norm`),UI 页码直接透传。 */
  991. export const ticketList = (d: {
  992. ticket_types?: string[];
  993. statuses?: string[];
  994. /** 回填来源三值:manual/unicom_feedback/mixed */
  995. sources?: string[];
  996. date_from?: string;
  997. date_to?: string;
  998. keyword?: string;
  999. /** 订阅(订阅)过滤:订阅详情「关联工单」按本条订阅现查(P3-D6)。 */
  1000. subscription_id?: string;
  1001. /** 合同过滤:合同详情「关联工单」按合同下订阅集合现查(P3-D7)。 */
  1002. contract_id?: string;
  1003. /** 客户过滤:客户维度的工单台账。 */
  1004. customer_id?: string;
  1005. /**
  1006. * 责任人过滤:**只有 `me` 一个取值**(服务端按会话解析,⛔ 收任意 user_id)。
  1007. * 「我的待办」靠它把可见行集收窄到本人名下——运维成员的可见性本来就是本人,
  1008. * 运营账号/团队主/总运营则是「先按可见范围取并集再筛本人」。
  1009. */
  1010. assignee?: string;
  1011. page?: number;
  1012. page_size?: number;
  1013. }) => list<TicketListResult>("/ticket/list@v1", d, d);
  1014. /** 工单详情定位入参 [实] —— 二选一(都给以 `ticket_id` 为准)。
  1015. *
  1016. * 客户门户⛔ 在 URL 里出现内部主键,故列表只回 `ticket_no`、详情按业务工单号定位;
  1017. * 运营侧仍走 `ticket_id`(台账/队列/待办页手上有主键)。 */
  1018. export type TicketDetailIn = { ticket_id?: string; ticket_no?: string; read_event?: boolean };
  1019. /** 工单详情 [实] —— GET;`read_event=true` 才推进 pending→processing(终态返 KLT-G20401)。 */
  1020. export const ticketDetail = (d: TicketDetailIn) =>
  1021. get<TicketDetail>(
  1022. `/ticket/detail@v1?${q({
  1023. ticket_id: d.ticket_id,
  1024. ticket_no: d.ticket_no,
  1025. read_event: d.read_event ? "true" : undefined,
  1026. })}`,
  1027. );
  1028. /** 待分派队列 [实] —— 逐行带 `candidates[]`(可分派候选人+手头量)。 */
  1029. export const ticketPendingQueue = (d?: {
  1030. ticket_types?: string[];
  1031. assign_team_id?: string;
  1032. keyword?: string;
  1033. page?: number;
  1034. page_size?: number;
  1035. }) => list<PendingQueueResult>("/ticket/pending_queue@v1", d, d);
  1036. /** 六档待办计数 [实] —— 红点/徽标唯一来源。 */
  1037. export const ticketTodoCounts = () => get<TodoCounts>("/ticket/todo_counts@v1");
  1038. /** 全链路追溯 [实] —— GET,四键至少一键(工单号/订单号/竣工单号/ticket_id)。 */
  1039. export const ticketTrace = (d: TraceIn) => get<TraceResult>(`/ticket/trace@v1?${q({ ...d })}`);
  1040. /** 报文待处置清单 [实] —— 仅 `unmatched`/`conflict`。 */
  1041. export const messagePending = (d?: { page?: number; page_size?: number; status?: string }) =>
  1042. list<MessagePendingResult>("/message/pending@v1", d, d);
  1043. /* ══════════════ §6.2 建单与分派(4) ══════════════ */
  1044. /**
  1045. * 建单 [实] —— 客户侧/运营侧同一口,`submitter_type` 由服务端按身份定。
  1046. * `ticket_type` 收 `fault`/`after_sale`/`service_stop`(create.rs `CREATE_TYPES`,
  1047. * 2026-11-14 起「运营人工发起服务停用」也挂本口=工单§3.2.1);`title` 必填(≤128 字)。
  1048. * `service_stop` 必带 `subscription_id` + `confirm:true`(二次确认),服务端同批登记
  1049. * `ticket_open_stop`(`action=stop`、`exec_status=pending`),实际停机由回填执行。
  1050. * 客户侧 ⛔ 带 `customer_id`(由会话派生);总运营必带;材料键须先落在
  1051. * `提交材料/{customer_id}/` 前缀下——该前缀 ⛔ 在建单前取到(`material_grant` 要 `ticket_id`),
  1052. * 所以门户建单 ⛔ 挂 attachments 假上传,材料在建单后走 `material_grant`+`material_attach`。
  1053. */
  1054. export const ticketCreate = (d: {
  1055. ticket_type: string;
  1056. customer_id?: string;
  1057. title: string;
  1058. detail?: string;
  1059. subscription_id?: string;
  1060. /** 仅 `service_stop` 用:人工发起停用的二次确认位,⛔ 由服务端默认放行。 */
  1061. confirm?: boolean;
  1062. materials?: CreateMaterialIn[];
  1063. }) => post<TicketCreateResult>("/ticket/create@v1", d);
  1064. /** 人工分派 [实] —— 候选人来自 `pending_queue` 行内 `candidates[]`。 */
  1065. export const ticketAssign = (d: { ticket_id: string; assignee_user_id: string }) =>
  1066. post<AssignResult>("/ticket/assign@v1", d);
  1067. /** 自动分派 [实] —— 按团队批量。 */
  1068. export const ticketDispatchAuto = (d: { team_id: string }) =>
  1069. post<DispatchResult>("/ticket/dispatch_auto@v1", d);
  1070. /** 转交代管 [实] —— 责任人本人把单交给同事代管。 */
  1071. export const ticketDelegate = (d: { ticket_id: string; trustee_user_id: string }) =>
  1072. post<DelegateResult>("/ticket/delegate@v1", d);
  1073. /* ══════════════ §6.3 处理推进与回填(5) ══════════════ */
  1074. /** 阅读推进 [实]——由详情口 `read_event=true` 内部调用,**无人工按钮**(工单§4.1.4,2026-11-04 定案)。 */
  1075. export const ticketStart = (d: { ticket_id: string }) => post<StartResult>("/ticket/start@v1", d);
  1076. /** 施工回填 [实] —— 停机类只录组四五项(契约 14.2),`route_rows`/`ip_rows` 传空数组。 */
  1077. export const ticketBackfill = (d: {
  1078. ticket_id: string;
  1079. exec_conclusion?: string;
  1080. conclusion_note?: string;
  1081. actual_opened_date?: string;
  1082. stop_done_date?: string;
  1083. builder_user_id?: string;
  1084. evidence_text?: string;
  1085. pin_bind_mode?: "shared" | "per_account";
  1086. route_rows?: BackfillInRoute[];
  1087. ip_rows?: BackfillInIp[];
  1088. check_item_ids?: string[];
  1089. check_note?: string;
  1090. evidence_material_ids?: string[];
  1091. expected_version?: number;
  1092. /** 扩展表单;省略=不改已有 ext;无 published 模板时后端忽略。 */
  1093. ext?: {
  1094. template_id?: string;
  1095. template_version?: number;
  1096. values?: Record<string, unknown>;
  1097. };
  1098. }) => post<BackfillResult>("/ticket/backfill@v1", d);
  1099. /** 回填草稿暂存 [实] —— 不触发开停生效/状态推进。 */
  1100. export const ticketBackfillDraft = (d: {
  1101. ticket_id: string;
  1102. exec_conclusion?: string;
  1103. conclusion_note?: string;
  1104. actual_opened_date?: string;
  1105. stop_done_date?: string;
  1106. evidence_text?: string;
  1107. pin_bind_mode?: "shared" | "per_account";
  1108. route_rows?: BackfillInRoute[];
  1109. ip_rows?: BackfillInIp[];
  1110. check_item_ids?: string[];
  1111. check_note?: string;
  1112. evidence_material_ids?: string[];
  1113. expected_version?: number;
  1114. ext?: {
  1115. template_id?: string;
  1116. template_version?: number;
  1117. values?: Record<string, unknown>;
  1118. };
  1119. }) => post<{ ticket_id: string; row_version: number; pin_bind_mode: string; saved: boolean }>(
  1120. "/ticket/backfill_draft@v1",
  1121. d,
  1122. );
  1123. /**
  1124. * 扩展模板可读类型(与后端 FORM_TICKET_TYPES 同源)。
  1125. * 合同对照:new→open;expand→service_open;change→updown;停机两类非合同驱动。
  1126. */
  1127. export const FORM_TEMPLATE_TICKET_TYPES = [
  1128. "open",
  1129. "service_open",
  1130. "updown",
  1131. "expiry_stop",
  1132. "service_stop",
  1133. ] as const;
  1134. /** 施工回填扩展模板 get [实]。 */
  1135. export const formTemplateGet = (ticket_type?: string) =>
  1136. get<{ items: FormTemplateBundle[] }>(
  1137. ticket_type
  1138. ? `/ticket/form_template_get@v1?ticket_type=${encodeURIComponent(ticket_type)}`
  1139. : "/ticket/form_template_get@v1",
  1140. );
  1141. /** 保存扩展模板草稿 [实](仅 admin)。 */
  1142. export const formTemplateSave = (d: {
  1143. ticket_type: string;
  1144. schema: FormSchema;
  1145. expect_version?: number;
  1146. template_id?: string;
  1147. }) => post<{ template_id: string; row_version: string | number; status: string }>("/ticket/form_template_save@v1", d);
  1148. /** 发布扩展模板 [实](仅 admin;必填变更须 ack_required_change)。 */
  1149. export const formTemplatePublish = (d: {
  1150. ticket_type: string;
  1151. template_id: string;
  1152. expect_version: number;
  1153. ack_required_change?: boolean;
  1154. }) =>
  1155. post<{ template_id: string; version: number | string; status: string; row_version: string | number }>(
  1156. "/ticket/form_template_publish@v1",
  1157. d,
  1158. );
  1159. /** 服务开通条目核对 [实]。 */
  1160. export const ticketCheckDone = (d: {
  1161. ticket_id: string;
  1162. item_ids?: string[];
  1163. note?: string;
  1164. /** 实际开通日(服务开通单三件套之一;服务开通单没有回填弹窗,这一列随核对登记)。 */
  1165. actual_opened_date?: string;
  1166. expected_version?: number;
  1167. /** 扩展表单;服务开通/变更协议核对同批;省略=不改已有。 */
  1168. ext?: {
  1169. template_id?: string;
  1170. template_version?: number;
  1171. values?: Record<string, unknown>;
  1172. };
  1173. }) => post<CheckDoneResult>("/ticket/check_done@v1", d);
  1174. /** 非主线单标记完成 [实]。 */
  1175. export const ticketMarkDone = (d: { ticket_id: string; note?: string; expected_version?: number }) =>
  1176. post<MarkDoneResult>("/ticket/mark_done@v1", d);
  1177. /* ══════════════ §6.4 终态收口与退回重办(5) ══════════════ */
  1178. /** 关闭/作废 [实]。 */
  1179. export const ticketClose = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
  1180. post<FinalizeResult>("/ticket/close@v1", d);
  1181. /** 客户侧撤回并关闭 [实]。 */
  1182. export const ticketWithdraw = (d: { ticket_id: string; reason?: string }) =>
  1183. post<FinalizeResult>("/ticket/withdraw@v1", d);
  1184. /** 非主线单客户侧闭环确认 [实]。 */
  1185. export const ticketConfirmClose = (d: { ticket_id: string; expected_version?: number }) =>
  1186. post<FinalizeResult>("/ticket/confirm_close@v1", d);
  1187. /** 延期提醒 [实] —— 载体两档:`open_stop`(开停记录)/`ticket`(工单本身);期限由服务端按超期天数推进。 */
  1188. export const ticketDefer = (d: { ticket_id: string; defer_scope?: "open_stop" | "ticket" }) =>
  1189. post<FinalizeResult>("/ticket/defer@v1", d);
  1190. /** 退回重办(总运营 ∨ 该单承接团队的主账号,2026-11-22 改判;原名「受控回退」,2026-11-18 更名) [实]。
  1191. *
  1192. * ⚠️ 只对 `completed`(已完成待确认)/`rejected`(竣工驳回)开放;`settled`(已办结)
  1193. * 是终态只读,服务端回 `KLT-G20418`——改历史走人工数据变更+审计。 */
  1194. export const ticketRevert = (d: { ticket_id: string; reason?: string; expected_version?: number }) =>
  1195. post<FinalizeResult>("/ticket/revert@v1", d);
  1196. /**
  1197. * 站内催办 [实](2026-11-18,需求§7.5.2)——向「卡在别人手里」的对家投递一封催办信。
  1198. *
  1199. * 收件人/信体/业务日一律服务端取(⛔ 传 `to_user_id`:那等于开了任意发信通路)。
  1200. * **一单一天一封**:同一业务日重复调用回 `created=false`/`reason=already_sent_today`
  1201. * ——那是**幂等成功**,UI 按「今日已催」呈现,⛔ 报错。
  1202. * 前置不满足(非 `completed`/未满 24 小时/对家=本人)回 `KLT-G20424`,`detail.reason`
  1203. * 与 `waiting.urge.reason` 同词典。
  1204. */
  1205. export type TicketUrgeResult = {
  1206. ticket_id: string;
  1207. /** `true`=本轮真的投递了一封;`false`=当日已发过(幂等去重)或并发已投。 */
  1208. created: boolean;
  1209. reason: string | null;
  1210. message_id?: string | null;
  1211. business_date: string;
  1212. counterparty?: { user_id: string; name: string; role: string; org_name: string | null };
  1213. waiting: TicketWaiting;
  1214. audit_written?: boolean;
  1215. next_step: string;
  1216. };
  1217. export const ticketUrge = (d: { ticket_id: string }) =>
  1218. post<TicketUrgeResult>("/ticket/urge@v1", d);
  1219. /* ══════════════ §6.5 竣工回传与回执(2) ══════════════ */
  1220. /** 生成并回传竣工 [实] —— 缺口未清 ⇒ 服务端硬拦。 */
  1221. export const completionGenerate = (d: { ticket_id: string }) =>
  1222. post<CompletionGenerateResult>("/completion/generate@v1", d);
  1223. /** 回执确认闭环 [实] —— 仅 admin/该团队主账号。 */
  1224. export const completionReceipt = (d: {
  1225. ticket_id: string;
  1226. completion_no?: string;
  1227. external_order_no?: string;
  1228. receipt_remark?: string;
  1229. expect_version?: number;
  1230. /** 驳回态冲突纠正(设计方案§3.3):**仅 admin** 生效,非驳回态传了也⛔ 改变任何行为。 */
  1231. override_state_conflict?: boolean;
  1232. }) => post<CompletionReceiptResult>("/completion/receipt@v1", d);
  1233. /**
  1234. * 竣工驳回理由七枚(工单§5.5.3 批复④),**顺序=后端 `domain::REJECT_REASONS` 定义序**。
  1235. *
  1236. * ⚠️ 顺序有语义:服务端按本表下标归一化后落库,**主原因=归一化首位**(下标最小的那枚),
  1237. * ⛔ 把"用户先点的那枚"当主原因——同一次勾选无论怎么点主原因都相同,报表「主原因分布」
  1238. * 才不会被排列组合劈成几条(驳回抽屉的预览按这条口径回显)。
  1239. */
  1240. export const REJECT_REASONS: { code: string; name: string }[] = [
  1241. { code: "doc_mismatch", name: "资料不符" },
  1242. { code: "resource_unavailable", name: "端口或IP资源不可用" },
  1243. { code: "duplicate", name: "重复申报" },
  1244. { code: "out_of_scope", name: "超出受理范围" },
  1245. { code: "doc_missing", name: "竣工资料缺失" },
  1246. { code: "site_not_ready", name: "现场不具备条件" },
  1247. { code: "other", name: "其他" },
  1248. ];
  1249. /** 一次驳回的枚数上限(`1 ≤ n ≤ 3`,超限/空选 ⇒ `KLT-G20422`)。 */
  1250. export const REJECT_REASON_MAX = 3;
  1251. /** 归一化主原因(本表下标最小者);未勾选回空串。 */
  1252. export const rejectPrimaryReason = (codes: string[]) =>
  1253. REJECT_REASONS.find((r) => codes.includes(r.code))?.name ?? "";
  1254. /** 登记竣工驳回 [实](工单§5.5.3,U-115)——重复提交命中幂等回 `KLT-G20421`+既有 seq。 */
  1255. export const completionReject = (d: {
  1256. ticket_id: string;
  1257. reason_codes: string[];
  1258. reason_text: string;
  1259. external_reject_no?: string;
  1260. }) => post<CompletionRejectResult>("/completion/reject@v1", d);
  1261. /* ══════════════ §6.6 报文人工处置(4) ══════════════ */
  1262. /** 报文关联到工单 [实]。 */
  1263. export const messageAttach = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
  1264. post<MessageActionResult>("/message/attach@v1", d);
  1265. /** 报文作废 [实] —— `void_reason` 服务端必填(缺失 ⇒ KLT-G20412),⛔ 空串提交。 */
  1266. export const messageVoid = (d: { message_id: string; void_reason?: string; expect_version?: number }) =>
  1267. post<MessageActionResult>("/message/void@v1", d);
  1268. /** 冲突确认 [实] —— `as_is`=以现状为准归档(默认)/`apply_external`=按报文外部值生效。 */
  1269. export const messageConfirmConflict = (d: {
  1270. message_id: string;
  1271. disposition?: "as_is" | "apply_external";
  1272. note?: string;
  1273. expect_version?: number;
  1274. }) => post<MessageActionResult>("/message/confirm_conflict@v1", d);
  1275. /** 报文改绑到另一单 [实]。 */
  1276. export const messageRematch = (d: { message_id: string; ticket_id: string; expect_version?: number }) =>
  1277. post<MessageActionResult>("/message/rematch@v1", d);
  1278. /* ══════════════ §6.7 材料直传(2) ══════════════ */
  1279. /** 申请直传凭证 [实] —— 拿 `oss_key` 后到 `presign_endpoint` 换签名直传,再 `material_attach` 登记。 */
  1280. export const ticketMaterialGrant = (d: {
  1281. ticket_id: string;
  1282. kind: string;
  1283. file_name?: string;
  1284. purpose?: "upload" | "download";
  1285. material_id?: string;
  1286. oss_key?: string;
  1287. }) => post<MaterialGrantResult>("/ticket/material_grant@v1", d);
  1288. /**
  1289. * 换一条材料下载地址 [实]。
  1290. *
  1291. * `detail@v1` 刻意不下发对象键 ⇒ 页面只能按 `material_id` 现签;签名由服务端向平台取,
  1292. * ⛔ 不经浏览器拼路径、⛔ 缓存地址(短时效)。
  1293. */
  1294. export const ticketMaterialDownload = (d: { ticket_id: string; kind: string; material_id: string }) =>
  1295. post<MaterialGrantDownload>("/ticket/material_grant@v1", {
  1296. ticket_id: d.ticket_id,
  1297. kind: d.kind,
  1298. material_id: d.material_id,
  1299. purpose: "download",
  1300. });
  1301. /** 登记已直传材料 [实]。 */
  1302. export const ticketMaterialAttach = (d: {
  1303. ticket_id: string;
  1304. kind: string;
  1305. oss_key: string;
  1306. file_name?: string;
  1307. size_bytes?: number;
  1308. }) => post<MaterialAttachResult>("/ticket/material_attach@v1", d);
  1309. /* ══════════════ §6.8 闭环方式配置(2) ══════════════ */
  1310. /** 读闭环方式 [实] —— 仅运营侧三类;交付侧 11104。 */
  1311. export const ticketConfigGet = () => get<ClosureConfig>("/ticket/config_get@v1");
  1312. /** 改闭环方式 [实] —— 仅总运营;`reason` 必填进审计。 */
  1313. export const ticketConfigUpdate = (d: { closure_mode: string; expect_version?: number; reason?: string }) =>
  1314. post<ClosureConfigUpdateResult>("/ticket/config_update@v1", d);