fix statistics

This commit is contained in:
sk 2025-01-02 10:17:35 +08:00
parent f85a6014fc
commit 23a7160332
2 changed files with 5 additions and 182 deletions

View File

@ -2,7 +2,6 @@ package main
import (
"fmt"
"golang.org/x/exp/maps"
"strings"
"github.com/mozillazg/go-pinyin"
@ -134,14 +133,14 @@ func (e *ExcelMgr) Save(id int, startTime, endTime string) error {
}
}
createSQL := buildCreateTableSQLWithIndices(d.TableName, d.DataName, files, index)
createSQL := buildCreateTableSQLWithIndices(d.TableName, d.DataName, d.TableHead, files, index)
if err = db.Exec(createSQL).Error; err != nil {
logger.Logger.Errorf("createTable error: %v", err)
return err
}
if err = insertData(db.DB, d.TableName, maps.Keys(files), rows); err != nil {
if err = insertData(db.DB, d.TableName, d.TableHead, rows); err != nil {
logger.Logger.Errorf("insertData error: %v", err)
return err
}
@ -195,12 +194,13 @@ func (e *ExcelMgr) Pull(id int, startTime, endTime string) (*excelize.File, stri
}
// 构建创建表的 SQL 语句,支持中文描述和索引
func buildCreateTableSQLWithIndices(tableName string, comment string, fields map[string]string, indices map[string]string) string {
func buildCreateTableSQLWithIndices(tableName string, comment string, head []string, fields map[string]string, indices map[string]string) string {
var columns []string
var indexDefs []string
// 遍历字段定义
for field, comment := range fields {
for _, field := range head {
comment := fields[field]
column := fmt.Sprintf("`%s` VARCHAR(255) COMMENT '%s'", field, comment)
columns = append(columns, column)

View File

@ -1,177 +0,0 @@
package main
import (
"math"
"mongo.games.com/game/model"
"mongo.games.com/goserver/core/logger"
"sort"
)
const (
ActState_Login int32 = 1 << iota //登录.1
ActState_Exchange //兑换.2
ActState_Game //游戏.3
ActState_Max
)
var ActMonitorMgrSington = &ActMonitorMgr{
ActMonitorList: make(map[int64]*ActMonitorInfo),
}
type ActMonitorInfo struct {
SeqNo int64
SnId int32
Platform string //平台
MonitorType int32 //二进制 1.登录 2.兑换 3.游戏
CreateTime int64 //创建时间
Creator string //创建者
ReMark string //备注
GameName string //当前所在游戏名字
State int //玩家状态 0.全部 1.不在线 2.在线 3.游戏中
}
type ActMonitorMgr struct {
ActMonitorList map[int64]*ActMonitorInfo
NowActSeqNo int64
}
// monitorType 自己的类型 flag 当前触发的类型
func (u *ActMonitorMgr) IsMarkFlag(monitorType, flag int32) bool {
if (monitorType & flag) != 0 {
return true
}
return false
}
func (u *ActMonitorMgr) Init() {
actMonitorData := model.GetAllActMonitorData()
for _, info := range actMonitorData {
ami := &ActMonitorInfo{
SeqNo: info.SeqNo,
SnId: info.SnId,
Platform: info.Platform,
MonitorType: info.MonitorType,
CreateTime: info.CreateTime,
Creator: info.Creator,
ReMark: info.ReMark,
}
if u.NowActSeqNo < info.SeqNo {
u.NowActSeqNo = info.SeqNo
}
u.ActMonitorList[info.SeqNo] = ami
}
}
type ActMonitorList struct {
PageNo int
PageSize int
PageSum int
TotalSum int
Data []*ActMonitorInfo
}
func (u *ActMonitorMgr) QueryAMIList(pageNo, pageSize int, platform string, snid, startTs, endTs, state int) *ActMonitorList {
if len(u.ActMonitorList) == 0 {
return nil
}
var amiList = make([]*ActMonitorInfo, 0)
for _, v := range u.ActMonitorList {
if len(platform) != 0 && v.Platform != platform {
continue
}
if snid != 0 && v.SnId != int32(snid) {
continue
}
if startTs != 0 && endTs != 0 && (v.CreateTime < int64(startTs) || v.CreateTime > int64(endTs)) {
continue
}
if state != 0 && v.State != state {
continue
}
amiList = append(amiList, v)
}
sort.Slice(amiList, func(i, j int) bool {
if amiList[i].SeqNo > amiList[j].SeqNo {
return true
}
return false
})
totalNum := len(amiList) //总条目
pageSum := int(math.Ceil(float64(totalNum) / float64(pageSize))) //总页数
if pageNo <= 0 || pageNo > pageSum {
pageNo = 1 //当前页
}
start := (pageNo - 1) * pageSize
end := start + pageSize
if totalNum > start {
if totalNum < end {
end = totalNum
}
amiList = amiList[start:end]
}
for k, v := range amiList {
actPlayer := amiList[k]
actPlayer.GameName = ""
p := PlayerMgrSington.GetPlayerBySnId(v.SnId)
if p != nil {
if p.IsOnLine() {
actPlayer.State = 2
} else {
actPlayer.State = 1
}
if p.scene != nil {
actPlayer.State = 3
actPlayer.GameName = p.scene.dbGameFree.GetName() + p.scene.dbGameFree.GetTitle()
}
} else {
actPlayer.State = 1
}
}
return &ActMonitorList{pageNo, pageSize, pageSum, totalNum, amiList}
}
func (u *ActMonitorMgr) Edit(amt *ActMonitorInfo) {
u.ActMonitorList[amt.SeqNo] = amt
}
func (u *ActMonitorMgr) Del(seqNo int64) {
delete(u.ActMonitorList, seqNo)
}
func (u *ActMonitorMgr) AddSeqNo() int64 {
u.NowActSeqNo++
return u.NowActSeqNo
}
func (u *ActMonitorMgr) GetSeqNo(snid int32, platform string) int64 {
for _, v := range u.ActMonitorList {
if v.SnId == snid && v.Platform == platform {
return v.SeqNo
}
}
return -1
}
func (u *ActMonitorMgr) SendActMonitorEvent(eventType, snid int32, name, platform string, billNo, exchangeCoin int64,
gameSceneName string, state int32) {
logger.Logger.Tracef("SendActMonitorEvent eventType:%v snid:%v name:%v platform:%v billNo:%v exchangeCoin:%v "+
"gameSceneName:%v state:%v", eventType, snid, name, platform, billNo, exchangeCoin, gameSceneName, state)
//seqNo := u.GetSeqNo(snid, platform)
//if data, ok := u.ActMonitorList[seqNo]; ok {
// if u.IsMarkFlag(eventType, data.MonitorType) {
// var flag int32
// if eventType == ActState_Login {
// flag = 1
// } else if eventType == ActState_Exchange {
// flag = 2
// } else if eventType == ActState_Game {
// flag = 3
// }
// logger.Logger.Tracef("GenerateActMonitorEvent "+
// "flag:%v eventType:%v snid:%v name:%v platform:%v billNo:%v exchangeCoin:%v "+
// "gameSceneName:%v state:%v reMark:%v",
// flag, eventType, snid, name, platform, billNo, exchangeCoin, gameSceneName, state, data.ReMark)
// LogChannelSingleton.WriteMQData(model.GenerateActMonitorEvent(flag, snid, name, platform,
// time.Now().Unix(), billNo, exchangeCoin, gameSceneName, state, data.ReMark))
// }
//}
}
func init() {
//RegisterParallelLoadFunc("用户行为监控列表", func() error {
// ActMonitorMgrSington.Init()
// return nil
//})
}