fix: reconnect cross checking upload flow
This commit is contained in:
@@ -116,39 +116,16 @@ export async function uploadCrossCheckingDocument(
|
|||||||
token: string | null = null
|
token: string | null = null
|
||||||
): Promise<{data: CrossCheckingFileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
): Promise<{data: CrossCheckingFileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||||
try {
|
try {
|
||||||
console.log('【交叉评查上传】开始上传文档:', { fileName, fileSize: binaryData.byteLength, typeId });
|
|
||||||
|
|
||||||
// 创建FormData对象
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
// 将二进制数据转换为Blob并添加到FormData
|
|
||||||
const blob = new Blob([binaryData], { type: fileType });
|
const blob = new Blob([binaryData], { type: fileType });
|
||||||
formData.append('file', blob, fileName);
|
formData.append('file', blob, fileName);
|
||||||
console.log('【交叉评查上传】Blob已创建,文件大小:', blob.size);
|
formData.append('typeId', String(typeId));
|
||||||
|
formData.append('region', 'default');
|
||||||
// 将信息添加到一个JSON对象中
|
formData.append('fileRole', 'primary');
|
||||||
const uploadInfo = {
|
formData.append('autoRun', 'true');
|
||||||
type_id: typeId,
|
formData.append('speed', priority === 'urgent' ? 'urgent' : 'normal');
|
||||||
evaluation_level: priority,
|
|
||||||
document_number: documentNumber || null,
|
|
||||||
remark: remark || null,
|
|
||||||
is_test_document: isTestDocument,
|
|
||||||
document_id: documentId || null,
|
|
||||||
is_reupload: isReupload
|
|
||||||
};
|
|
||||||
|
|
||||||
// 添加JSON字符串到FormData
|
|
||||||
formData.append('upload_info', JSON.stringify(uploadInfo));
|
|
||||||
console.log('【交叉评查上传】FormData准备完成:', JSON.stringify(uploadInfo));
|
|
||||||
|
|
||||||
// 根据是否有documentId决定使用哪个接口
|
|
||||||
const uploadEndpoint = '/batch_upload';
|
|
||||||
const uploadUrl = UPLOAD_URL + uploadEndpoint;
|
|
||||||
console.log('【交叉评查上传】准备发送请求到服务器:', uploadUrl);
|
|
||||||
|
|
||||||
// 发送请求
|
|
||||||
try {
|
try {
|
||||||
console.log('【交叉评查上传】开始axios请求...');
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'X-File-Name': encodeURIComponent(fileName),
|
'X-File-Name': encodeURIComponent(fileName),
|
||||||
};
|
};
|
||||||
@@ -157,30 +134,43 @@ export async function uploadCrossCheckingDocument(
|
|||||||
headers['Authorization'] = `Bearer ${token}`;
|
headers['Authorization'] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(uploadUrl, formData, {
|
const response = await axios.post(`${API_BASE_URL}/api/upload`, formData, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
|
const uploadData = response.data?.data;
|
||||||
console.log('【交叉评查上传】收到服务器响应:', { status: response.status, statusText: response.statusText });
|
if (!uploadData?.documentId) {
|
||||||
|
return { error: response.data?.message || response.data?.msg || '处理上传响应失败', status: response.status };
|
||||||
console.log('【交叉评查上传】JSON响应解析成功:', response.data);
|
|
||||||
|
|
||||||
const extractedData = extractApiData<CrossCheckingFileUploadResponse>(response.data);
|
|
||||||
console.log('【交叉评查上传】提取的数据:', extractedData);
|
|
||||||
|
|
||||||
if (!extractedData) {
|
|
||||||
console.error('【交叉评查上传】无法提取数据');
|
|
||||||
return { error: '处理上传响应失败', status: 500 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('【交叉评查上传】上传成功,返回数据');
|
return {
|
||||||
return { data: extractedData as CrossCheckingFileUploadResponse };
|
data: {
|
||||||
|
success: true,
|
||||||
|
result: {
|
||||||
|
id: Number(uploadData.documentId),
|
||||||
|
file_name: uploadData.fileName || fileName,
|
||||||
|
file_size: binaryData.byteLength,
|
||||||
|
file_url: uploadData.storagePath || '',
|
||||||
|
type_id: Number(uploadData.typeId || typeId),
|
||||||
|
type_description: uploadData.typeCode || '',
|
||||||
|
document_number: documentNumber || null,
|
||||||
|
storage_type: 'oss',
|
||||||
|
is_test_document: isTestDocument,
|
||||||
|
remark: remark || null,
|
||||||
|
background_processing: true,
|
||||||
|
evaluation_level: priority,
|
||||||
|
},
|
||||||
|
error: null,
|
||||||
|
}
|
||||||
|
};
|
||||||
} catch (axiosError) {
|
} catch (axiosError) {
|
||||||
console.error('【交叉评查上传】axios请求失败:', axiosError);
|
|
||||||
if (axios.isAxiosError(axiosError)) {
|
if (axios.isAxiosError(axiosError)) {
|
||||||
const errorText = axiosError.response?.data || axiosError.message;
|
const errorText =
|
||||||
|
axiosError.response?.data?.message ||
|
||||||
|
axiosError.response?.data?.msg ||
|
||||||
|
axiosError.response?.data?.detail ||
|
||||||
|
axiosError.message;
|
||||||
return {
|
return {
|
||||||
error: `上传失败: ${axiosError.response?.status || 500} ${axiosError.response?.statusText || ''} - ${errorText}`,
|
error: `上传失败: ${errorText}`,
|
||||||
status: axiosError.response?.status || 500
|
status: axiosError.response?.status || 500
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -190,7 +180,6 @@ export async function uploadCrossCheckingDocument(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('【交叉评查上传】上传过程中发生错误:', error);
|
|
||||||
return {
|
return {
|
||||||
error: error instanceof Error ? error.message : '上传失败',
|
error: error instanceof Error ? error.message : '上传失败',
|
||||||
status: 500
|
status: 500
|
||||||
|
|||||||
@@ -946,33 +946,24 @@ export async function updateDocumentAuditStatus(id: string, auditStatus: number,
|
|||||||
*/
|
*/
|
||||||
export async function getCrossCheckingDocumentTypes(jwtToken?: string): Promise<ApiResponse<DocumentType[]>> {
|
export async function getCrossCheckingDocumentTypes(jwtToken?: string): Promise<ApiResponse<DocumentType[]>> {
|
||||||
try {
|
try {
|
||||||
// console.log('[getCrossCheckingDocumentTypes] 开始获取交叉评查文档类型');
|
const response = await axios.get<{ data?: Array<{
|
||||||
|
id: number;
|
||||||
const response = await postgrestGet<DocumentType>('/api/postgrest/proxy/document_types',{
|
name: string;
|
||||||
select: 'id,name,code,evaluation_point_groups_ids',
|
code: string;
|
||||||
filter: {
|
isEnabled?: boolean;
|
||||||
evaluation_point_groups_ids: 'not.is.null'
|
ruleSetIds?: number[];
|
||||||
},
|
}> }>(`${API_BASE_URL}/api/document-types`, {
|
||||||
token: jwtToken
|
headers: jwtToken ? { Authorization: `Bearer ${jwtToken}` } : undefined,
|
||||||
});
|
});
|
||||||
|
const rawItems = Array.isArray(response.data?.data) ? response.data.data : [];
|
||||||
if (response.error) {
|
const filteredData = rawItems
|
||||||
console.error('[getCrossCheckingDocumentTypes] 获取失败:', response.error);
|
.filter((item) => item && item.isEnabled !== false)
|
||||||
return {
|
.map((item) => ({
|
||||||
success: false,
|
id: item.id,
|
||||||
error: response.error
|
name: item.name,
|
||||||
};
|
code: item.code,
|
||||||
}
|
}))
|
||||||
|
.sort((a, b) => a.name.localeCompare(b.name, 'zh-CN'));
|
||||||
// 进一步过滤,确保 evaluation_point_groups_ids 是非空数组
|
|
||||||
const dataArray = Array.isArray(response.data) ? response.data : [];
|
|
||||||
const filteredData = dataArray.filter(
|
|
||||||
(item: DocumentType) => item.evaluation_point_groups_ids &&
|
|
||||||
Array.isArray(item.evaluation_point_groups_ids) &&
|
|
||||||
item.evaluation_point_groups_ids.length > 0
|
|
||||||
);
|
|
||||||
|
|
||||||
// console.log('[getCrossCheckingDocumentTypes] 获取成功,共', filteredData.length, '个文档类型');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user