168 lines
4.2 KiB
TypeScript
168 lines
4.2 KiB
TypeScript
import axios from 'axios';
|
|
import { API_BASE_URL } from '~/config/api-config';
|
|
|
|
// 文档数据库表接口
|
|
export interface Document {
|
|
id: number;
|
|
user_id: number | null;
|
|
type_id: number;
|
|
name: string;
|
|
document_number: string;
|
|
path: string;
|
|
storage_type: string;
|
|
file_size: number;
|
|
upload_time: string;
|
|
is_test_document: boolean;
|
|
evaluation_level: string;
|
|
status: string;
|
|
ocr_result: Record<string, unknown>;
|
|
extracted_results: Record<string, unknown> | null;
|
|
sumary: string | null;
|
|
remark: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
evaluations_status: number | null;
|
|
audit_status: number | null;
|
|
}
|
|
|
|
// 文档类型接口
|
|
export interface DocumentType {
|
|
id: number;
|
|
name: string;
|
|
description: string | null;
|
|
status: number;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// 评查文件UI接口
|
|
export interface ReviewFileUI {
|
|
id: string;
|
|
status: string;
|
|
path: string;
|
|
fileName: string;
|
|
fileCode: string;
|
|
fileType: string;
|
|
fileTypeId: number;
|
|
fileSize: number;
|
|
uploadTime: string;
|
|
reviewStatus: string;
|
|
reviewStatusCode: number;
|
|
issueCount: number;
|
|
score?: number;
|
|
auditStatus: number | null;
|
|
issues: Array<{
|
|
severity: 'info' | 'warning' | 'error' | 'critical';
|
|
message: string;
|
|
}>;
|
|
createdBy: string;
|
|
passCount: number;
|
|
warningCount: number;
|
|
failCount: number;
|
|
manualCount: number;
|
|
}
|
|
|
|
|
|
// 文件列表搜索参数
|
|
export interface DocumentSearchParams {
|
|
fileType?: string; // 文件类型ID
|
|
reviewStatus?: string; // 评查状态
|
|
// dateRange?: string; // 日期范围
|
|
dateFrom?: string; // 开始日期
|
|
dateTo?: string; // 结束日期
|
|
keyword?: string; // 搜索关键字
|
|
sortOrder?: string; // 排序方式
|
|
page?: number; // 当前页码
|
|
pageSize?: number; // 每页条数
|
|
}
|
|
|
|
|
|
/**
|
|
* 将评查状态代码映射到UI状态
|
|
* @param status 评查状态代码
|
|
* @returns UI状态
|
|
*/
|
|
export function mapReviewStatusToUI(status: number | null): string {
|
|
switch(status) {
|
|
case 1: return 'pass';
|
|
case -2: return 'warning';
|
|
case -1: return 'fail';
|
|
case 0: return 'pending';
|
|
default: return 'pending';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 将UI状态映射到评查状态代码
|
|
* @param status UI状态
|
|
* @returns 评查状态代码
|
|
*/
|
|
export function mapUIToReviewStatus(status: string): number {
|
|
switch(status) {
|
|
case 'pass': return 1;
|
|
case 'warning': return -2;
|
|
case 'fail': return -1;
|
|
case 'pending': return 0;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
|
|
// TODO: 是否需要出一个公共的接口,文件上传/文档列表 都需要用到:点击查看/开始审核 更新这个文件的审核状态(只有待审核的状态才会进行更新调用)
|
|
/**
|
|
* 更新文件的审核状态
|
|
* @param id 文件ID
|
|
* @param auditStatus 审核状态
|
|
* @param userId 用户ID
|
|
* @returns 更新结果
|
|
*/
|
|
export async function updateDocumentAuditStatus(id: string, auditStatus: number, userId: string, frontendJWT?: string): Promise<{
|
|
success?: boolean;
|
|
error?: string;
|
|
status?: number;
|
|
}> {
|
|
try {
|
|
if (!id) {
|
|
return { error: '文件ID不能为空', status: 400 };
|
|
}
|
|
|
|
if (!userId) {
|
|
return { error: '用户身份验证失败', status: 401 };
|
|
}
|
|
|
|
console.log('📝 [updateDocumentAuditStatus] 开始更新文件审核状态:', {
|
|
id,
|
|
auditStatus,
|
|
userId
|
|
});
|
|
|
|
try {
|
|
await axios.put(
|
|
`${API_BASE_URL}/api/documents/${id}`,
|
|
{ auditStatus },
|
|
{
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(frontendJWT ? { 'Authorization': `Bearer ${frontendJWT}` } : {})
|
|
}
|
|
}
|
|
);
|
|
|
|
console.log('✅ [updateDocumentAuditStatus] 新后端更新成功');
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error('❌ [updateDocumentAuditStatus] 新后端更新失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '更新文件审核状态失败',
|
|
status: axios.isAxiosError(error) ? error.response?.status || 500 : 500
|
|
};
|
|
}
|
|
} catch (error) {
|
|
console.error('❌ [updateDocumentAuditStatus] 更新文件审核状态异常:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '更新文件审核状态失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|