fix(ops): 错误详情中显示账号和分组名称

- 在 GetErrorLogByID 查询中添加 LEFT JOIN 关联查询
- 关联 accounts 和 groups 表获取名称
- 填充 AccountName 和 GroupName 字段
This commit is contained in:
IanShaw027
2026-01-14 23:52:00 +08:00
parent 841d7ef2f2
commit f25f992a30

View File

@@ -300,50 +300,54 @@ func (r *opsRepository) GetErrorLogByID(ctx context.Context, id int64) (*service
q := ` q := `
SELECT SELECT
id, e.id,
created_at, e.created_at,
error_phase, e.error_phase,
error_type, e.error_type,
COALESCE(error_owner, ''), COALESCE(e.error_owner, ''),
COALESCE(error_source, ''), COALESCE(e.error_source, ''),
severity, e.severity,
COALESCE(upstream_status_code, status_code, 0), COALESCE(e.upstream_status_code, e.status_code, 0),
COALESCE(platform, ''), COALESCE(e.platform, ''),
COALESCE(model, ''), COALESCE(e.model, ''),
COALESCE(is_retryable, false), COALESCE(e.is_retryable, false),
COALESCE(retry_count, 0), COALESCE(e.retry_count, 0),
COALESCE(resolved, false), COALESCE(e.resolved, false),
resolved_at, e.resolved_at,
resolved_by_user_id, e.resolved_by_user_id,
resolved_retry_id, e.resolved_retry_id,
COALESCE(client_request_id, ''), COALESCE(e.client_request_id, ''),
COALESCE(request_id, ''), COALESCE(e.request_id, ''),
COALESCE(error_message, ''), COALESCE(e.error_message, ''),
COALESCE(error_body, ''), COALESCE(e.error_body, ''),
upstream_status_code, e.upstream_status_code,
COALESCE(upstream_error_message, ''), COALESCE(e.upstream_error_message, ''),
COALESCE(upstream_error_detail, ''), COALESCE(e.upstream_error_detail, ''),
COALESCE(upstream_errors::text, ''), COALESCE(e.upstream_errors::text, ''),
is_business_limited, e.is_business_limited,
user_id, e.user_id,
api_key_id, e.api_key_id,
account_id, e.account_id,
group_id, COALESCE(a.name, ''),
CASE WHEN client_ip IS NULL THEN NULL ELSE client_ip::text END, e.group_id,
COALESCE(request_path, ''), COALESCE(g.name, ''),
stream, CASE WHEN e.client_ip IS NULL THEN NULL ELSE e.client_ip::text END,
COALESCE(user_agent, ''), COALESCE(e.request_path, ''),
auth_latency_ms, e.stream,
routing_latency_ms, COALESCE(e.user_agent, ''),
upstream_latency_ms, e.auth_latency_ms,
response_latency_ms, e.routing_latency_ms,
time_to_first_token_ms, e.upstream_latency_ms,
COALESCE(request_body::text, ''), e.response_latency_ms,
request_body_truncated, e.time_to_first_token_ms,
request_body_bytes, COALESCE(e.request_body::text, ''),
COALESCE(request_headers::text, '') e.request_body_truncated,
FROM ops_error_logs e.request_body_bytes,
WHERE id = $1 COALESCE(e.request_headers::text, '')
FROM ops_error_logs e
LEFT JOIN accounts a ON e.account_id = a.id
LEFT JOIN groups g ON e.group_id = g.id
WHERE e.id = $1
LIMIT 1` LIMIT 1`
var out service.OpsErrorLogDetail var out service.OpsErrorLogDetail
@@ -393,7 +397,9 @@ LIMIT 1`
&userID, &userID,
&apiKeyID, &apiKeyID,
&accountID, &accountID,
&out.AccountName,
&groupID, &groupID,
&out.GroupName,
&clientIP, &clientIP,
&out.RequestPath, &out.RequestPath,
&out.Stream, &out.Stream,