From fda49b1541db5f386c240197c28e66e7055803b9 Mon Sep 17 00:00:00 2001 From: Wenyan Date: Tue, 25 Nov 2025 12:28:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(evaluation):=20=E6=A8=A1=E5=9D=972.5=20-?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E8=AF=84=E6=9F=A5=E7=82=B9=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 功能变更: 1. 新增 batchUpdateRuleStatus 函数 - 支持批量启用/禁用评查点 - 逐个验证评查点ID有效性 - 使用增强的 updateRule 函数确保数据完整性 - 支持部分成功场景 - 返回详细的操作结果: * success: 是否全部成功 * updated_count: 成功更新数量 * failed_ids: 失败的ID列表 * errors: 详细错误信息(包含每个失败ID的错误原因) 2. 新增 batchDeleteRules 函数 - 支持批量删除评查点 - 使用增强的 deleteRule 函数(自动包含关联检查) - 逐个验证每个评查点的删除条件: * ID存在性 * 关联评查结果检查 - 支持部分成功场景 - 返回详细的操作结果: * success: 是否全部成功 * deleted_count: 成功删除数量 * failed_ids: 失败的ID列表 * errors: 详细错误信息(包含每个失败ID的错误原因) 技术实现: - 复用增强的 getRule, updateRule, deleteRule 函数 - 继承所有单个操作的验证逻辑 - Try-catch 确保单个失败不影响整体流程 - 详细的错误追踪和报告 - 类型安全的返回值结构 安全性保障: - 批量删除时自动检查每个评查点的关联评查结果 - 如果评查点已被使用,阻止删除并记录错误 - 防止误删除造成数据不一致 - 提供清晰的失败原因帮助用户理解和处理 验收标准: ✅ 支持批量启用/禁用评查点 ✅ 支持批量删除评查点 ✅ 返回更新/删除成功数量 ✅ 返回失败的ID列表 ✅ 提供详细的错误信息 ✅ 支持部分成功场景 ✅ 批量删除包含关联检查 ✅ 类型安全的API设计 符合实施计划: - 阶段 2.5:评查点批量操作接口对接 ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/evaluation_points/rules.ts | 104 +++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/app/api/evaluation_points/rules.ts b/app/api/evaluation_points/rules.ts index 29eb3a7..7a68f0c 100644 --- a/app/api/evaluation_points/rules.ts +++ b/app/api/evaluation_points/rules.ts @@ -1823,4 +1823,108 @@ export async function getRuleStatistics(token?: string): Promise<{data: RuleStat status: 500 }; } +} + +/** + * 批量更新评查点启用状态 + * @param ids 评查点ID列表 + * @param is_enabled 启用状态 + * @param token JWT token (可选) + * @returns 批量更新结果 + */ +export async function batchUpdateRuleStatus( + ids: string[], + is_enabled: boolean, + token?: string +): Promise<{ + success: boolean; + updated_count: number; + failed_ids: string[]; + errors?: Array<{ id: string; error: string }>; +}> { + const failedIds: string[] = []; + const errors: Array<{ id: string; error: string }> = []; + let updatedCount = 0; + + // 逐个验证并更新 + for (const id of ids) { + try { + // 验证评查点是否存在 + const existingRule = await getRule(id, token); + if (existingRule.error || !existingRule.data) { + failedIds.push(id); + errors.push({ id, error: '评查点不存在' }); + continue; + } + + // 执行更新 + const updateResult = await updateRule(id, { isActive: is_enabled }, token); + if (updateResult.error) { + failedIds.push(id); + errors.push({ id, error: updateResult.error }); + } else { + updatedCount++; + } + } catch (error) { + failedIds.push(id); + errors.push({ + id, + error: error instanceof Error ? error.message : '更新失败' + }); + } + } + + return { + success: failedIds.length === 0, + updated_count: updatedCount, + failed_ids: failedIds, + errors: errors.length > 0 ? errors : undefined + }; +} + +/** + * 批量删除评查点 + * @param ids 评查点ID列表 + * @param token JWT token (可选) + * @returns 批量删除结果 + */ +export async function batchDeleteRules( + ids: string[], + token?: string +): Promise<{ + success: boolean; + deleted_count: number; + failed_ids: string[]; + errors?: Array<{ id: string; error: string }>; +}> { + const failedIds: string[] = []; + const errors: Array<{ id: string; error: string }> = []; + let deletedCount = 0; + + // 逐个验证并删除 + for (const id of ids) { + try { + // 使用增强的 deleteRule 函数(包含关联检查) + const deleteResult = await deleteRule(id, token); + if (deleteResult.error) { + failedIds.push(id); + errors.push({ id, error: deleteResult.error }); + } else { + deletedCount++; + } + } catch (error) { + failedIds.push(id); + errors.push({ + id, + error: error instanceof Error ? error.message : '删除失败' + }); + } + } + + return { + success: failedIds.length === 0, + deleted_count: deletedCount, + failed_ids: failedIds, + errors: errors.length > 0 ? errors : undefined + }; } \ No newline at end of file