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