feat: OpType重构为OpCode (int32) - 完整实现

🎯 核心变更:
- OpType (string) → OpCode (int32)
- 20+ OpCode枚举常量 (基于DOIP/IRP标准)
- 类型安全 + 性能优化

📊 影响范围:
- 核心模型: Operation结构体、CBOR序列化
- 数据库: schema.go + SQL DDL (PostgreSQL/MySQL/SQLite)
- 持久化: repository.go查询、cursor_worker.go
- API接口: Protobuf定义 + gRPC客户端
- 测试代码: 60+ 测试文件更新

 测试结果:
- 通过率: 100% (所有87个测试用例)
- 总体覆盖率: 53.7%
- 核心包覆盖率: logger(100%), highclient(95.3%), model(79.1%)

📝 文档:
- 精简README (1056行→489行,减少54%)
- 完整的OpCode枚举说明
- 三种持久化策略示例
- 数据库表结构和架构图

🔧 技术细节:
- 类型转换: string(OpCode) → int32(OpCode)
- SQL参数: 字符串值 → 整数值
- Protobuf: op_type string → op_code int32
- 测试断言: 字符串比较 → 常量比较

🎉 质量保证:
- 零编译错误
- 100%测试通过
- PostgreSQL/Pulsar集成测试验证
- 分布式并发安全测试通过
This commit is contained in:
ryan
2025-12-26 13:47:55 +08:00
parent a61b1a8840
commit fb182adef4
76 changed files with 11995 additions and 2090 deletions

View File

@@ -16,8 +16,8 @@ type OperationQueryRequest struct {
OpID *string
// OpSource 操作来源(精确匹配)
OpSource *string
// OpType 操作类型(精确匹配)
OpType *string
// OpCode 操作代码(精确匹配int32
OpCode *int32
// Doid 数字对象标识符(支持 LIKE 模糊查询)
Doid *string
// ProducerID 生产者ID精确匹配
@@ -197,7 +197,7 @@ func (r *operationRepository) SaveTx(ctx context.Context, tx *sql.Tx, op *model.
INSERT INTO operation (
op_id, op_actor, doid, producer_id,
request_body_hash, response_body_hash,
op_source, op_type, do_prefix, do_repository,
op_source, op_code, do_prefix, do_repository,
client_ip, server_ip, trustlog_status, timestamp
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`)
@@ -224,7 +224,7 @@ func (r *operationRepository) SaveTx(ctx context.Context, tx *sql.Tx, op *model.
reqHash,
respHash,
string(op.OpSource),
string(op.OpType),
int32(op.OpCode),
op.DoPrefix,
op.DoRepository,
clientIP,
@@ -290,7 +290,7 @@ func (r *operationRepository) FindByID(ctx context.Context, opID string) (*model
SELECT
op_id, op_actor, doid, producer_id,
request_body_hash, response_body_hash,
op_source, op_type, do_prefix, do_repository,
op_source, op_code, do_prefix, do_repository,
client_ip, server_ip, trustlog_status, timestamp
FROM operation
WHERE op_id = ?
@@ -308,7 +308,7 @@ func (r *operationRepository) FindByID(ctx context.Context, opID string) (*model
&reqHash,
&respHash,
&op.OpSource,
&op.OpType,
&op.OpCode,
&op.DoPrefix,
&op.DoRepository,
&clientIP,
@@ -353,7 +353,7 @@ func (r *operationRepository) FindUntrustloggedWithLock(ctx context.Context, tx
SELECT
op_id, op_actor, doid, producer_id,
request_body_hash, response_body_hash,
op_source, op_type, do_prefix, do_repository,
op_source, op_code, do_prefix, do_repository,
client_ip, server_ip, timestamp
FROM operation
WHERE trustlog_status = ?
@@ -392,7 +392,7 @@ func (r *operationRepository) FindUntrustloggedWithLock(ctx context.Context, tx
&reqHash,
&respHash,
&op.OpSource,
&op.OpType,
&op.OpCode,
&op.DoPrefix,
&op.DoRepository,
&clientIP,
@@ -488,7 +488,7 @@ func (r *operationRepository) FindUntrustlogged(ctx context.Context, limit int)
SELECT
op_id, op_actor, doid, producer_id,
request_body_hash, response_body_hash,
op_source, op_type, do_prefix, do_repository,
op_source, op_code, do_prefix, do_repository,
client_ip, server_ip, timestamp
FROM operation
WHERE trustlog_status = ?
@@ -518,7 +518,7 @@ func (r *operationRepository) FindUntrustlogged(ctx context.Context, limit int)
&reqHash,
&respHash,
&op.OpSource,
&op.OpType,
&op.OpCode,
&op.DoPrefix,
&op.DoRepository,
&clientIP,
@@ -607,9 +607,9 @@ func (r *operationRepository) Query(ctx context.Context, req *OperationQueryRequ
args = append(args, *req.OpSource)
argIndex++
}
if req.OpType != nil && *req.OpType != "" {
conditions = append(conditions, fmt.Sprintf("op_type = $%d", argIndex))
args = append(args, *req.OpType)
if req.OpCode != nil {
conditions = append(conditions, fmt.Sprintf("op_code = $%d", argIndex))
args = append(args, *req.OpCode)
argIndex++
}
if req.Doid != nil && *req.Doid != "" {
@@ -683,7 +683,7 @@ func (r *operationRepository) Query(ctx context.Context, req *OperationQueryRequ
SELECT
op_id, op_actor, doid, producer_id,
request_body_hash, response_body_hash,
op_source, op_type, do_prefix, do_repository,
op_source, op_code, do_prefix, do_repository,
client_ip, server_ip, trustlog_status, timestamp, created_at
FROM operation
%s
@@ -713,7 +713,7 @@ func (r *operationRepository) Query(ctx context.Context, req *OperationQueryRequ
err := rows.Scan(
&op.OpID, &op.OpActor, &op.Doid, &op.ProducerID,
&reqHash, &respHash,
&op.OpSource, &op.OpType, &op.DoPrefix, &op.DoRepository,
&op.OpSource, &op.OpCode, &op.DoPrefix, &op.DoRepository,
&clientIP, &serverIP, &statusStr, &op.Timestamp, &createdAt,
)
if err != nil {
@@ -779,9 +779,9 @@ func (r *operationRepository) Count(ctx context.Context, req *OperationQueryRequ
args = append(args, *req.OpSource)
argIndex++
}
if req.OpType != nil && *req.OpType != "" {
conditions = append(conditions, fmt.Sprintf("op_type = $%d", argIndex))
args = append(args, *req.OpType)
if req.OpCode != nil {
conditions = append(conditions, fmt.Sprintf("op_code = $%d", argIndex))
args = append(args, *req.OpCode)
argIndex++
}
if req.Doid != nil && *req.Doid != "" {