feat: 添加 Operation 查询功能及完整测试
主要功能: - 新增 OperationQueryRequest/OperationQueryResult 结构体 - 实现 Repository.Query() - 支持多条件筛选、分页、排序 - 实现 Repository.Count() - 统计记录数 - 新增 PersistenceClient.QueryOperations/CountOperations/GetOperationByID 查询功能: - 支持按 OpID、OpSource、OpType、Doid 等字段筛选 - 支持模糊查询(Doid、DoPrefix) - 支持时间范围查询(TimeFrom/TimeTo) - 支持 IP 地址筛选(ClientIP、ServerIP) - 支持按 TrustlogStatus 筛选 - 支持组合查询 - 支持分页(PageSize、PageNumber) - 支持排序(OrderBy、OrderDesc) 测试覆盖: - ✅ query_test.go - 查询功能单元测试 - ✅ pg_query_integration_test.go - PostgreSQL 集成测试(16个测试用例) * Query all records * Filter by OpSource/OpType/Status/Actor/Producer/IP * DOID 模糊查询 * 时间范围查询 * 分页测试 * 排序测试(升序/降序) * 组合查询 * Count 统计 * PersistenceClient 接口测试 修复: - 修复 TestClusterSafety_MultipleCursorWorkers - 添加缺失字段 - 修复 TestCursorInitialization - 确保 schema 最新 - 添加自动 schema 更新(ALTER TABLE IF NOT EXISTS) 测试结果: - ✅ 所有单元测试通过(100%) - ✅ 所有集成测试通过(PostgreSQL、Pulsar、E2E) - ✅ Query 功能测试通过(16个测试用例)
This commit is contained in:
@@ -396,3 +396,45 @@ func (c *PersistenceClient) Close() error {
|
||||
c.logger.Info("persistence client closed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryOperations 查询操作记录(支持分页、筛选、排序)
|
||||
func (c *PersistenceClient) QueryOperations(ctx context.Context, req *OperationQueryRequest) (*OperationQueryResult, error) {
|
||||
if c.manager == nil {
|
||||
return nil, fmt.Errorf("persistence manager not initialized")
|
||||
}
|
||||
|
||||
repo := c.manager.GetOperationRepo()
|
||||
if repo == nil {
|
||||
return nil, fmt.Errorf("operation repository not available")
|
||||
}
|
||||
|
||||
return repo.Query(ctx, req)
|
||||
}
|
||||
|
||||
// CountOperations 统计符合条件的操作记录数
|
||||
func (c *PersistenceClient) CountOperations(ctx context.Context, req *OperationQueryRequest) (int64, error) {
|
||||
if c.manager == nil {
|
||||
return 0, fmt.Errorf("persistence manager not initialized")
|
||||
}
|
||||
|
||||
repo := c.manager.GetOperationRepo()
|
||||
if repo == nil {
|
||||
return 0, fmt.Errorf("operation repository not available")
|
||||
}
|
||||
|
||||
return repo.Count(ctx, req)
|
||||
}
|
||||
|
||||
// GetOperationByID 根据 OpID 查询单条操作记录
|
||||
func (c *PersistenceClient) GetOperationByID(ctx context.Context, opID string) (*model.Operation, TrustlogStatus, error) {
|
||||
if c.manager == nil {
|
||||
return nil, "", fmt.Errorf("persistence manager not initialized")
|
||||
}
|
||||
|
||||
repo := c.manager.GetOperationRepo()
|
||||
if repo == nil {
|
||||
return nil, "", fmt.Errorf("operation repository not available")
|
||||
}
|
||||
|
||||
return repo.FindByID(ctx, opID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user