feat(evaluation): 模块2.5 - 新增评查点批量操作接口
功能变更:
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user