From 87ad3376fe36991c89683a8612d8fb96a8c128a0 Mon Sep 17 00:00:00 2001 From: yorn <1057707203@qq.com> Date: Tue, 3 Jun 2025 21:06:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=B7=E5=AE=97=E5=92=8C?= =?UTF-8?q?=E5=90=88=E5=90=8C=E7=9A=84=E6=95=B0=E6=8D=AE=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=E7=9A=84=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/evaluation_points/reviews.ts | 23 ++- app/api/evaluation_points/rules-files.ts | 5 +- app/api/evaluation_points/rules.ts | 56 +++++- app/components/layout/Layout.tsx | 2 +- app/components/layout/Sidebar.tsx | 14 +- app/components/reviews/ReviewPointsList.tsx | 54 +++--- app/routes/files.upload.tsx | 11 ++ app/routes/reviews.tsx | 3 +- app/routes/rules-files.tsx | 71 +++++-- app/routes/rules._index.tsx | 195 +++++++++++++++----- 10 files changed, 326 insertions(+), 108 deletions(-) diff --git a/app/api/evaluation_points/reviews.ts b/app/api/evaluation_points/reviews.ts index 2a4df4c..37fb7e6 100644 --- a/app/api/evaluation_points/reviews.ts +++ b/app/api/evaluation_points/reviews.ts @@ -58,6 +58,7 @@ interface AuditStatus { document_id: string | number; evaluation_point_id: string | number; edit_audit_status: number; + message: string; [key: string]: unknown; } @@ -205,13 +206,13 @@ export async function getReviewPoints(fileId: string) { const manualReviewPointsData = extractApiData(manualReviewPointsResponse.data); // 构建评查点ID到editAuditStatus的映射 - const editAuditStatusMap = new Map(); + const editAuditStatusMap = new Map(); // 如果有查询结果,则根据evaluation_point_id索引到对应数据 if (manualReviewPointsData && Array.isArray(manualReviewPointsData)) { manualReviewPointsData.forEach(auditStatus => { if (auditStatus.evaluation_point_id && auditStatus.edit_audit_status !== undefined) { - editAuditStatusMap.set(auditStatus.evaluation_point_id, {id: auditStatus.id, status: auditStatus.edit_audit_status}); + editAuditStatusMap.set(auditStatus.evaluation_point_id, {id: auditStatus.id, status: auditStatus.edit_audit_status, message: auditStatus.message}); } }); } @@ -220,7 +221,7 @@ export async function getReviewPoints(fileId: string) { if (manualReviewPointsIds.length > 0) { manualReviewPointsIds.forEach(pointId => { if (!editAuditStatusMap.has(pointId)) { - editAuditStatusMap.set(pointId, {id: '', status: 0}); + editAuditStatusMap.set(pointId, {id: '', status: 0, message: ''}); } }); } @@ -247,7 +248,7 @@ export async function getReviewPoints(fileId: string) { const resultData: ReviewPointResult[] = evaluationResultsData.map(result => { const point = pointsMap.get(result.evaluation_point_id) || {} as EvaluationPoint; const group = groupsMap.get(point.evaluation_point_groups_id || 0) || {} as EvaluationPointGroup; - const editAuditStatus = editAuditStatusMap.get(result.evaluation_point_id) || {id: '', status: 0}; + const editAuditStatus = editAuditStatusMap.get(result.evaluation_point_id) || {id: '', status: 0, message: ''}; // 评查结果内容改成由evaluated_point_results_log中获取 const evaluatedPointResultsLog = result.evaluated_point_results_log || {}; @@ -304,6 +305,7 @@ export async function getReviewPoints(fileId: string) { pointId: point.id, editAuditStatusId: editAuditStatus.id, editAuditStatus: editAuditStatus.status, + editAuditStatusMessage: editAuditStatus.message, title: message, pointName: point.name || '', groupName: group.name || '', @@ -667,8 +669,8 @@ export async function updateReviewResult(resultId: string, editAuditStatusId: st // 构建要更新的数据,保留原有字段 const updatedEvaluatedResults = { ...currentEvaluatedResults, - // 如果是重新审核操作,不更新result,只更新message - ...(isReview ? { message } : { result: result === 'true' ? true : false, message }), + // 如果是重新审核操作,不更新result和message + ...(isReview ? {} : { result: result === 'true' ? true : false, message }), }; const updatedData = { @@ -696,7 +698,11 @@ export async function updateReviewResult(resultId: string, editAuditStatusId: st // 更新现有审核状态记录 const auditStatusResponse = await postgrestPut( 'audit_status', - { edit_audit_status: editAuditStatusValue }, + { + edit_audit_status: editAuditStatusValue, + // 重新审核时不更新message + ...(isReview ? {} : { message }) + }, { id: editAuditStatusId } ); @@ -714,7 +720,8 @@ export async function updateReviewResult(resultId: string, editAuditStatusId: st document_id: documentId, evaluation_point_id: evaluationPointId, evaluation_result_id: resultId, - edit_audit_status: editAuditStatusValue + edit_audit_status: editAuditStatusValue, + message: isReview ? '' : message }; // 使用postgrestPost创建新记录 diff --git a/app/api/evaluation_points/rules-files.ts b/app/api/evaluation_points/rules-files.ts index 3a481a3..03b5b97 100644 --- a/app/api/evaluation_points/rules-files.ts +++ b/app/api/evaluation_points/rules-files.ts @@ -267,11 +267,12 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P // 处理文件类型筛选 if (searchParams.fileType) { + // console.log('API处理文件类型筛选:', searchParams.fileType); // 特殊处理 'record' 类型,表示 type_id 为 2 或 3 if (searchParams.fileType === 'record') { filter['type_id'] = 'in.(2,3)'; } else { - filter['type_id'] = `eq.${searchParams.fileType}`; + filter['type_id'] = `eq.${Number(searchParams.fileType)}`; } } @@ -319,7 +320,7 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P // } params.filter = filter; - // console.log('params-----',params); + // console.log('API请求参数:', params); // 发送API请求获取文档列表 const response = await postgrestGet('documents', params); diff --git a/app/api/evaluation_points/rules.ts b/app/api/evaluation_points/rules.ts index 4ac1bb0..23efce8 100644 --- a/app/api/evaluation_points/rules.ts +++ b/app/api/evaluation_points/rules.ts @@ -34,6 +34,7 @@ export interface RulesQueryParams { keyword?: string; orderBy?: string; orderDirection?: 'asc' | 'desc'; + reviewType?: string; // 添加 reviewType 参数,值为 contract 或 record } /** @@ -162,7 +163,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul isActive, keyword, orderBy = 'created_at', - orderDirection = 'desc' + orderDirection = 'desc', + reviewType } = params; // 构建PostgrestParams参数 @@ -204,6 +206,46 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul postgrestParams.filter!['is_enabled'] = `eq.${isActive}`; } + // 根据reviewType添加过滤条件 + if (reviewType) { + try { + // 先获取所有评查点组数据,用于找到对应的pid + const groupsAllResponse = await postgrestGet<{code: number; msg: string; data: Array<{id: number; pid: number}>}>('evaluation_point_groups', { + select: 'id,pid' + }); + + let groups: Array<{id: number; pid: number}> = []; + + if (!groupsAllResponse.error) { + if (groupsAllResponse.data && 'code' in groupsAllResponse.data && groupsAllResponse.data.data) { + groups = groupsAllResponse.data.data; + } else if (Array.isArray(groupsAllResponse.data)) { + groups = groupsAllResponse.data; + } + } + + // 根据reviewType过滤pid + let pidList: number[] = []; + + if (reviewType === 'contract') { + // 合同类型,找到所有pid=3的评查点组 + const contractGroups = groups.filter(g => g.pid === 3).map(g => g.id); + pidList = contractGroups; + } else if (reviewType === 'record') { + // 卷宗类型,找到所有pid=1或pid=2的评查点组 + const recordGroups = groups.filter(g => g.pid === 1 || g.pid === 2).map(g => g.id); + pidList = recordGroups; + } + + // 如果有过滤的组id,则添加到查询条件中 + if (pidList.length > 0) { + postgrestParams.filter!['evaluation_point_groups_id'] = `in.(${pidList.join(',')})`; + } + } catch (error) { + console.error('获取评查点组数据出错:', error); + } + } + // 如果指定了评查点类型ID,需要先查询该类型下的所有规则组ID if (ruleType) { try { @@ -790,9 +832,10 @@ export interface RuleGroup { /** * 获取评查点类型列表 + * @param reviewType 评查类型,contract表示合同,record表示卷宗 * @returns 评查点类型列表 */ -export async function getRuleTypes(): Promise<{data: RuleType[]; error?: never} | {data?: never; error: string; status?: number}> { +export async function getRuleTypes(reviewType?: string): Promise<{data: RuleType[]; error?: never} | {data?: never; error: string; status?: number}> { try { // 构建PostgrestParams参数 const postgrestParams: PostgrestParams = { @@ -810,6 +853,15 @@ export async function getRuleTypes(): Promise<{data: RuleType[]; error?: never} } }; + // 根据 reviewType 添加过滤条件 + if (reviewType === 'contract') { + // 如果是合同类型,只加载id=3的评查点类型 + postgrestParams.filter!['id'] = 'eq.3'; + } else if (reviewType === 'record') { + // 如果是卷宗类型,只加载id=1和id=2的评查点类型 + postgrestParams.filter!['id'] = 'in.(1,2)'; + } + // 发送请求获取评查点类型列表 const response = await postgrestGet<{code: number; msg: string; data: Array<{ id: number; diff --git a/app/components/layout/Layout.tsx b/app/components/layout/Layout.tsx index f48fc32..26e3457 100644 --- a/app/components/layout/Layout.tsx +++ b/app/components/layout/Layout.tsx @@ -73,7 +73,7 @@ export function Layout({ children, userRole = 'developer' }: LayoutProps) { if (typeof window !== 'undefined') { try { const reviewType = sessionStorage.getItem('reviewType'); - console.log('Layout 路由变化, reviewType:', reviewType, '路径:', location.pathname); + // console.log('Layout 路由变化, reviewType:', reviewType, '路径:', location.pathname); if (reviewType && REVIEW_TYPE_TO_APP[reviewType]) { setSelectedApp(REVIEW_TYPE_TO_APP[reviewType]); } diff --git a/app/components/layout/Sidebar.tsx b/app/components/layout/Sidebar.tsx index f87fd90..ef565ea 100644 --- a/app/components/layout/Sidebar.tsx +++ b/app/components/layout/Sidebar.tsx @@ -147,13 +147,13 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = 'contract path: '/rules-files', icon: 'ri-list-check-2' }, - { - id: 'rule-new', - title: '新增评查点', - path: '/rules-new', - requiredRole: 'developer', - icon: 'ri-add-circle-line' - }, + // { + // id: 'rule-new', + // title: '新增评查点', + // path: '/rules-new', + // requiredRole: 'developer', + // icon: 'ri-add-circle-line' + // }, // { // id: 'review-detail', // title: '评查详情', diff --git a/app/components/reviews/ReviewPointsList.tsx b/app/components/reviews/ReviewPointsList.tsx index 964644c..f5ab8d4 100644 --- a/app/components/reviews/ReviewPointsList.tsx +++ b/app/components/reviews/ReviewPointsList.tsx @@ -78,6 +78,7 @@ export interface ReviewPoint { pointId?: string; editAuditStatusId?: string | number; editAuditStatus: number; + editAuditStatusMessage?: string; // 添加审核意见字段 pointName: string; title: string; groupName: string; @@ -354,19 +355,12 @@ export function ReviewPointsList({ // 初始化建议文本 useEffect(() => { - // 将所有评查点的建议文本存储到状态中 - const suggestions: Record = {}; - - reviewPoints.forEach(point => { - suggestions[point.id] = point.suggestion || ''; - }); - // setSuggestionTexts(suggestions); - // 使用函数式更新,不再需要外部 manualReviewNotes 变量 setManualReviewNotes(prev => { const notes = { ...prev }; reviewPoints.forEach(point => { - notes[point.id] = point.actionContent || ''; + // 优先使用editAuditStatusMessage,如果为空则使用actionContent或suggestion + notes[point.id] = point.editAuditStatusMessage || point.actionContent || point.suggestion || ''; }); return notes; }); @@ -388,37 +382,33 @@ export function ReviewPointsList({ * @param message 用户输入的审核内容 */ const handleReviewAction = (reviewPointResultId: string, editAuditStatusId: string | number | undefined, action: 'approve' | 'reject' | 'review', message: string) => { - // 更新评查点状态 - // console.log('handleReviewAction-------', reviewPointResultId, editAuditStatusId, action, message); - if(message.trim() === ''){ + // 通过/不通过时,必须有输入内容 + if(action !== 'review' && message.trim() === ''){ toastService.error('请输入审核意见'); return; } + if (action === 'review') { - // 重新审核时,不更新结果状态,只更新审核意见和审核状态 - // console.log('重新审核-------', reviewPointResultId, editAuditStatusId || '', 'review', message); + // 重新审核时,不更新结果状态,也不更新审核意见和审核状态 onStatusChange(reviewPointResultId, editAuditStatusId || '', 'review', message); // 找到当前评查点并更新其editAuditStatus为0,使其立即显示通过/不通过按钮 const updatedReviewPoint = reviewPoints.find(point => point.id === reviewPointResultId); if (updatedReviewPoint) { updatedReviewPoint.editAuditStatus = 0; + // 重新审核时不更新输入框内容 } } else { // 通过/不通过时,更新结果状态和审核意见 - // console.log('通过/不通过-------', reviewPointResultId, editAuditStatusId || '', action === 'approve' ? 'true' : 'false', message); onStatusChange(reviewPointResultId, editAuditStatusId || '', action === 'approve' ? 'true' : 'false', message); + + // 找到当前评查点并立即更新其editAuditStatusMessage + const updatedReviewPoint = reviewPoints.find(point => point.id === reviewPointResultId); + if (updatedReviewPoint) { + updatedReviewPoint.editAuditStatusMessage = message; + } } - // 将参数输出到控制台 - // console.log('评查点审核操作', { - // id: reviewPointResultId, - // editAuditStatusId: editAuditStatusId, - // action: action, - // content: message, - // status: action === 'approve' ? 'true' : (action === 'reject' ? 'false' : 'review') - // }); - // 清除编辑状态 setEditingReviewPoint(null); }; @@ -2008,10 +1998,11 @@ export function ReviewPointsList({
@@ -2034,7 +2025,7 @@ export function ReviewPointsList({ ) : ( @@ -2138,9 +2129,10 @@ export function ReviewPointsList({