修改评查详情
This commit is contained in:
-131
@@ -1,131 +0,0 @@
|
||||
/**
|
||||
* API基础服务
|
||||
*/
|
||||
|
||||
// 默认API基础URL
|
||||
const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:8000';
|
||||
|
||||
/**
|
||||
* 通用API响应格式
|
||||
*/
|
||||
export interface ApiResponse<T> {
|
||||
status: 'success' | 'error';
|
||||
data?: T;
|
||||
message?: string;
|
||||
error?: {
|
||||
code: string;
|
||||
details?: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页请求参数
|
||||
*/
|
||||
export interface PaginationParams {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页响应数据
|
||||
*/
|
||||
export interface PaginatedResponse<T> {
|
||||
items: T[];
|
||||
totalItems: number;
|
||||
totalPages: number;
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一错误处理
|
||||
*/
|
||||
export class ApiError extends Error {
|
||||
statusCode: number;
|
||||
errorCode: string;
|
||||
details?: any;
|
||||
|
||||
constructor(message: string, statusCode: number, errorCode: string, details?: any) {
|
||||
super(message);
|
||||
this.name = 'ApiError';
|
||||
this.statusCode = statusCode;
|
||||
this.errorCode = errorCode;
|
||||
this.details = details;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建请求URL
|
||||
*/
|
||||
export function buildUrl(path: string, params?: Record<string, any>): string {
|
||||
// 确保API_BASE_URL末尾没有斜杠,而path开头有斜杠
|
||||
const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
||||
|
||||
try {
|
||||
const url = new URL(`${baseUrl}${normalizedPath}`);
|
||||
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null) {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
} catch (error) {
|
||||
console.error('URL构建错误:', error);
|
||||
throw new Error(`无法构建URL: ${baseUrl}${normalizedPath}, 错误: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用API请求函数
|
||||
*/
|
||||
export async function apiRequest<T>(
|
||||
url: string,
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
||||
body?: any,
|
||||
headers?: Record<string, string>
|
||||
): Promise<T> {
|
||||
const requestInit: RequestInit = {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
...headers
|
||||
}
|
||||
};
|
||||
|
||||
if (body) {
|
||||
requestInit.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
const response = await fetch(url, requestInit);
|
||||
|
||||
// 获取响应数据
|
||||
const data = await response.json() as ApiResponse<T>;
|
||||
|
||||
// 检查状态码
|
||||
if (!response.ok) {
|
||||
throw new ApiError(
|
||||
data.message || '请求失败',
|
||||
response.status,
|
||||
data.error?.code || 'UNKNOWN_ERROR',
|
||||
data.error?.details
|
||||
);
|
||||
}
|
||||
|
||||
// 检查业务状态
|
||||
if (data.status === 'error') {
|
||||
throw new ApiError(
|
||||
data.message || '请求失败',
|
||||
response.status,
|
||||
data.error?.code || 'BUSINESS_ERROR',
|
||||
data.error?.details
|
||||
);
|
||||
}
|
||||
|
||||
return data.data as T;
|
||||
}
|
||||
@@ -57,6 +57,7 @@ interface EvaluationPoint {
|
||||
suggestion_message_type?: string;
|
||||
suggestion_message?: string;
|
||||
score?: number;
|
||||
updated_at?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ interface StatsData {
|
||||
* 获取当前评查文件的所有评查点结果
|
||||
* @param fileId 评查文件ID
|
||||
* @returns 评查点结果列表和统计数据
|
||||
*/
|
||||
*/
|
||||
export async function getReviewPoints(fileId: string) {
|
||||
// 步骤1:根据fileId查询evaluation_results表
|
||||
const evaluationResultsParams: PostgrestParams = {
|
||||
@@ -197,12 +198,24 @@ export async function getReviewPoints(fileId: string) {
|
||||
return {
|
||||
id: result.id,
|
||||
title: message,
|
||||
pointName: point.name || '',
|
||||
groupName: group.name || '',
|
||||
status: point.suggestion_message_type || '',
|
||||
content: data,
|
||||
suggestion: point.suggestion_message || '',
|
||||
result: result.evaluated_results?.result, // 记录评查结果,用于统计
|
||||
score: point.score || 0
|
||||
score: point.score || 0,
|
||||
legalBasis: point.references_laws || {}
|
||||
// legalBasis: {
|
||||
// name: '中华人民共和国食品安全法',
|
||||
// content: '中华人民共和国食品安全法',
|
||||
// article: [
|
||||
// {
|
||||
// name: '中华人民共和国食品安全法',
|
||||
// content: '中华人民共和国食品安全法'
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
};
|
||||
});
|
||||
|
||||
@@ -233,5 +246,30 @@ export async function getReviewPoints(fileId: string) {
|
||||
stats.score += item.score || 0;
|
||||
});
|
||||
|
||||
return { data: resultData, stats };
|
||||
// 构建文件信息-评查信息的数据
|
||||
// 找出最新的评查时间
|
||||
let latestUpdatedAt = '';
|
||||
evaluationResultsData.forEach(result => {
|
||||
if (result.updated_at && (!latestUpdatedAt || result.updated_at > latestUpdatedAt)) {
|
||||
latestUpdatedAt = result.updated_at.toString();
|
||||
}
|
||||
});
|
||||
|
||||
// 提取不重复的规则组名称
|
||||
const uniqueGroups = Array.from(new Set(resultData.map(item => item.groupName))).filter(Boolean);
|
||||
|
||||
// 计算问题数量
|
||||
const issueCount = stats.warning + stats.error;
|
||||
|
||||
// 构建评查信息对象
|
||||
const reviewInfo = {
|
||||
reviewTime: formatDate(latestUpdatedAt),
|
||||
reviewModel: 'DeepSeek',
|
||||
ruleGroup: uniqueGroups.join('、'),
|
||||
result: issueCount > 0 ? 'warning' : 'success',
|
||||
issueCount: issueCount
|
||||
};
|
||||
// console.log("reviewInfo-------",JSON.stringify(reviewInfo,null,2));
|
||||
|
||||
return { data: resultData, stats, reviewInfo };
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export interface DocumentSearchParams {
|
||||
function formatDate(dateString: string): string {
|
||||
if (!dateString) return '';
|
||||
try {
|
||||
return dayjs(dateString).format('YYYY-MM-DD HH:mm:ss');
|
||||
return dayjs(dateString).format('YYYY-MM-DD');
|
||||
} catch (error) {
|
||||
console.error('日期格式化失败:', error);
|
||||
return dateString;
|
||||
@@ -215,7 +215,12 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
|
||||
case 'upload_time_asc':
|
||||
params.order = 'created_at.asc';
|
||||
break;
|
||||
// 其他排序方式可以在这里添加
|
||||
// case 'issue_count_desc':
|
||||
// params.order = 'issue_count.desc';
|
||||
// break;
|
||||
// case 'issue_count_asc':
|
||||
// params.order = 'issue_count.asc';
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,25 @@ function getFileExtension(filename: string): string {
|
||||
return parts.length > 1 ? parts.pop()?.toLowerCase() || '' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评查结果
|
||||
* @param id 评查结果ID
|
||||
* @returns 评查结果
|
||||
*/
|
||||
async function getEvaluationResults(id: number) {
|
||||
const response = await postgrestGet<[]>('evaluation_results', {
|
||||
filter: {
|
||||
'document_id': `eq.${id}`
|
||||
}
|
||||
});
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
const evaluationResult = extractApiData<[]>(response.data);
|
||||
return evaluationResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将API文档转换为UI文档
|
||||
*/
|
||||
@@ -122,6 +141,24 @@ async function convertToUIDocument(doc: Document): Promise<DocumentUI> {
|
||||
const typeResponse = await getDocumentTypes();
|
||||
const documentTypes = typeResponse.data?.types || [];
|
||||
const docType = documentTypes.find(type => type.id.toString() === doc.type_id.toString());
|
||||
const evaluationResult = await getEvaluationResults(doc.id);
|
||||
let issues = 0;
|
||||
|
||||
interface EvaluationResultItem {
|
||||
evaluated_results?: {
|
||||
result?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
if (evaluationResult && Array.isArray(evaluationResult)) {
|
||||
evaluationResult.forEach((result: EvaluationResultItem) => {
|
||||
if(result && result.evaluated_results && !result.evaluated_results.result){
|
||||
issues++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
id: doc.id,
|
||||
@@ -132,7 +169,7 @@ async function convertToUIDocument(doc: Document): Promise<DocumentUI> {
|
||||
size: doc.file_size,
|
||||
auditStatus: doc.audit_status || 0,
|
||||
fileStatus: doc.status || '', // 默认为''
|
||||
issues: 0, // 固定为0
|
||||
issues: issues, // 使用计算得到的issues
|
||||
uploadTime: formatDate(doc.updated_at),
|
||||
fileType: getFileExtension(doc.name),
|
||||
path: doc.path,
|
||||
|
||||
@@ -40,6 +40,7 @@ function extractApiData<T>(responseData: unknown): T | null {
|
||||
|
||||
// 文档状态枚举
|
||||
export enum DocumentStatus {
|
||||
waiting = 'waiting',
|
||||
WAITING = "Waiting",
|
||||
CUTTING = "Cutting",
|
||||
EXTRACTIONING = "Extractioning",
|
||||
@@ -176,6 +177,7 @@ export async function uploadDocumentToServer(
|
||||
// 发送请求
|
||||
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
|
||||
const response = await fetch('http://172.16.0.55:8000/admin/documents/upload', {
|
||||
// const response = await fetch('http://172.16.0.119:8000/admin/documents/upload', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-File-Name': encodeURIComponent(fileName)
|
||||
|
||||
Reference in New Issue
Block a user