70 lines
6.0 KiB
TypeScript
70 lines
6.0 KiB
TypeScript
/**
|
|
* 合同付款预警 API 类型与请求封装。
|
|
* 依赖:统一 requestJson;后端 /api/contract-payment。
|
|
* 逻辑:台账/合同详情查询、汇总卡统计、待发送摘要、每日扫描入队、周五汇总入队及批次附件下载。
|
|
*/
|
|
import { requestBlob, requestJson } from '@/shared/api/client';
|
|
|
|
export interface PaymentNode {
|
|
id: number; node_code: string; node_type: string; amount?: string | null; percentage?: string | null;
|
|
anchor_type?: string | null; anchor_date?: string | null; due_date?: string | null; paid_at?: string | null; status: string;
|
|
}
|
|
export interface PaymentAlert { id: number; node_id: number; alert_round: number; scheduled_at?: string | null; sent_at?: string | null; recipient_user_id?: number | null; status: string; }
|
|
export interface ContractAttachment {
|
|
id: number; source: string; file_name: string; mime_type?: string | null; asset_no?: string | null;
|
|
dms_path?: string | null; created_at?: string | null; status: string;
|
|
}
|
|
export interface ContractPaymentContract {
|
|
id: number; contract_no?: string | null; workflow_no?: string | null; purchase_order_no?: string | null;
|
|
supplier_name?: string | null; total_amount?: string | null; currency?: string | null; applicant_name?: string | null;
|
|
effective_date?: string | null; delivery_due_date?: string | null; oa_archive_at?: string | null;
|
|
status: string; parse_status: string; plan_status: string; parse_issues?: string[]; nodes: PaymentNode[]; alerts?: PaymentAlert[]; attachments?: ContractAttachment[];
|
|
}
|
|
export interface ContractListResponse { total: number; page: number; page_size: number; pages: number; items: ContractPaymentContract[]; }
|
|
export type LedgerFocus = 'due' | 'overdue' | 'active' | 'due_this_month';
|
|
export interface LedgerSummary {
|
|
due: number;
|
|
overdue: number;
|
|
active: number;
|
|
due_this_month: number;
|
|
}
|
|
export interface AlertBatch { id: number; batch_no: string; week_key: string; status: string; summary?: { total?: number; stages?: Record<string, number> }; excel_file_name?: string | null; excel_file_size?: number | null; sent_at?: string | null; }
|
|
export interface AlertSummary { pending_count: number; next_send_at?: string | null; timezone?: string | null; }
|
|
|
|
/**
|
|
* 分页查询合同付款台账或待确认合同。
|
|
* 核心逻辑:keyword 同时匹配合同号、流程号、采购单号和供应商;reviewOnly 走待确认列表。
|
|
* @param params.keyword - 模糊检索词,可为空。
|
|
* @param params.parse_status - 解析状态精确筛选。
|
|
* @param params.reviewOnly - 为 true 时只查 needs_review。
|
|
* @param params.focus - 汇总卡口径:即将到期 / 逾期未付 / 进行中 / 本月应付。
|
|
* @returns 分页后的合同列表。
|
|
*/
|
|
export const listContractPaymentContracts = (params?: { keyword?: string; parse_status?: string; reviewOnly?: boolean; focus?: LedgerFocus; page?: number; pageSize?: number }) => {
|
|
const query = new URLSearchParams(); if (params?.keyword) query.set('keyword', params.keyword); if (params?.parse_status) query.set('parse_status', params.parse_status); if (params?.reviewOnly) query.set('review_only', '1'); if (params?.focus) query.set('focus', params.focus); if (params?.page) query.set('page', String(params.page)); if (params?.pageSize) query.set('page_size', String(params.pageSize));
|
|
const suffix = query.toString() ? `?${query.toString()}` : ''; return requestJson<ContractListResponse>(`/api/contract-payment/contracts${suffix}`);
|
|
};
|
|
/** 获取单份合同的概览、原文附件、付款计划与预警审计详情。 */
|
|
export const getContractPaymentContract = (contractId: number) => requestJson<ContractPaymentContract>(`/api/contract-payment/contracts/${contractId}`);
|
|
/** 用已归档的盖章合同原文重新解析,并返回覆盖后的合同详情。 */
|
|
export const reparseContractPaymentContract = (contractId: number) => requestJson<{ contract: ContractPaymentContract; parse_result: { status: string }; attachment_name: string }>(`/api/contract-payment/contracts/${contractId}/reparse`, { method: 'POST' });
|
|
/** 下载当前登录用户有权限访问的合同原文附件。 */
|
|
export const downloadContractPaymentAttachment = (contractId: number, attachmentId: number) => requestBlob(`/api/contract-payment/contracts/${contractId}/attachments/${attachmentId}/download`);
|
|
/** 提交 OA 合同同步;force 为 true 时由后端显式覆盖本次 OA 返回的非空主表字段。 */
|
|
export const enqueueContractPaymentSync = (force = false) => requestJson<{ job_id: string }>('/api/contract-payment/sync', { method: 'POST', body: JSON.stringify({ force }) });
|
|
/** 提交存量合同批量重解析,直接使用已归档附件刷新历史解析结果。 */
|
|
export const enqueueContractPaymentReparse = () => requestJson<{ job_id: string }>('/api/contract-payment/sync', { method: 'POST', body: JSON.stringify({ reparse_existing: true }) });
|
|
export const enqueueContractPaymentAlertScan = () => requestJson<{ job_id: string }>('/api/contract-payment/alerts/run', { method: 'POST' });
|
|
export const enqueueContractPaymentWeeklyAlert = () => requestJson<{ job_id: string }>('/api/contract-payment/alerts/weekly-run', { method: 'POST' });
|
|
/** 查询本周待发送笔数和下一次周五汇总发送时间。 */
|
|
export const getContractPaymentAlertSummary = () => requestJson<AlertSummary>('/api/contract-payment/alerts/summary');
|
|
/**
|
|
* 查询合同台账四张汇总卡的合同份数。
|
|
* 核心逻辑:始终统计全部已解析台账,不跟当前 keyword;与点卡片过滤共用 focus 口径。
|
|
* @returns due / overdue / active / due_this_month。
|
|
*/
|
|
export const getContractPaymentLedgerSummary = () => requestJson<LedgerSummary>('/api/contract-payment/contracts/summary');
|
|
export const listContractPaymentAlertBatches = () => requestJson<{ items: AlertBatch[] }>('/api/contract-payment/alert-batches');
|
|
/** 下载已归档的合同付款预警周汇总 Excel 明细。 */
|
|
export const downloadContractPaymentAlertBatchExcel = (batchId: number) => requestBlob(`/api/contract-payment/alert-batches/${batchId}/excel`);
|