2025-07-17 17:09:09 +08:00

111 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package smdl
import (
"admin/apps/game/domain/entity"
dto2 "admin/internal/model/dto"
"admin/lib/xlog"
"encoding/base64"
"strconv"
)
type GameLogHook struct {
}
var removeFields = map[string]struct{}{
"pub_mediaid": {},
"pub_role_name": {},
"pub_udid": {},
}
var alias = map[string]string{
"pub_viplev": "vip等级",
"pub_userid": "账号",
"pub_totalcash": "总充值金额",
"pub_serverid": "服务器id",
"pub_rolename": "角色名",
"pub_roleid": "角色id",
"pub_lev": "等级",
"pub_language": "语言",
"pub_ip": "IP",
}
var base64decodeFields = map[string]struct{}{
"pub_rolename": {},
"chatlog_msg": {},
}
func init() {
for i := 0; i < 15; i++ {
removeFields["chatlog_score"] = struct{}{}
removeFields["chatlog_score"+strconv.Itoa(i)] = struct{}{}
removeFields["chatlog_label"] = struct{}{}
removeFields["chatlog_label"+strconv.Itoa(i)] = struct{}{}
removeFields["chatlog_checklevel"] = struct{}{}
removeFields["chatlog_checklevel"+strconv.Itoa(i)] = struct{}{}
}
removeFields["chatlog_code"] = struct{}{}
removeFields["chatlog_checkresult"] = struct{}{}
}
func (hook *GameLogHook) Trim(projectInfo *entity.Project, eventName []string, totalCount int, fieldsDescInfo []*dto2.GameLogFieldInfo, rows [][]any) (
int, []*dto2.GameLogFieldInfo, [][]any) {
// 删除不需要的字段
i := 0
for {
if i >= len(fieldsDescInfo) {
break
}
field := fieldsDescInfo[i]
if _, find := removeFields[field.Name]; find {
// 找到这个字段在去掉的列表里
fieldsDescInfo = append(fieldsDescInfo[:i], fieldsDescInfo[i+1:]...)
// 对应所有数据行里也删除这个值
for _, row := range rows {
row = append(row[:i], row[i+1:]...)
}
} else {
// 查找要不要把value做base64解码
if _, find := base64decodeFields[field.Name]; find {
for _, row := range rows {
newValue, err := base64.StdEncoding.DecodeString((*(row[i].(*interface{}))).(string))
if err != nil {
xlog.Warnf("base64 decode field:%v value:%v error:%v", field.Name, row[i], err)
} else {
row[i] = string(newValue)
}
}
}
i++
}
}
// 查找别名
for _, en := range eventName {
// 查找全局eventName描述表信息对里面没有别的字段名改为表里的名字
descInfo, find := globEventList[en]
if find {
for _, f := range fieldsDescInfo {
find := false
for _, f1 := range descInfo.fields {
if f.Name == f1.Name && f1.Alias != "" {
if f.Name == f.Alias {
f.Alias = f1.Alias
}
find = true
break
}
}
if !find {
aliasName, find1 := alias[f.Name]
if find1 && f.Name == f.Alias && f.Alias != "" {
f.Alias = aliasName
}
}
}
}
}
return totalCount, fieldsDescInfo, rows
}