完善评查详情
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { postgrestGet, type PostgrestParams } from "../postgrest-client";
|
||||
import { postgrestGet, type PostgrestParams, postgrestPut } from "../postgrest-client";
|
||||
import {getDocument} from "~/api/files/documents";
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
@@ -95,6 +96,13 @@ interface StatsData {
|
||||
* @returns 评查点结果列表和统计数据
|
||||
*/
|
||||
export async function getReviewPoints(fileId: string) {
|
||||
// 首先先获取这个文档的数据
|
||||
const documentData = await getDocument(fileId);
|
||||
if (documentData.error) {
|
||||
console.error("获取文档数据错误:", documentData.error);
|
||||
return Response.json({ error: documentData.error }, { status: documentData.status || 500 });
|
||||
}
|
||||
|
||||
// 步骤1:根据fileId查询evaluation_results表
|
||||
const evaluationResultsParams: PostgrestParams = {
|
||||
select: '*',
|
||||
@@ -195,16 +203,81 @@ export async function getReviewPoints(fileId: string) {
|
||||
data = result.evaluated_results.data || '';
|
||||
}
|
||||
|
||||
// 提取页码数组
|
||||
let contentPage: number[] = [];
|
||||
console.log('datacontent-------', data);
|
||||
if (data && typeof data === 'object') {
|
||||
try {
|
||||
const dataObj = data as Record<string, string>;
|
||||
// 检查是否是预期的格式 {'立案报告表-完整性检查':'缺失部分内容'}
|
||||
for (const key in dataObj) {
|
||||
if (Object.prototype.hasOwnProperty.call(dataObj, key)) {
|
||||
// 使用'-'分割获取前缀(如'立案报告表')
|
||||
const prefix = key.split('-')[0];
|
||||
console.log('prefix-------', prefix);
|
||||
// 检查document.data中的ocrResult是否存在这个key
|
||||
if (documentData.data?.ocrResult &&
|
||||
typeof documentData.data.ocrResult === 'object') {
|
||||
|
||||
// ocrResult可能有嵌套的ocr_result属性
|
||||
let ocrData: Record<string, any> = documentData.data.ocrResult as Record<string, any>;
|
||||
|
||||
// 检查是否有嵌套的ocr_result对象
|
||||
if ('ocr_result' in ocrData &&
|
||||
ocrData.ocr_result &&
|
||||
typeof ocrData.ocr_result === 'object') {
|
||||
ocrData = ocrData.ocr_result as Record<string, any>;
|
||||
}
|
||||
|
||||
for (const ocrKey in ocrData) {
|
||||
// 如果找到匹配的key
|
||||
if (ocrKey === prefix &&
|
||||
ocrData[ocrKey] &&
|
||||
typeof ocrData[ocrKey] === 'object' &&
|
||||
'pages' in ocrData[ocrKey]) {
|
||||
|
||||
// 获取pages数组
|
||||
const pages = ocrData[ocrKey].pages;
|
||||
if (Array.isArray(pages)) {
|
||||
contentPage = pages;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析评查点data失败:', e);
|
||||
contentPage = [];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: result.id,
|
||||
title: message,
|
||||
pointName: point.name || '',
|
||||
groupName: group.name || '',
|
||||
status: point.suggestion_message_type || '',
|
||||
|
||||
status: point.suggestion_message_type || '', //评查点的评查结果状态
|
||||
// status: 'error', //评查点的评查结果状态
|
||||
|
||||
content: data,
|
||||
|
||||
contentPage: contentPage,
|
||||
|
||||
suggestion: point.suggestion_message || '',
|
||||
// suggestion: '只是给建议的修改内容',
|
||||
|
||||
result: result.evaluated_results?.result, // 记录评查结果,用于统计
|
||||
score: point.score || 0,
|
||||
|
||||
postAction: point.post_action || '',
|
||||
// postAction: 'manual',
|
||||
|
||||
actionContent: point.action_config || '',
|
||||
// actionContent: '用户提前在评查点输入过的修改内容',
|
||||
|
||||
legalBasis: point.references_laws || {}
|
||||
// legalBasis: {
|
||||
// name: '中华人民共和国食品安全法',
|
||||
@@ -271,5 +344,79 @@ export async function getReviewPoints(fileId: string) {
|
||||
};
|
||||
// console.log("reviewInfo-------",JSON.stringify(reviewInfo,null,2));
|
||||
|
||||
return { data: resultData, stats, reviewInfo };
|
||||
return { data: resultData, stats, reviewInfo, document: documentData.data };
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新评查结果
|
||||
* @param resultId 评查结果ID
|
||||
* @param result 评查结果 (true/false)
|
||||
* @param message 评查意见
|
||||
* @returns 更新后的评查结果
|
||||
*/
|
||||
export async function updateReviewResult(resultId: string, result: boolean, message: string): Promise<{
|
||||
data?: unknown;
|
||||
error?: string;
|
||||
status?: number;
|
||||
}> {
|
||||
try {
|
||||
if (!resultId) {
|
||||
return { error: '评查结果ID不能为空', status: 400 };
|
||||
}
|
||||
|
||||
// 首先获取当前评查结果数据
|
||||
const currentResultResponse = await postgrestGet('evaluation_results', {
|
||||
select: '*',
|
||||
filter: { id: `eq.${resultId}` }
|
||||
});
|
||||
|
||||
if (currentResultResponse.error) {
|
||||
return { error: currentResultResponse.error, status: currentResultResponse.status };
|
||||
}
|
||||
|
||||
const currentResultData = extractApiData<EvaluationResult[]>(currentResultResponse.data);
|
||||
|
||||
if (!currentResultData || !Array.isArray(currentResultData) || currentResultData.length === 0) {
|
||||
return { error: '未找到评查结果数据', status: 404 };
|
||||
}
|
||||
|
||||
const currentResult = currentResultData[0];
|
||||
const currentEvaluatedResults = currentResult.evaluated_results || {};
|
||||
|
||||
// 构建要更新的数据,保留原有字段,只更新result和message
|
||||
const updatedEvaluatedResults = {
|
||||
...currentEvaluatedResults,
|
||||
result: result,
|
||||
message: message
|
||||
};
|
||||
|
||||
const updatedData = {
|
||||
evaluated_results: updatedEvaluatedResults
|
||||
};
|
||||
|
||||
// 调用 API 更新数据
|
||||
const response = await postgrestPut<unknown, typeof updatedData>(
|
||||
'evaluation_results',
|
||||
updatedData,
|
||||
{ id: resultId }
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
const extractedData = extractApiData<unknown>(response.data);
|
||||
|
||||
if (!extractedData) {
|
||||
return { error: '更新评查结果失败', status: 500 };
|
||||
}
|
||||
|
||||
return { data: extractedData };
|
||||
} catch (error) {
|
||||
console.error('更新评查结果失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '更新评查结果失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user