From 23a7160332cfb67c63c7d867066d4d0d46927aca Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 2 Jan 2025 10:17:35 +0800 Subject: [PATCH 1/2] fix statistics --- statistics/task/excelmgr.go | 10 +- worldsrv/actmonitormgr.go | 177 ------------------------------------ 2 files changed, 5 insertions(+), 182 deletions(-) delete mode 100644 worldsrv/actmonitormgr.go diff --git a/statistics/task/excelmgr.go b/statistics/task/excelmgr.go index bc83808..bd9d5d5 100644 --- a/statistics/task/excelmgr.go +++ b/statistics/task/excelmgr.go @@ -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) diff --git a/worldsrv/actmonitormgr.go b/worldsrv/actmonitormgr.go deleted file mode 100644 index 01a8120..0000000 --- a/worldsrv/actmonitormgr.go +++ /dev/null @@ -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 - //}) -} From 8174c8447d5bbbbb3587353f1d10b3b2c110e919 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 2 Jan 2025 10:22:58 +0800 Subject: [PATCH 2/2] fix statistics --- statistics/task/excelmgr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statistics/task/excelmgr.go b/statistics/task/excelmgr.go index bd9d5d5..7d579e7 100644 --- a/statistics/task/excelmgr.go +++ b/statistics/task/excelmgr.go @@ -110,7 +110,7 @@ func (e *ExcelMgr) Save(id int, startTime, endTime string) error { filename := fmt.Sprintf("%s_%s_%s.xlsx", d.DataName, startTime, endTime) - if VP.GetBool("IsDatabaseMode") { + if true { rows, err := d.GetRows("Sheet1") if err != nil { return err