feat: 1. 完善起草合同页面的逻辑交互,对接minio的接口操作
This commit is contained in:
@@ -88,122 +88,6 @@ export interface RuleGroupQueryParams {
|
||||
token?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评查点分组列表(支持分页、筛选、排序)
|
||||
* @deprecated 使用 getEvaluationPointGroups 代替(FastAPI v3)
|
||||
* @param params 查询参数
|
||||
* @returns 评查点分组列表和总数
|
||||
*/
|
||||
export async function getRuleGroups_legacy(
|
||||
params?: RuleGroupQueryParams
|
||||
): Promise<{data: RuleGroup[]; totalCount?: number; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
const {
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
name,
|
||||
code,
|
||||
is_enabled,
|
||||
pid = '0', // 默认获取一级分组
|
||||
orderBy = 'created_at',
|
||||
order = 'desc',
|
||||
token
|
||||
} = params || {};
|
||||
|
||||
// 构建筛选条件
|
||||
const filter: Record<string, string> = {};
|
||||
|
||||
// 父级ID筛选 (pid=null或'0'表示一级分组)
|
||||
if (pid === null || pid === '0') {
|
||||
filter['pid'] = 'eq.0';
|
||||
} else if (pid) {
|
||||
filter['pid'] = `eq.${pid}`;
|
||||
}
|
||||
|
||||
// 名称模糊搜索
|
||||
if (name) {
|
||||
filter['name'] = `ilike.*${name}*`;
|
||||
}
|
||||
|
||||
// 编码模糊搜索
|
||||
if (code) {
|
||||
filter['code'] = `ilike.*${code}*`;
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if (is_enabled !== undefined) {
|
||||
filter['is_enabled'] = `eq.${is_enabled}`;
|
||||
}
|
||||
|
||||
const postgrestParams: PostgrestParams = {
|
||||
select: `
|
||||
id,
|
||||
pid,
|
||||
name,
|
||||
code,
|
||||
description,
|
||||
is_enabled,
|
||||
created_at
|
||||
`,
|
||||
filter,
|
||||
order: `${orderBy}.${order}`, // PostgREST order format: field.direction
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
token
|
||||
};
|
||||
|
||||
const response = await postgrestGet<{code: number; msg: string; data: Array<{
|
||||
id: number;
|
||||
pid: number;
|
||||
name: string;
|
||||
code?: string;
|
||||
description?: string;
|
||||
is_enabled: boolean;
|
||||
created_at?: string;
|
||||
}>}>('evaluation_point_groups', postgrestParams);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
// 处理响应数据
|
||||
let groups: RuleGroup[] = [];
|
||||
if (response.data && 'code' in response.data && response.data.data) {
|
||||
groups = response.data.data.map(group => ({
|
||||
id: group.id.toString(),
|
||||
pid: group.pid.toString(),
|
||||
name: group.name,
|
||||
code: group.code,
|
||||
description: group.description,
|
||||
is_enabled: group.is_enabled,
|
||||
createdAt: group.created_at ? formatDate(group.created_at) : undefined
|
||||
}));
|
||||
} else if (Array.isArray(response.data)) {
|
||||
groups = response.data.map(group => ({
|
||||
id: group.id.toString(),
|
||||
pid: group.pid.toString(),
|
||||
name: group.name,
|
||||
code: group.code,
|
||||
description: group.description,
|
||||
is_enabled: group.is_enabled,
|
||||
createdAt: group.created_at ? formatDate(group.created_at) : undefined
|
||||
}));
|
||||
}
|
||||
|
||||
// 注意:由于当前 PostgREST 客户端不支持 count 参数,totalCount 返回当前页的记录数
|
||||
// 后续可优化为单独查询获取准确的总数
|
||||
return {
|
||||
data: groups,
|
||||
totalCount: groups.length
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取评查点分组列表失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '获取评查点分组列表失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定分组的子分组(包含评查点数量统计)
|
||||
@@ -241,204 +125,6 @@ export async function getChildGroups(parentId: string, token?: string): Promise<
|
||||
|
||||
|
||||
|
||||
|
||||
// ==================== 批量操作接口 ====================
|
||||
|
||||
/**
|
||||
* 批量更新分组状态(启用/禁用)
|
||||
* @deprecated 使用 batchUpdateEvaluationPointGroupStatus 代替(FastAPI v3)
|
||||
* @param ids 分组ID列表
|
||||
* @param is_enabled 目标状态
|
||||
* @param token JWT token (可选)
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function batchUpdateRuleGroupStatus_legacy(
|
||||
ids: string[],
|
||||
is_enabled: boolean,
|
||||
token?: string
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
updated_count: number;
|
||||
failed_ids: string[];
|
||||
errors?: Array<{ id: string; error: string }>;
|
||||
}> {
|
||||
try {
|
||||
// ========== 1. 参数验证 ==========
|
||||
|
||||
if (!Array.isArray(ids) || ids.length === 0) {
|
||||
return {
|
||||
success: false,
|
||||
updated_count: 0,
|
||||
failed_ids: [],
|
||||
errors: [{ id: 'validation', error: 'ID列表不能为空' }]
|
||||
};
|
||||
}
|
||||
|
||||
// 验证每个ID的有效性
|
||||
const invalidIds = ids.filter(id => !id || id.trim() === '');
|
||||
if (invalidIds.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
updated_count: 0,
|
||||
failed_ids: ids,
|
||||
errors: [{ id: 'validation', error: '存在无效的分组ID' }]
|
||||
};
|
||||
}
|
||||
|
||||
// ========== 2. 逐个更新(确保每个分组都能被正确处理) ==========
|
||||
|
||||
const failedIds: string[] = [];
|
||||
const errors: Array<{ id: string; error: string }> = [];
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 验证分组是否存在
|
||||
const groupResponse = await getRuleGroup(id, token);
|
||||
if (groupResponse.error || !groupResponse.data) {
|
||||
failedIds.push(id);
|
||||
errors.push({ id, error: '分组不存在或无法访问' });
|
||||
continue;
|
||||
}
|
||||
|
||||
// 执行更新
|
||||
const updateResponse = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, Partial<ApiRuleGroup>>(
|
||||
'evaluation_point_groups',
|
||||
{ is_enabled },
|
||||
{ id },
|
||||
token
|
||||
);
|
||||
|
||||
if (updateResponse.error) {
|
||||
failedIds.push(id);
|
||||
errors.push({ id, error: updateResponse.error });
|
||||
} else {
|
||||
updatedCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
failedIds.push(id);
|
||||
errors.push({
|
||||
id,
|
||||
error: error instanceof Error ? error.message : '更新失败'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 3. 返回结果 ==========
|
||||
|
||||
return {
|
||||
success: failedIds.length === 0,
|
||||
updated_count: updatedCount,
|
||||
failed_ids: failedIds,
|
||||
errors: errors.length > 0 ? errors : undefined
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('批量更新分组状态失败:', error);
|
||||
return {
|
||||
success: false,
|
||||
updated_count: 0,
|
||||
failed_ids: ids,
|
||||
errors: [{
|
||||
id: 'batch',
|
||||
error: error instanceof Error ? error.message : '批量更新失败'
|
||||
}]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除分组(安全的阻止删除策略)
|
||||
* @deprecated 使用 batchDeleteEvaluationPointGroups 代替(FastAPI v3)
|
||||
* @param ids 分组ID列表
|
||||
* @param token JWT token (可选)
|
||||
* @returns 删除结果
|
||||
*/
|
||||
export async function batchDeleteRuleGroups_legacy(
|
||||
ids: string[],
|
||||
token?: string
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
deleted_count: number;
|
||||
failed_ids: string[];
|
||||
errors?: Array<{ id: string; error: string; details?: { hasChildren?: boolean; hasPoints?: boolean } }>;
|
||||
}> {
|
||||
try {
|
||||
// ========== 1. 参数验证 ==========
|
||||
|
||||
if (!Array.isArray(ids) || ids.length === 0) {
|
||||
return {
|
||||
success: false,
|
||||
deleted_count: 0,
|
||||
failed_ids: [],
|
||||
errors: [{ id: 'validation', error: 'ID列表不能为空' }]
|
||||
};
|
||||
}
|
||||
|
||||
// 验证每个ID的有效性
|
||||
const invalidIds = ids.filter(id => !id || id.trim() === '');
|
||||
if (invalidIds.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
deleted_count: 0,
|
||||
failed_ids: ids,
|
||||
errors: [{ id: 'validation', error: '存在无效的分组ID' }]
|
||||
};
|
||||
}
|
||||
|
||||
// ========== 2. 逐个删除(使用安全的阻止删除策略) ==========
|
||||
|
||||
const failedIds: string[] = [];
|
||||
const errors: Array<{ id: string; error: string; details?: { hasChildren?: boolean; hasPoints?: boolean } }> = [];
|
||||
let deletedCount = 0;
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
const deleteResult = await deleteRuleGroup(id, token);
|
||||
|
||||
if (!deleteResult.success) {
|
||||
failedIds.push(id);
|
||||
errors.push({
|
||||
id,
|
||||
error: deleteResult.error || '删除失败',
|
||||
details: deleteResult.details ? {
|
||||
hasChildren: deleteResult.details.hasChildren,
|
||||
hasPoints: deleteResult.details.hasPoints
|
||||
} : undefined
|
||||
});
|
||||
} else {
|
||||
deletedCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
failedIds.push(id);
|
||||
errors.push({
|
||||
id,
|
||||
error: error instanceof Error ? error.message : '删除失败'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 3. 返回结果 ==========
|
||||
|
||||
return {
|
||||
success: failedIds.length === 0,
|
||||
deleted_count: deletedCount,
|
||||
failed_ids: failedIds,
|
||||
errors: errors.length > 0 ? errors : undefined
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('批量删除分组失败:', error);
|
||||
return {
|
||||
success: false,
|
||||
deleted_count: 0,
|
||||
failed_ids: ids,
|
||||
errors: [{
|
||||
id: 'batch',
|
||||
error: error instanceof Error ? error.message : '批量删除失败'
|
||||
}]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// FastAPI v3 接口函数(新版)
|
||||
// ========================================
|
||||
|
||||
Reference in New Issue
Block a user