feat: 1. 完善起草合同页面的逻辑交互,对接minio的接口操作
This commit is contained in:
+5
-103
@@ -145,7 +145,7 @@ function getFileExtension(filename: string): string {
|
||||
* @returns 评查结果
|
||||
*/
|
||||
async function getEvaluationResults(id: number, frontendJWT?: string) {
|
||||
const response = await postgrestGet<[]>('evaluation_results', {
|
||||
const response = await postgrestGet<[]>('/api/postgrest/proxy/evaluation_results', {
|
||||
filter: {
|
||||
'document_id': `eq.${id}`
|
||||
},
|
||||
@@ -254,7 +254,7 @@ export async function deleteDocument(id: string, userId: string, token?: string)
|
||||
}
|
||||
|
||||
const response = await postgrestDelete(
|
||||
'documents',
|
||||
'/api/postgrest/proxy/documents',
|
||||
{
|
||||
filter: {
|
||||
'id': `eq.${id}`,
|
||||
@@ -298,7 +298,7 @@ export async function getDocument(id: string, userId: string, frontendJWT?: stri
|
||||
}
|
||||
|
||||
const response = await postgrestGet<Document[]>(
|
||||
'documents',
|
||||
'/api/postgrest/proxy/documents',
|
||||
{
|
||||
filter: {
|
||||
'id': `eq.${id}`,
|
||||
@@ -349,7 +349,7 @@ export async function getDocumentWithNoUserId(id: string, frontendJWT?: string):
|
||||
// console.log("get单个文档id", id)
|
||||
|
||||
const response = await postgrestGet<Document[]>(
|
||||
'documents',
|
||||
'/api/postgrest/proxy/documents',
|
||||
{
|
||||
filter: {
|
||||
'id': `eq.${id}`,
|
||||
@@ -430,7 +430,7 @@ export async function updateDocument(id: string, document: Partial<DocumentUI> &
|
||||
// console.log('更新文档API数据:', apiDocument);
|
||||
|
||||
const response = await postgrestPut<Document, Partial<Document>>(
|
||||
'documents',
|
||||
'/api/postgrest/proxy/documents',
|
||||
apiDocument,
|
||||
{
|
||||
id: parseInt(id),
|
||||
@@ -653,101 +653,3 @@ export async function getDocumentsListFromAPI(searchParams: {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档历史版本列表
|
||||
* @param documentName 文档名称
|
||||
* @param userId 用户ID
|
||||
* @param excludeId 排除的文档ID(当前最新版本的ID)
|
||||
* @param token JWT token
|
||||
* @returns 历史版本列表
|
||||
*/
|
||||
export async function getDocumentHistory(
|
||||
documentName: string,
|
||||
userId: string,
|
||||
excludeId: number,
|
||||
token?: string
|
||||
): Promise<{
|
||||
data?: DocumentVersionUI[];
|
||||
error?: string;
|
||||
status?: number;
|
||||
}> {
|
||||
try {
|
||||
if (!documentName) {
|
||||
return { error: '文档名称不能为空', status: 400 };
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
return { error: '用户身份验证失败', status: 401 };
|
||||
}
|
||||
|
||||
// 调用 RPC 函数获取历史版本
|
||||
const response = await postgrestPost<any[], unknown>(
|
||||
'rpc/documents_get_document_history',
|
||||
{
|
||||
p_document_name: documentName,
|
||||
p_user_id: parseInt(userId, 10),
|
||||
p_exclude_id: excludeId
|
||||
},
|
||||
token
|
||||
);
|
||||
|
||||
if (response.error || !response.data) {
|
||||
return { error: response.error || '获取历史版本失败', status: response.status || 500 };
|
||||
}
|
||||
|
||||
const historyDocs = response.data;
|
||||
|
||||
// 转换为 UI 格式,并计算问题数量差异
|
||||
const documents: DocumentVersionUI[] = historyDocs.map((doc: any, index: number) => {
|
||||
// 计算与下一个版本(更早的版本)的问题数量差异
|
||||
let issuesDiff: number | undefined;
|
||||
let issuesDiffType: 'increase' | 'decrease' | 'same' | undefined;
|
||||
|
||||
if (index < historyDocs.length - 1) {
|
||||
const olderDoc = historyDocs[index + 1];
|
||||
if (doc.false_count != null && olderDoc.false_count != null) {
|
||||
const diff = doc.false_count - olderDoc.false_count;
|
||||
issuesDiff = Math.abs(diff);
|
||||
if (diff > 0) {
|
||||
issuesDiffType = 'increase';
|
||||
} else if (diff < 0) {
|
||||
issuesDiffType = 'decrease';
|
||||
} else {
|
||||
issuesDiffType = 'same';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: doc.id,
|
||||
name: doc.name,
|
||||
documentNumber: doc.document_number,
|
||||
type: doc.type_id.toString(),
|
||||
typeName: doc.type_name || '未知类型',
|
||||
size: doc.file_size,
|
||||
auditStatus: doc.audit_status ?? 0,
|
||||
fileStatus: doc.status || '',
|
||||
issues: doc.false_count ?? null,
|
||||
issuesDiff,
|
||||
issuesDiffType,
|
||||
uploadTime: formatDate(doc.created_at),
|
||||
fileType: getFileExtension(doc.name),
|
||||
path: doc.path,
|
||||
isTest: doc.is_test_document,
|
||||
updatedAt: formatDate(doc.updated_at),
|
||||
pageCount: doc.ocr_result?.__meta?.page_count || 0,
|
||||
ocrResult: doc.ocr_result,
|
||||
versionNumber: historyDocs.length - index
|
||||
};
|
||||
});
|
||||
|
||||
return { data: documents };
|
||||
} catch (error) {
|
||||
console.error('获取文档历史版本失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '获取文档历史版本失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user