feat: 1. 完善全局路由的访问权限的验证。 2. 完善接口返回的树形路由结构 3.优化评查点列表的查询,改用表连接的方式,废弃使用数据库的rpc函数,同时进行地区隔离和权限隔离。
4. 删除冗余的评查文件列表。 5.完善上传文档 页面初始化查询数据的时候 查询文件类型(改成动态指定) 6. 添加获取入口模块的查询接口。 7.完善服务端中判断token的有效性,失效则跳转到登录页。 8. 重构layout和sidebar的页面,改成由动态权限路由来渲染对应的菜单栏。 9.重构入口页面,通过动态查询根据不同地区的人返回不同的入口。
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { postgrestPut, postgrestPost } from '../postgrest-client';
|
||||
import { formatDate } from '../../utils';
|
||||
import { postgrestPut } from '../postgrest-client';
|
||||
|
||||
// 文档数据库表接口
|
||||
export interface Document {
|
||||
@@ -62,32 +61,6 @@ export interface ReviewFileUI {
|
||||
manualCount: number;
|
||||
}
|
||||
|
||||
// 数据库函数返回的评查文件结构
|
||||
interface ReviewFileFromSQL {
|
||||
id: number;
|
||||
status: string;
|
||||
path: string;
|
||||
file_name: string;
|
||||
file_code: string;
|
||||
file_type_name: string;
|
||||
file_type_id: number;
|
||||
file_size: number;
|
||||
upload_time: string;
|
||||
created_at: string;
|
||||
evaluations_status: number;
|
||||
audit_status: number | null;
|
||||
created_by_user_id: number | null;
|
||||
issue_count: number;
|
||||
total_score: number;
|
||||
pass_count: number;
|
||||
warning_count: number;
|
||||
fail_count: number;
|
||||
manual_count: number;
|
||||
issues: Array<{
|
||||
severity: 'info' | 'warning' | 'error' | 'critical';
|
||||
message: string;
|
||||
}> | null;
|
||||
}
|
||||
|
||||
// 文件列表搜索参数
|
||||
export interface DocumentSearchParams {
|
||||
@@ -133,183 +106,7 @@ export function mapUIToReviewStatus(status: string): number {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件扩展名
|
||||
* @param fileName 文件名
|
||||
* @returns 文件扩展名
|
||||
*/
|
||||
export function getFileExtension(fileName: string): string {
|
||||
return fileName.split('.').pop()?.toLowerCase() || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评查文件列表
|
||||
* @param searchParams 搜索参数
|
||||
* @param documentIds 文档ID数组(可选)
|
||||
* @param userId 用户ID
|
||||
* @returns 评查文件列表和总数
|
||||
*/
|
||||
export async function getReviewFiles(searchParams: DocumentSearchParams = {}, documentIds: number[] | null = null, userId?: string): Promise<{
|
||||
data?: { files: ReviewFileUI[], total: number };
|
||||
error?: string;
|
||||
status?: number;
|
||||
}> {
|
||||
try {
|
||||
// 确保userId必须存在,如果不存在则抛出错误
|
||||
if (!userId) {
|
||||
return { error: '用户身份验证失败,无法获取评查文件列表', status: 401 };
|
||||
}
|
||||
|
||||
const {
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
keyword,
|
||||
fileType, // sessionStorage.getItem('reviewType')
|
||||
reviewStatus,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
sortOrder = 'upload_time_desc'
|
||||
} = searchParams;
|
||||
|
||||
let p_typeid: number[] | null = null;
|
||||
if (fileType) {
|
||||
if (fileType === 'record') {
|
||||
p_typeid = [2, 3, 155];
|
||||
} else if (fileType === 'contract') {
|
||||
p_typeid = [1];
|
||||
} else {
|
||||
const typeId = parseInt(fileType, 10);
|
||||
if (!isNaN(typeId)) {
|
||||
p_typeid = [typeId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rpcParams = {
|
||||
p_keyword: keyword || null,
|
||||
p_typeid: p_typeid,
|
||||
p_evaluations_status: reviewStatus ? mapUIToReviewStatus(reviewStatus) : null,
|
||||
p_date_from: dateFrom || null,
|
||||
p_date_to: dateTo || null,
|
||||
p_document_ids: documentIds || null,
|
||||
p_user_id: parseInt(userId, 10), // 强制要求传递用户ID
|
||||
};
|
||||
|
||||
const listParams = {
|
||||
...rpcParams,
|
||||
p_page: page,
|
||||
p_page_size: pageSize,
|
||||
p_sort_order: sortOrder
|
||||
};
|
||||
|
||||
// 并行执行获取数据和获取总数的请求
|
||||
const [filesResponse, countResponse] = await Promise.all([
|
||||
postgrestPost<ReviewFileFromSQL[]>('rpc/get_review_files_with_details', listParams),
|
||||
postgrestPost<number>('rpc/count_review_files', rpcParams)
|
||||
]);
|
||||
|
||||
// 处理获取文档列表的错误
|
||||
if (filesResponse.error || !filesResponse.data) {
|
||||
return { error: filesResponse.error || '获取文档数据失败', status: filesResponse.status || 500 };
|
||||
}
|
||||
|
||||
// 处理获取总数的错误
|
||||
if (countResponse.error || typeof countResponse.data !== 'number') {
|
||||
console.error('获取文档总数失败:', countResponse.error);
|
||||
}
|
||||
|
||||
const totalCount = typeof countResponse.data === 'number' ? countResponse.data : 0;
|
||||
|
||||
// 将SQL返回的数据转换为UI格式
|
||||
const reviewFiles: ReviewFileUI[] = filesResponse.data.map((file: ReviewFileFromSQL) => ({
|
||||
id: file.id.toString(),
|
||||
status: file.status,
|
||||
path: file.path,
|
||||
fileName: file.file_name,
|
||||
fileCode: file.file_code,
|
||||
fileType: file.file_type_name,
|
||||
fileTypeId: file.file_type_id,
|
||||
fileSize: file.file_size,
|
||||
uploadTime: formatDate(file.created_at),
|
||||
reviewStatus: mapReviewStatusToUI(file.evaluations_status),
|
||||
reviewStatusCode: file.evaluations_status,
|
||||
issueCount: file.issue_count,
|
||||
score: file.total_score,
|
||||
auditStatus: file.audit_status,
|
||||
issues: file.issues || [],
|
||||
createdBy: file.created_by_user_id?.toString() || '系统',
|
||||
passCount: file.pass_count,
|
||||
warningCount: file.warning_count,
|
||||
failCount: file.fail_count,
|
||||
manualCount: file.manual_count,
|
||||
}));
|
||||
|
||||
return {
|
||||
data: {
|
||||
files: reviewFiles,
|
||||
total: totalCount
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取评查文件列表失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '获取评查文件列表失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件的评查状态
|
||||
* @param id 文件ID
|
||||
* @param status 评查状态
|
||||
* @returns 更新后的文件信息
|
||||
*/
|
||||
// export async function updateReviewStatus(id: string, status: string): Promise<{
|
||||
// data?: ReviewFileUI;
|
||||
// error?: string;
|
||||
// status?: number;
|
||||
// }> {
|
||||
// try {
|
||||
// if (!id) {
|
||||
// return { error: '文件ID不能为空', status: 400 };
|
||||
// }
|
||||
|
||||
// const statusValue = mapUIToReviewStatus(status);
|
||||
|
||||
// const response = await postgrestPut<Document, Partial<Document>>(
|
||||
// 'documents',
|
||||
// { evaluations_status: statusValue },
|
||||
// { id: parseInt(id) }
|
||||
// );
|
||||
|
||||
// if (response.error) {
|
||||
// return { error: response.error, status: response.status };
|
||||
// }
|
||||
|
||||
// const extractedData = extractApiData<Document>(response.data);
|
||||
|
||||
// if (!extractedData) {
|
||||
// return { error: '更新评查状态失败', status: 500 };
|
||||
// }
|
||||
|
||||
// // 获取文档类型,用于查找文档类型名称
|
||||
// const documentTypesResponse = await getDocumentTypes({pageSize: 500});
|
||||
// const documentTypes = documentTypesResponse.data?.types || [];
|
||||
|
||||
// // 查找文档类型名称
|
||||
// const docType = documentTypes.find((type: DocumentTypeUI) => type.id === extractedData.type_id);
|
||||
// const typeName = docType ? docType.name : '未知类型';
|
||||
|
||||
// return { data: convertToReviewFileUI(extractedData, typeName) };
|
||||
// } catch (error) {
|
||||
// console.error('更新评查状态失败:', error);
|
||||
// return {
|
||||
// error: error instanceof Error ? error.message : '更新评查状态失败',
|
||||
// status: 500
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 更新文件的审核状态
|
||||
|
||||
Reference in New Issue
Block a user