46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package identity
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
userdomain "hyapp/services/user-service/internal/domain/user"
|
|
"hyapp/services/user-service/internal/storage/mysql/shared"
|
|
)
|
|
|
|
type displayUserIDLog struct {
|
|
// AppCode 是短号审计所属 App。
|
|
AppCode string
|
|
// UserID 是短号变更所属用户。
|
|
UserID int64
|
|
// OldID 是变更前短号。
|
|
OldID string
|
|
// NewID 是变更后短号。
|
|
NewID string
|
|
// OldKind 是变更前来源。
|
|
OldKind userdomain.DisplayUserIDKind
|
|
// NewKind 是变更后来源。
|
|
NewKind userdomain.DisplayUserIDKind
|
|
// ChangeType 区分 default_change、pretty_apply、pretty_expire。
|
|
ChangeType string
|
|
// LeaseID 是靓号相关变更的租约 ID。
|
|
LeaseID string
|
|
// Reason 是操作原因。
|
|
Reason string
|
|
// OperatorID 是操作者,系统任务可为空。
|
|
OperatorID int64
|
|
// RequestID 是入口请求或任务 ID。
|
|
RequestID string
|
|
// CreatedAtMs 是日志创建时间。
|
|
CreatedAtMs int64
|
|
}
|
|
|
|
func insertDisplayUserIDChangeLog(ctx context.Context, tx *sql.Tx, item displayUserIDLog) error {
|
|
// 所有短号变更都写审计日志,便于追踪默认号和靓号覆盖历史。
|
|
_, err := tx.ExecContext(ctx, `
|
|
INSERT INTO display_user_id_change_logs (app_code, user_id, old_display_user_id, new_display_user_id, old_display_user_id_kind, new_display_user_id_kind, change_type, lease_id, reason, operator_user_id, request_id, created_at_ms)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
`, item.AppCode, item.UserID, item.OldID, item.NewID, string(item.OldKind), string(item.NewKind), item.ChangeType, shared.NullableString(item.LeaseID), item.Reason, shared.NullableOperator(item.OperatorID), item.RequestID, item.CreatedAtMs)
|
|
return err
|
|
}
|