Files
yunzerwebsiteallinone/go/services/operation_log_user.go
T
2026-11-16 17:22:50 +08:00

64 lines
1.4 KiB
Go

package services
import "server/models"
func OperationLogUser(tid *uint64, userID uint64) (account, name string) {
if userID == 0 {
return "", ""
}
if tid != nil && *tid != 0 {
var user models.SystemTenantUser
if err := models.Orm.QueryTable(new(models.SystemTenantUser)).
Filter("tid", *tid).
Filter("uid", ResolveTenantUID(*tid, userID)).
One(&user); err == nil {
if user.Account != nil {
account = *user.Account
}
if user.Name != nil {
name = *user.Name
}
}
return account, name
}
var user models.AdminUser
if err := models.Orm.QueryTable(new(models.AdminUser)).
Filter("id", userID).
One(&user); err == nil {
account = user.Account
if user.Name != nil {
name = *user.Name
}
}
return account, name
}
type operationLogUserKey struct {
tid uint64
uid uint64
}
type OperationLogUserResolver struct {
cache map[operationLogUserKey][2]string
}
func NewOperationLogUserResolver() *OperationLogUserResolver {
return &OperationLogUserResolver{cache: make(map[operationLogUserKey][2]string)}
}
func (r *OperationLogUserResolver) Resolve(tid *uint64, userID uint64) (account, name string) {
var tidVal uint64
if tid != nil {
tidVal = *tid
}
key := operationLogUserKey{tid: tidVal, uid: userID}
if v, ok := r.cache[key]; ok {
return v[0], v[1]
}
account, name = OperationLogUser(tid, userID)
r.cache[key] = [2]string{account, name}
return account, name
}