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