130 lines
9.0 KiB
TypeScript
130 lines
9.0 KiB
TypeScript
/**
|
|
* 合同付款预警 API 类型与请求封装。
|
|
* 依赖:统一 requestJson;后端 /api/contract-payment。
|
|
* 逻辑:台账/合同详情查询、汇总卡统计、待发送摘要、每日扫描入队、周五汇总入队、批次附件下载、失败原因及后台任务状态。
|
|
* 待确认合同的人工复核提交到 manual-review,通过后合同进入台账。
|
|
* 带 JSON body 的 POST 必须声明 Content-Type: application/json,否则 Flask 拒绝解析。
|
|
*/
|
|
import { requestBlob, requestJson } from '@/shared/api/client';
|
|
|
|
/**
|
|
* 组装带 JSON 正文的 POST。
|
|
* 核心逻辑:Flask 的 request.get_json 只在 Content-Type 为 application/json 时读取 body。
|
|
* @param body - 将序列化为 JSON 的请求体。
|
|
* @returns fetch 的 method、headers 与 body。
|
|
*/
|
|
function jsonPost(body: unknown): RequestInit {
|
|
return {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
};
|
|
}
|
|
|
|
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; paid_source?: 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; company_name?: string | null; erp_schema?: 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 AlertBatchFailureReason { code: string; detail?: string | null; }
|
|
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; created_at?: string | null; failure_reasons?: AlertBatchFailureReason[]; }
|
|
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 interface ManualReviewStageInput {
|
|
node_type: string;
|
|
skipped: boolean;
|
|
percentage: string;
|
|
amount: string;
|
|
basis_date: string;
|
|
}
|
|
export interface ManualReviewInput {
|
|
purchase_order_no: string;
|
|
contract_no: string;
|
|
total_amount: string;
|
|
archive_date: string;
|
|
stages: ManualReviewStageInput[];
|
|
}
|
|
/**
|
|
* 提交待确认合同的人工复核。
|
|
* 核心逻辑:后端校验比例合计、金额和必填日期;通过后合同 parse_status 变为 parsed。
|
|
* @param contractId - 合同台账主键。
|
|
* @param payload - 采购单号、合同金额和四个付款阶段。
|
|
* @returns 复核后的合同详情。
|
|
*/
|
|
/**
|
|
* 把未付的预付款或出货款标为已付。
|
|
* 核心逻辑:只提交这一阶段的付款日期和可选说明;后端关闭尚未发送的预警。
|
|
* @param contractId - 合同台账主键。
|
|
* @param nodeId - 付款节点主键。
|
|
* @param payload.paidDate - 付款日期,YYYY-MM-DD。
|
|
* @param payload.remark - 可选说明。
|
|
* @returns 更新后的合同详情。
|
|
*/
|
|
export const markContractPaymentNodePaid = (contractId: number, nodeId: number, payload: { paidDate: string; remark?: string }) => requestJson<{ contract: ContractPaymentContract }>(`/api/contract-payment/contracts/${contractId}/nodes/${nodeId}/mark-paid`, jsonPost({ paid_date: payload.paidDate, remark: payload.remark || '' }));
|
|
export const submitContractPaymentManualReview = (contractId: number, payload: ManualReviewInput) => requestJson<{ contract: ContractPaymentContract }>(`/api/contract-payment/contracts/${contractId}/manual-review`, jsonPost(payload));
|
|
/** 下载当前登录用户有权限访问的合同原文附件。 */
|
|
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', jsonPost({ force }));
|
|
/** 提交存量合同批量重解析,直接使用已归档附件刷新历史解析结果。 */
|
|
export const enqueueContractPaymentReparse = () => requestJson<{ job_id: string }>('/api/contract-payment/sync', jsonPost({ reparse_existing: true }));
|
|
export const enqueueContractPaymentAlertScan = () => requestJson<{ job_id: string }>('/api/contract-payment/alerts/run', { method: 'POST' });
|
|
export const enqueueContractPaymentWeeklyAlert = () => requestJson<{ job_id: number }>('/api/contract-payment/alerts/weekly-run', { method: 'POST' });
|
|
export interface ContractPaymentJobResult { batches?: number; sent?: number; failed?: number; alerts?: number; }
|
|
export interface ContractPaymentJob { id: number; status: string; message?: string | null; result?: ContractPaymentJobResult | null; }
|
|
/**
|
|
* 查询当前管理员刚提交的合同付款后台任务。
|
|
* 核心逻辑:发送预警只是入队,页面需轮询本接口直到 success / failed,再刷新周汇总列表。
|
|
* @param jobId - 入队接口返回的任务主键。
|
|
* @returns 任务状态与发送计数。
|
|
*/
|
|
export const getContractPaymentJob = (jobId: number) => requestJson<ContractPaymentJob>(`/api/contract-payment/jobs/${jobId}`);
|
|
/** 查询本周待发送笔数和下一次周五汇总发送时间。 */
|
|
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`);
|