326 lines
11 KiB
TypeScript
326 lines
11 KiB
TypeScript
// api/record.ts Day 53(D24):下行批次记录接口(契约先行,Day60 record API 前由
|
|
// msw mock 承载——FE 全程不被后端阻塞;后端实现须按本契约回填 api/v1/record.go)。
|
|
import { get, post } from './request'
|
|
|
|
/** 下行批次行(message_task 聚合口径;进度四态+发送中=mobile_count)。
|
|
* intercepted_count 为 message_detail status=5 聚合计数(后端 Day60 实现)。 */
|
|
export interface DownRecord {
|
|
id: number
|
|
task_no: string
|
|
send_type: number // 1群发 2个性 3定时 4文件
|
|
sign: string
|
|
content: string
|
|
mobile_count: number
|
|
success_count: number
|
|
fail_count: number
|
|
unknown_count: number
|
|
intercepted_count: number
|
|
sending_count: number // 待发+提交中(0待发1提交)
|
|
fee_total: number
|
|
audit_status: number // 0待 1过 2拒 3免审 4超时
|
|
status: number // 0待发 1进行中 2完成 3失败 4已取消
|
|
created_at: string
|
|
finished_at: string | null
|
|
}
|
|
|
|
/** 下行批次列表查询参数(分页 100/页为验收口径)。 */
|
|
export interface DownQuery {
|
|
page: number
|
|
page_size: number
|
|
task_no?: string
|
|
send_type?: number
|
|
status?: number
|
|
start_time?: string
|
|
end_time?: string
|
|
}
|
|
|
|
export interface DownPage {
|
|
list: DownRecord[]
|
|
total: number
|
|
}
|
|
|
|
/** 下行批次分页列表。 */
|
|
export function fetchDownRecords(q: DownQuery): Promise<DownPage> {
|
|
return get<DownPage>('/record/down', { ...q })
|
|
}
|
|
|
|
/** 拦截号码下载(CSV:mobile,error_code,reason;无拦截时后端返回 404 业务码)。
|
|
* 原生 fetch 直取(不走 axios XHR——jsdom XHR+blob 与 msw 拦截层不兼容,
|
|
* 同 fe2 multipart 坑;真实浏览器两条路径等价)。失败时抛 BizError 同构 Error。 */
|
|
export async function downloadIntercepted(taskId: number): Promise<Blob> {
|
|
const base = import.meta.env.VITE_API_BASE_URL as string
|
|
const resp = await fetch(`${base}/record/down/${taskId}/intercepted?format=csv`, {
|
|
headers: { Accept: 'text/csv' },
|
|
})
|
|
const ct = resp.headers.get('content-type') ?? ''
|
|
if (!resp.ok || ct.includes('application/json')) {
|
|
// 404 业务码:{code,msg}(无拦截/任务不存在)
|
|
const body = (await resp.json().catch(() => null)) as { code?: string; msg?: string } | null
|
|
throw new Error(body?.msg ?? `下载失败 HTTP:${resp.status}`)
|
|
}
|
|
return resp.blob()
|
|
}
|
|
|
|
/** 进度占比工具已拆至 record-progress.ts(无 request 依赖,mock 安全引用);此处 re-export 保持既有 import 兼容。 */
|
|
export { progressOf } from './record-progress'
|
|
|
|
/** 拦截明细行(下载预览/测试断言用)。 */
|
|
export interface InterceptedRow {
|
|
mobile: string
|
|
error_code: string
|
|
reason: string
|
|
}
|
|
|
|
// ---- D25 下行明细(号码级,5 天热数据;契约先行,mock 承载,Day60 后端回填) ----
|
|
|
|
/** 号码级明细行(message_detail 口径,与 D22 SendDetail 同构+task_no 冗余便于全局检索)。 */
|
|
export interface DownDetail {
|
|
id: number
|
|
task_id: number
|
|
task_no: string
|
|
mobile: string
|
|
province: string
|
|
carrier: string // 移动/联通/电信
|
|
status: number // 0待发 1已提交 2成功 3失败 4未知 5拦截
|
|
error_code: string // ISC:xxx/通道原始码(空=成功)
|
|
ext_code: string
|
|
call_data: string
|
|
fee: number
|
|
created_at: string
|
|
}
|
|
|
|
/** 明细查询参数(5 天热数据窗口由后端保证;分页 100/页与批次口径一致)。 */
|
|
export interface DownDetailQuery {
|
|
page: number
|
|
page_size: number
|
|
mobile?: string // 模糊(尾号匹配)
|
|
task_no?: string // 精确(批次钻入预填)
|
|
status?: number
|
|
error_code?: string // 精确(ISC 码筛选联调)
|
|
start_time?: string
|
|
end_time?: string
|
|
}
|
|
|
|
export interface DownDetailPage {
|
|
list: DownDetail[]
|
|
total: number
|
|
}
|
|
|
|
/** 号码级明细分页(D25)。 */
|
|
export function fetchDownDetails(q: DownDetailQuery): Promise<DownDetailPage> {
|
|
return get<DownDetailPage>('/record/down/details', { ...q })
|
|
}
|
|
|
|
/** 通道侧交互记录(CMPP 钻入:channel_log 按 detail 检索)。 */
|
|
export interface ChannelLogEntry {
|
|
at: string
|
|
kind: string // connect/submit/deliver/reclaim…
|
|
level: number // 0 info/1 warn/2 error
|
|
msg_id: string
|
|
detail: string
|
|
latency_ms: number
|
|
}
|
|
|
|
/** CMPP/通道日志钻入(D25;拦截号未投通道→空列表)。 */
|
|
export function fetchDetailChannelLogs(detailId: number): Promise<{ total: number; list: ChannelLogEntry[] }> {
|
|
return get<{ total: number; list: ChannelLogEntry[] }>(`/record/down/details/${detailId}/channel-logs`)
|
|
}
|
|
|
|
// ---- D26 历史记录(>5 天全量,ClickHouse 冷数据;契约先行,Day61 后端回填) ----
|
|
|
|
/** 历史明细行(冷数据口径:与 DownDetail 同构+终态锁定,无进行中态)。 */
|
|
export interface HistoryRecord {
|
|
id: number
|
|
task_id: number
|
|
task_no: string
|
|
mobile: string
|
|
province: string
|
|
carrier: string
|
|
status: number // 冷数据仅终态:2成功/3失败/4未知/5拦截
|
|
error_code: string
|
|
fee: number
|
|
created_at: string
|
|
}
|
|
|
|
/** 历史查询参数(时间范围为冷数据主索引;后端 ClickHouse 分区裁剪,mock 同语义)。 */
|
|
export interface HistoryQuery {
|
|
page: number
|
|
page_size: number
|
|
mobile?: string
|
|
task_no?: string
|
|
status?: number
|
|
start_time?: string
|
|
end_time?: string
|
|
}
|
|
|
|
export interface HistoryPage {
|
|
list: HistoryRecord[]
|
|
total: number
|
|
}
|
|
|
|
/** 全量历史明细分页(D26;查询 <3s 验收)。 */
|
|
export function fetchHistoryRecords(q: HistoryQuery): Promise<HistoryPage> {
|
|
return get<HistoryPage>('/record/history', { ...q })
|
|
}
|
|
|
|
/** 异步导出任务(D26;状态机 pending→ready/failed,完成后下载中心取件)。 */
|
|
export interface ExportTask {
|
|
id: number
|
|
scope: string // 导出范围描述(筛选条件快照)
|
|
status: 'pending' | 'ready' | 'failed'
|
|
total: number // 匹配行数(ready 时)
|
|
created_at: string
|
|
expires_at: string // 下载链接有效期(默认 24h)
|
|
}
|
|
|
|
/** 提交异步导出(当前筛选条件快照;返回任务号,轮询下载中心)。 */
|
|
export function createHistoryExport(q: Omit<HistoryQuery, 'page' | 'page_size'>): Promise<{ id: number }> {
|
|
return post<{ id: number }>('/record/history/export', { ...q })
|
|
}
|
|
|
|
/** 下载中心:导出任务列表(D26;Day62 MinIO 落地后切真实下载)。 */
|
|
export function fetchHistoryExports(): Promise<{ list: ExportTask[] }> {
|
|
return get<{ list: ExportTask[] }>('/record/history/exports')
|
|
}
|
|
|
|
// ---- D27 上行记录(message_uplink 口径;契约先行,mock 承载,Day60 后端回填) ----
|
|
|
|
/** 上行记录行(message_uplink:Deliver MO→码号分配→落库;Day49 后端已交付)。 */
|
|
export interface UplinkRecord {
|
|
id: number
|
|
dest_code: string // 接入码号(归属分配依据:精确>前缀>admin 兜底)
|
|
src_mobile: string // 上行来源手机号
|
|
content: string
|
|
account_id: number // 归属账号
|
|
account_name: string // 冗余展示(mock 口径;真实联调由后端 join)
|
|
channel_id: number
|
|
recv_at: string
|
|
match_task_id: number // 0=未匹配(15 天窗口外/无下行);>0=窗口内最近下行明细
|
|
}
|
|
|
|
/** 上行查询参数(码号/手机号为主筛选;matched 三态筛选)。 */
|
|
export interface UplinkQuery {
|
|
page: number
|
|
page_size: number
|
|
dest_code?: string // 精确/前缀(码号两级匹配同口径)
|
|
src_mobile?: string // 模糊(尾号匹配)
|
|
matched?: number // 0=未匹配 1=已匹配(缺省=全部)
|
|
start_time?: string
|
|
end_time?: string
|
|
}
|
|
|
|
export interface UplinkPage {
|
|
list: UplinkRecord[]
|
|
total: number
|
|
}
|
|
|
|
/** 上行记录分页(D27;15 天匹配窗口由后端保证,前端提示口径)。 */
|
|
export function fetchUplinkRecords(q: UplinkQuery): Promise<UplinkPage> {
|
|
return get<UplinkPage>('/record/uplink', { ...q })
|
|
}
|
|
|
|
/** 提交上行导出(权限:uplink:export;无权限后端 403,按钮前端隐藏为第一道闸)。
|
|
* 复用 D26 异步导出任务模型(下载中心取件),scope 快照含上行筛选条件。 */
|
|
export function createUplinkExport(q: Omit<UplinkQuery, 'page' | 'page_size'>): Promise<{ id: number }> {
|
|
return post<{ id: number }>('/record/uplink/export', { ...q })
|
|
}
|
|
|
|
// ---- D28 回执重推工具+手动配对(message_report 30 天窗口;契约先行,mock 承载,Day58 后端 repush 域回填) ----
|
|
|
|
/** 回执行(message_report 口径;Day56 消费者已落库,30 天重推窗口数据源)。 */
|
|
export interface RepushReport {
|
|
id: number
|
|
detail_id: number
|
|
task_no: string // 冗余便于检索(后端 join message_detail)
|
|
mobile: string
|
|
account_id: number
|
|
status: 'SUCCESS' | 'FAILURE' | 'UNKNOWN' // Day55 三态
|
|
raw_code: string // 通道原始码(DELIVRD/GB:0001…)
|
|
error_code: string
|
|
report_at: string
|
|
push_status: number // 0未推 1已推 2推送失败(重推候选)
|
|
pushed_at: string | null
|
|
}
|
|
|
|
/** 回执查询参数(重推工具筛选)。 */
|
|
export interface RepushQuery {
|
|
page: number
|
|
page_size: number
|
|
account_id?: number
|
|
mobile?: string // 尾号模糊
|
|
task_no?: string // 精确
|
|
status?: 'SUCCESS' | 'FAILURE' | 'UNKNOWN'
|
|
start_time?: string
|
|
end_time?: string
|
|
}
|
|
|
|
/** 回执分页(D28)。 */
|
|
export function fetchRepushReports(q: RepushQuery): Promise<{ list: RepushReport[]; total: number }> {
|
|
return get<{ list: RepushReport[]; total: number }>('/record/repush', { ...q })
|
|
}
|
|
|
|
/** 重推请求(时间窗必填;账号/手机号收窄;30 天窗口后端强校验=第二道闸)。 */
|
|
export interface RepushRequest {
|
|
account_id?: number
|
|
mobiles?: string[]
|
|
start_time: string
|
|
end_time: string
|
|
}
|
|
|
|
/** 重推受理结果(异步任务:count=窗口内匹配回执数,推送反馈同批挂账 Day60)。 */
|
|
export interface RepushResult {
|
|
task_id: number
|
|
count: number
|
|
}
|
|
|
|
/** 提交回执重推(30 天窗口校验:超窗后端 ISC:400 业务错)。 */
|
|
export function createRepush(req: RepushRequest): Promise<RepushResult> {
|
|
return post<RepushResult>('/record/repush', req)
|
|
}
|
|
|
|
/** 手动配对四方式(实施计划 5.5:3h 外无状态明细手工指定终态)。 */
|
|
export type PairMode = 'msg_mobile' | 'detail' | 'task_time' | 'time_mobile'
|
|
|
|
/** 配对请求(按 mode 取对应字段;target_status 指定终态,资金口径后端同 Day57)。 */
|
|
export interface PairRequest {
|
|
mode: PairMode
|
|
msg_id?: string // msg_mobile:通道 msg_id+手机号精确
|
|
mobile?: string // msg_mobile/time_mobile:手机号
|
|
detail_id?: number // detail:明细雪花 ID 精确
|
|
task_no?: string // task_time:任务号
|
|
start_time?: string // task_time/time_mobile:时间窗
|
|
end_time?: string
|
|
target_status: 2 | 3 | 4 // 成功(不退费)/失败(退款)/未知(冻结释放)
|
|
}
|
|
|
|
/** 配对结果(matched=圈中挂起明细;updated=回写终态;skipped=已终态跳过)。 */
|
|
export interface PairResult {
|
|
matched: number
|
|
updated: number
|
|
skipped: number
|
|
}
|
|
|
|
/** 提交手动配对(结果回写挂起列表:updated 行离场)。 */
|
|
export function createManualPair(req: PairRequest): Promise<PairResult> {
|
|
return post<PairResult>('/record/repush/pair', req)
|
|
}
|
|
|
|
/** 挂起明细行(手动配对数据源:3h 外仍 status=1 的明细)。 */
|
|
export interface PendingDetail {
|
|
detail_id: number
|
|
task_no: string
|
|
msg_id: string // 通道 msg_id(msg_mobile 配对键)
|
|
mobile: string
|
|
content: string
|
|
sent_at: string
|
|
age_hours: number // 挂起时长(>3 为可配对口径)
|
|
}
|
|
|
|
/** 挂起明细分页(配对页列表;仅 3h 外)。 */
|
|
export function fetchPendingDetails(
|
|
q: { page: number; page_size: number; mobile?: string; task_no?: string },
|
|
): Promise<{ list: PendingDetail[]; total: number }> {
|
|
return get<{ list: PendingDetail[]; total: number }>('/record/repush/pending', { ...q })
|
|
}
|
|
|