| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- package log
- import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/go-redis/redis/v8"
- "go.uber.org/zap"
- "gorm.io/gorm"
- "log-server/global"
- "log-server/model/log"
- "log-server/model/log/request"
- "log-server/model/log/response"
- loging2 "log-server/service/log/loging"
- "math"
- "strconv"
- "time"
- )
- type ServiceStatisticsLog struct {
- loging2.LogicalLog
- }
- var StatisticsCompletedKey = "%s:StatisticsCompleted"
- var TaskType = []int{0, 1}
- func (s *ServiceStatisticsLog) CreateStatisticsLog() {
- key := fmt.Sprintf(StatisticsCompletedKey, s.LogicalLog.CurrentDate())
- ctx := context.Background()
- b, err := s.LogicalLog.ExistsKey(ctx, key)
- if err != nil {
- global.GVA_LOG.Error("获取redis key失败!"+key, zap.Error(err))
- return
- }
- if b {
- global.GVA_LOG.Info("统计数据已完成!"+key, zap.Error(err))
- return
- }
- gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.YesterdayDate())
- if err != nil {
- global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
- return
- }
- if len(gameMps) == 0 {
- global.GVA_LOG.Info("获取redis game list没有数据!")
- return
- }
- var statisticsLogs []*log.StatisticsLog
- for gameId, _ := range gameMps {
- for _, tt := range TaskType {
- statisticsLog := new(log.StatisticsLog)
- gameIdInt, _ := strconv.Atoi(gameId)
- pullAccountOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4100000", loging2.OkStatus, tt)
- pullAccountFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4100000", loging2.FailStatus, tt)
- ConstituencyFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.FailStatus, tt)
- ConstituencyOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.OkStatus, tt)
- StartProxyFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4200000", loging2.FailStatus, tt)
- StartProxyOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4200000", loging2.OkStatus, tt)
- SimulatorStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
- SimulatorStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
- NetworkCheckFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4400000", loging2.FailStatus, tt)
- NetworkCheckOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4400000", loging2.OkStatus, tt)
- GameStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4500000", loging2.FailStatus, tt)
- GameStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4500000", loging2.OkStatus, tt)
- xmyLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.FailStatus, tt)
- xmyLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.OkStatus, tt)
- wxLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.FailStatus, tt)
- wxLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.OkStatus, tt)
- mzLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.FailStatus, tt)
- mzLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.OkStatus, tt)
- LoginFail := xmyLoginFail + wxLoginFail + mzLoginFail
- LoginOk := xmyLoginOk + wxLoginOk + mzLoginOk
- EnterMainFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4700000", loging2.FailStatus, tt)
- EnterMainOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4700000", loging2.OkStatus, tt)
- FeeFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.FailStatus, tt)
- FeeOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.OkStatus, tt)
- ScriptStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
- ScriptStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
- EnterGameFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.FailStatus, tt)
- EnterGameOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.OkStatus, tt)
- AuthenticationFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.FailStatus, tt)
- AuthenticationOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.OkStatus, tt)
- HasRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4609902", loging2.NoLogStatus, tt)
- NotRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4609901", loging2.NoLogStatus, tt)
- EnterStartGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4501000", loging2.NoLogStatus, tt)
- EnterAuthentication, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.NoLogStatus, tt)
- EnterConstituency, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.NoLogStatus, tt)
- EnterGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.NoLogStatus, tt)
- EnterMain, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4701000", loging2.NoLogStatus, tt)
- EnterFee, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.NoLogStatus, tt)
- EnterXmyLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.NoLogStatus, tt)
- EnterWxLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.NoLogStatus, tt)
- EnterMzLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.NoLogStatus, tt)
- BanOff1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601006", loging2.FailStatus, tt) // 小绵羊登录封号
- BanOff2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602008", loging2.FailStatus, tt) // 微信登录封号
- BanOff3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603006", loging2.FailStatus, tt) // 魅族登录封号
- BanOff4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701003", loging2.FailStatus, tt) // 主线封号
- Freeze, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4809904", loging2.NoLogStatus, tt) // 冻结
- BanOff := BanOff1 + BanOff2 + BanOff3 + BanOff4
- EnterLogin := EnterXmyLogin + EnterMzLogin + EnterWxLogin
- statisticsLog.PullAccountOk = pullAccountOk
- statisticsLog.PullAccountFail = pullAccountFail
- statisticsLog.StartProxyFail = StartProxyFail
- statisticsLog.StartProxyOk = StartProxyOk
- statisticsLog.SimulatorStartFail = SimulatorStartFail
- statisticsLog.SimulatorStartOk = SimulatorStartOk
- statisticsLog.NetworkCheckFail = NetworkCheckFail
- statisticsLog.NetworkCheckOk = NetworkCheckOk
- statisticsLog.EnterMainFail = EnterMainFail
- statisticsLog.EnterMainOk = EnterMainOk
- statisticsLog.EnterGameFail = EnterGameFail
- statisticsLog.EnterGameOk = EnterGameOk
- statisticsLog.GameId = gameIdInt
- statisticsLog.ConstituencyFail = ConstituencyFail
- statisticsLog.ConstituencyOk = ConstituencyOk
- statisticsLog.FeeFail = FeeFail
- statisticsLog.FeeOk = FeeOk
- statisticsLog.GameStartFail = GameStartFail
- statisticsLog.GameStartOk = GameStartOk
- statisticsLog.LoginFail = LoginFail
- statisticsLog.LoginOk = LoginOk
- statisticsLog.XmyLoginFail = xmyLoginFail
- statisticsLog.XmyLoginOk = xmyLoginOk
- statisticsLog.WxLoginFail = wxLoginFail
- statisticsLog.WxLoginOk = wxLoginOk
- statisticsLog.MzLoginFail = mzLoginFail
- statisticsLog.MzLoginOk = mzLoginOk
- statisticsLog.ScriptStartFail = ScriptStartFail
- statisticsLog.ScriptStartOk = ScriptStartOk
- statisticsLog.AuthenticationFail = AuthenticationFail
- statisticsLog.AuthenticationOk = AuthenticationOk
- statisticsLog.HasRole = HasRole
- statisticsLog.NotRole = NotRole
- statisticsLog.EnterStartGame = EnterStartGame
- statisticsLog.EnterAuthentication = EnterAuthentication
- statisticsLog.EnterConstituency = EnterConstituency
- statisticsLog.EnterGame = EnterGame
- statisticsLog.EnterMain = EnterMain
- statisticsLog.EnterFee = EnterFee
- statisticsLog.EnterLogin = EnterLogin
- statisticsLog.BanOff = BanOff
- statisticsLog.Freeze = Freeze
- statisticsLog.Type = tt
- statisticsLog.CreateTime = time.Now().Format("2006-01-02 15:04:05")
- statisticsLog.CreateDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02")
- statisticsLogs = append(statisticsLogs, statisticsLog)
- if len(statisticsLogs) == 100 {
- err = global.GVA_DB.Create(statisticsLogs).Error
- if err != nil {
- global.GVA_LOG.Error("添加statisticsLogs失败!", zap.Error(err))
- return
- }
- statisticsLogs = []*log.StatisticsLog{}
- }
- }
- }
- if len(statisticsLogs) == 0 {
- global.GVA_REDIS.Set(ctx, key, 1, 24*time.Hour)
- return
- }
- err = global.GVA_DB.Create(statisticsLogs).Error
- if err != nil {
- global.GVA_LOG.Error("添加statisticsLogs失败!", zap.Error(err))
- return
- }
- global.GVA_REDIS.Set(ctx, key, 1, 24*time.Hour)
- return
- }
- func (s *ServiceStatisticsLog) TodayStatisticsLogList1() (interface{}, error) {
- gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.CurrentDate())
- if err != nil {
- global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
- return nil, err
- }
- /*var statisticsLogs []*log.StatisticsLog
- for _,info := range apiList{
- statisticsLog := new(log.StatisticsLog)
- statisticsLog.PullAccountOk = info.PullAccountOk
- statisticsLog.PullAccountFail = info.PullAccountFail
- statisticsLog.StartProxyFail = info.StartProxyFail
- statisticsLog.StartProxyOk = info.StartProxyOk
- statisticsLog.SimulatorStartFail = info.SimulatorStartFail
- statisticsLog.SimulatorStartOk = info.SimulatorStartOk
- statisticsLog.NetworkCheckFail = info.NetworkCheckFail
- statisticsLog.NetworkCheckOk = info.NetworkCheckOk
- statisticsLog.EnterMainFail = info.EnterMainFail
- statisticsLog.EnterMainOk = info.EnterMainOk
- statisticsLog.EnterGameFail = info.EnterGameFail
- statisticsLog.EnterGameOk = info.EnterGameOk
- statisticsLog.GameId = info.GameId
- statisticsLog.ConstituencyFail = info.ConstituencyFail
- statisticsLog.ConstituencyOk = info.ConstituencyOk
- statisticsLog.FeeFail = info.FeeFail
- statisticsLog.FeeOk = info.FeeOk
- statisticsLog.GameStartFail = info.GameStartFail
- statisticsLog.GameStartOk = info.GameStartOk
- statisticsLog.LoginFail = info.LoginFail
- statisticsLog.LoginOk = info.LoginOk
- statisticsLog.XmyLoginFail = info.XmyLoginFail
- statisticsLog.XmyLoginOk = info.XmyLoginOk
- statisticsLog.WxLoginFail = info.WxLoginFail
- statisticsLog.WxLoginOk = info.WxLoginOk
- statisticsLog.MzLoginFail = info.MzLoginFail
- statisticsLog.MzLoginOk = info.MzLoginOk
- statisticsLog.ScriptStartFail = info.ScriptStartFail
- statisticsLog.ScriptStartOk = info.ScriptStartOk
- statisticsLog.AuthenticationFail = info.AuthenticationFail
- statisticsLog.AuthenticationOk = info.AuthenticationOk
- statisticsLog.HasRole = info.HasRole
- statisticsLog.NotRole = info.NotRole
- statisticsLog.EnterStartGame = info.EnterStartGame
- statisticsLog.EnterAuthentication = info.EnterAuthentication
- statisticsLog.EnterConstituency = info.EnterConstituency
- statisticsLog.EnterGame = info.EnterGame
- statisticsLog.EnterMain = info.EnterMain
- statisticsLog.EnterFee = info.EnterFee
- statisticsLog.EnterLogin = info.EnterLogin
- statisticsLog.BanOff = info.BanOff
- statisticsLog.Freeze = info.Freeze
- statisticsLog.Type = info.Type
- statisticsLog.CreateTime = info.CreateTime
- statisticsLog.CreateDate = info.CreateDate
- statisticsLogs = append(statisticsLogs,statisticsLog)
- }*/
- ctx := context.Background()
- var gmps = map[string][]map[int]interface{}{}
- for gameId, _ := range gameMps {
- var TTmps = map[int]interface{}{}
- gameIdInt, _ := strconv.Atoi(gameId)
- for _, tt := range TaskType {
- cacheKeys, err := s.LogicalLog.GetGameStatisticsCacheKeys(ctx, s.CurrentDate(), gameIdInt, tt)
- if err != nil {
- if err == redis.Nil {
- continue
- }
- return nil, err
- }
- var dmps = map[string]string{}
- for _, cacheKey := range cacheKeys {
- num, _ := global.GVA_REDIS.Get(ctx, cacheKey).Result()
- code := s.LogicalLog.ByCacheKeyGetEndNode(cacheKey)
- dmps[code] = num
- }
- if len(dmps) != 0 {
- TTmps[tt] = dmps
- }
- }
- gmps[gameId] = append(gmps[gameId], TTmps)
- }
- return gmps, err
- }
- func (s *ServiceStatisticsLog) TodayStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo) (interface{}, int64, error) {
- gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.CurrentDate())
- if err != nil {
- global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
- return nil, 0, err
- }
- if len(gameMps) == 0 {
- global.GVA_LOG.Info("获取redis game list没有数据!")
- return nil, 0, err
- }
- if api.GameId != 0 {
- _, b := gameMps[strconv.Itoa(api.GameId)]
- if !b {
- return nil, 0, nil
- }
- gameMps = map[string]string{strconv.Itoa(api.GameId): "1"}
- }
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
- total := len(gameMps)
- var statisticsLogs []*log.StatisticsLog
- for i := 0; i < limit+offset; i++ {
- }
- i := 0
- lf := limit + offset
- for gameId, _ := range gameMps {
- if i < offset {
- i++
- continue
- }
- if i >= lf {
- break
- }
- for _, tt := range TaskType {
- statisticsLog := new(log.StatisticsLog)
- gameIdInt, _ := strconv.Atoi(gameId)
- pullAccountOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4100000", loging2.OkStatus, tt)
- pullAccountFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4100000", loging2.FailStatus, tt)
- ConstituencyFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.FailStatus, tt)
- ConstituencyOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.OkStatus, tt)
- StartProxyFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4200000", loging2.FailStatus, tt)
- StartProxyOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4200000", loging2.OkStatus, tt)
- SimulatorStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
- SimulatorStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
- NetworkCheckFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4400000", loging2.FailStatus, tt)
- NetworkCheckOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4400000", loging2.OkStatus, tt)
- GameStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4500000", loging2.FailStatus, tt)
- GameStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4500000", loging2.OkStatus, tt)
- xmyLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.FailStatus, tt)
- xmyLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.OkStatus, tt)
- wxLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.FailStatus, tt)
- wxLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.OkStatus, tt)
- mzLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.FailStatus, tt)
- mzLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.OkStatus, tt)
- LoginFail := xmyLoginFail + wxLoginFail + mzLoginFail
- LoginOk := xmyLoginOk + wxLoginOk + mzLoginOk
- EnterMainFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4700000", loging2.FailStatus, tt)
- EnterMainOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4700000", loging2.OkStatus, tt)
- FeeFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4800000", loging2.FailStatus, tt)
- FeeOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4800000", loging2.OkStatus, tt)
- ScriptStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
- ScriptStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
- EnterGameFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.FailStatus, tt)
- EnterGameOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.OkStatus, tt)
- AuthenticationFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.FailStatus, tt)
- AuthenticationOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.OkStatus, tt)
- HasRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4609902", loging2.NoLogStatus, tt)
- NotRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4609901", loging2.NoLogStatus, tt)
- EnterStartGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4501000", loging2.NoLogStatus, tt)
- EnterAuthentication, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.NoLogStatus, tt)
- EnterConstituency, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.NoLogStatus, tt)
- EnterGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.NoLogStatus, tt)
- EnterMain, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701000", loging2.NoLogStatus, tt)
- EnterFee1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4801000", loging2.NoLogStatus, tt) //小绵羊进入付费
- EnterFee2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4802000", loging2.NoLogStatus, tt) //微信进入付费
- EnterFee3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4803000", loging2.NoLogStatus, tt) //魅族进入付费
- EnterFee4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4804000", loging2.NoLogStatus, tt) //QQ卡进入付费
- EnterFee := EnterFee1 + EnterFee2 + EnterFee3 + EnterFee4
- EnterXmyLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.NoLogStatus, tt)
- EnterWxLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.NoLogStatus, tt)
- EnterMzLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.NoLogStatus, tt)
- BanOff1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601006", loging2.FailStatus, tt) // 小绵羊登录封号
- BanOff2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602008", loging2.FailStatus, tt) // 微信登录封号
- BanOff3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603006", loging2.FailStatus, tt) // 魅族登录封号
- BanOff4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701003", loging2.FailStatus, tt) // 主线封号
- Freeze, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4809904", loging2.NoLogStatus, tt) // 冻结
- BanOff := BanOff1 + BanOff2 + BanOff3 + BanOff4
- EnterLogin := EnterXmyLogin + EnterMzLogin + EnterWxLogin
- statisticsLog.PullAccountOk = pullAccountOk
- statisticsLog.PullAccountFail = pullAccountFail
- statisticsLog.StartProxyFail = StartProxyFail
- statisticsLog.StartProxyOk = StartProxyOk
- statisticsLog.SimulatorStartFail = SimulatorStartFail
- statisticsLog.SimulatorStartOk = SimulatorStartOk
- statisticsLog.NetworkCheckFail = NetworkCheckFail
- statisticsLog.NetworkCheckOk = NetworkCheckOk
- statisticsLog.EnterMainFail = EnterMainFail
- statisticsLog.EnterMainOk = EnterMainOk
- statisticsLog.EnterGameFail = EnterGameFail
- statisticsLog.EnterGameOk = EnterGameOk
- statisticsLog.GameId = gameIdInt
- statisticsLog.ConstituencyFail = ConstituencyFail
- statisticsLog.ConstituencyOk = ConstituencyOk
- statisticsLog.FeeFail = FeeFail
- statisticsLog.FeeOk = FeeOk
- statisticsLog.GameStartFail = GameStartFail
- statisticsLog.GameStartOk = GameStartOk
- statisticsLog.LoginFail = LoginFail
- statisticsLog.LoginOk = LoginOk
- statisticsLog.XmyLoginFail = xmyLoginFail
- statisticsLog.XmyLoginOk = xmyLoginOk
- statisticsLog.WxLoginFail = wxLoginFail
- statisticsLog.WxLoginOk = wxLoginOk
- statisticsLog.MzLoginFail = mzLoginFail
- statisticsLog.MzLoginOk = mzLoginOk
- statisticsLog.ScriptStartFail = ScriptStartFail
- statisticsLog.ScriptStartOk = ScriptStartOk
- statisticsLog.AuthenticationFail = AuthenticationFail
- statisticsLog.AuthenticationOk = AuthenticationOk
- statisticsLog.HasRole = HasRole
- statisticsLog.NotRole = NotRole
- statisticsLog.EnterStartGame = EnterStartGame
- statisticsLog.EnterAuthentication = EnterAuthentication
- statisticsLog.EnterConstituency = EnterConstituency
- statisticsLog.EnterGame = EnterGame
- statisticsLog.EnterMain = EnterMain
- statisticsLog.EnterFee = EnterFee
- statisticsLog.EnterLogin = EnterLogin
- statisticsLog.BanOff = BanOff
- statisticsLog.Freeze = Freeze
- statisticsLog.Type = tt
- statisticsLog.CreateTime = time.Now().Format("2006-01-02 15:04:05")
- statisticsLog.CreateDate = time.Now().Format("2006-01-02")
- statisticsLogs = append(statisticsLogs, statisticsLog)
- }
- }
- return statisticsLogs, int64(total), err
- }
- func (s *ServiceStatisticsLog) OtherStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
- date := api.CreateDate
- if date == "" || date == s.CurrentDate() {
- apilist, total, err := s.TodayStatisticsLogList(ctx, api, info)
- return apilist, total, err
- }
- db := global.GVA_DB.Model(&log.StatisticsLog{})
- if api.GameId != 0 {
- db = db.Where("game_id = ?", api.GameId)
- }
- var total int64
- err := db.Count(&total).Error
- if err != nil {
- return nil, 0, err
- }
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
- var statisticsLogs []*log.StatisticsLog
- db = db.Where("create_date = ?", date)
- db = db.Limit(limit).Offset(offset)
- err = db.Order("id").Find(&statisticsLogs).Error
- if err != nil {
- return nil, 0, err
- }
- for _, statisticsLog := range statisticsLogs {
- statisticsLog.CreateDate = statisticsLog.CreateDate[:10]
- }
- return statisticsLogs, total, err
- }
- func (s *ServiceStatisticsLog) ResetStatisticsLog(ctx context.Context, gameId int, date string) {
- var total int64
- key := date + ":" + strconv.Itoa(gameId) + ":reset"
- global.GVA_REDIS.Set(ctx, key, 1, time.Minute*15)
- db := global.GVA_DB.Table("loging")
- db = db.Where("game_id = ?", gameId)
- err := db.Count(&total).Error
- if err != nil {
- global.GVA_LOG.Error("重置统计数据总数报错", zap.Error(err))
- return
- }
- limit := 100
- num := int(math.Ceil(float64(total) / float64(limit)))
- offset := 0
- err = s.LogicalLog.DelStatisticsNumCache(ctx, date, gameId)
- if err != nil {
- global.GVA_LOG.Error("重置统计数据删除缓存报错", zap.Error(err))
- return
- }
- err = s.LogicalLog.DelUuidCodeCache(ctx, date, gameId)
- if err != nil {
- global.GVA_LOG.Error("重置统计数据删除缓存报错2", zap.Error(err))
- return
- }
- global.GVA_LOG.Info("num = " + strconv.Itoa(num))
- for i := 0; i < num; i++ {
- global.GVA_LOG.Info("offset = " + strconv.Itoa(offset))
- var statisticsLogs []request.AddLogRequest
- db2 := global.GVA_DB.Table("loging")
- db2 = db2.Where("create_date = ?", date)
- db2 = db2.Where("game_id = ?", gameId)
- db2 = db2.Limit(limit).Offset(offset)
- err = db2.Order("id").Find(&statisticsLogs).Error
- for _, statisticsLog := range statisticsLogs {
- s.ResetStatisticsCache(ctx, statisticsLog, date)
- }
- offset += limit
- }
- global.GVA_LOG.Info("重置统计数据完成")
- }
- func (s *ServiceStatisticsLog) ResetStatisticsCache(c context.Context, api request.AddLogRequest, date string) {
- coding := strconv.Itoa(api.Coding)
- nodeCoding := coding[:3]
- status := coding[5:]
- noLogStatus := coding[3:5]
- var logical ServiceResetLoging
- switch nodeCoding {
- case "410":
- logical = new(loging2.ResetLog)
- break
- case "430":
- logical = new(loging2.ResetLog)
- break
- default:
- logical = new(loging2.ResetOtherLog)
- break
- }
- var err error
- if status == "99" {
- err = logical.SuccessLog(c, api, date)
- } else if noLogStatus == "99" {
- err = logical.NoLogStatusData(c, api, date)
- } else {
- err = logical.FailLog(c, api, date)
- }
- if err != nil {
- global.GVA_LOG.Error("创建失败!", zap.Error(err))
- }
- }
- // 每天凌晨reset统计数据
- func (s *ServiceStatisticsLog) EveryDayResetStatisticsCache() {
- date := s.YesterdayDate()
- ctx := context.Background()
- gameMps, err := s.LogicalLog.GetGameCache(ctx, date)
- if err != nil {
- global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
- return
- }
- if len(gameMps) == 0 {
- global.GVA_LOG.Info("获取redis game list没有数据!")
- return
- }
- for gameId, _ := range gameMps {
- id, _ := strconv.Atoi(gameId)
- s.ResetStatisticsLog(ctx, id, date)
- }
- global.GVA_LOG.Info("游戏重置缓存完成!")
- }
- func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
- ctx := context.Background()
- codeMps, err := s.LogicalLog.GetComputerCache(ctx, s.LogicalLog.CurrentDate())
- if err != nil {
- return
- }
- if len(codeMps) == 0 {
- return
- }
- var csReplys []*log.LogComputer
- for code, r := range codeMps {
- csReply := new(log.LogComputer)
- csReply.PcCode = code
- csReply.Operator = r
- var gameInfos []*response.GameInfo
- accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
- if err != nil {
- continue
- }
- taskMps, err := s.LogicalLog.GetComputerTaskSuccessNumCache(ctx, s.LogicalLog.CurrentDate(), code)
- if err != nil {
- continue
- }
- for gameId, num := range accountMps {
- gameInfo := new(response.GameInfo)
- gameInfo.GameId = gameId
- gameInfo.PullAccountNum = num
- gameInfo.TaskSuccessNum = taskMps[gameId]
- gameInfos = append(gameInfos, gameInfo)
- }
- gameInfoByte, _ := json.Marshal(gameInfos)
- csReply.GameInfo = string(gameInfoByte)
- csReply.CreateDate = time.Now().Format("2006-01-02")
- if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
- // 已存在,更新
- mp := make(map[string]interface{})
- mp["game_info"] = string(gameInfoByte)
- if csReply.Operator != "" {
- mp["operator"] = csReply.Operator
- }
- err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Updates(mp).Error
- if err != nil {
- global.GVA_LOG.Error("更新数据失败", zap.Error(err))
- }
- continue
- }
- csReplys = append(csReplys, csReply)
- }
- if len(csReplys) != 0 {
- err = global.GVA_DB.Table("log_computer").Create(csReplys).Error
- if err != nil {
- global.GVA_LOG.Error("更新数据失败", zap.Error(err))
- }
- }
- return
- }
- func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.StatisticsLog, info request.PageInfo) (interface{}, int64, error) {
- date := api.CreateDate
- if date == "" {
- date = s.CurrentDate()
- }
- db := global.GVA_DB.Model(&log.LogComputer{})
- var total int64
- err := db.Count(&total).Error
- if err != nil {
- return nil, 0, err
- }
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
- var statisticsLogs []*log.LogComputer
- db = db.Where("create_date = ?", date)
- db = db.Limit(limit).Offset(offset)
- err = db.Order("id").Find(&statisticsLogs).Error
- if err != nil {
- return nil, 0, err
- }
- var statisticsLogsComputer []*response.ComputerStatisticsReply1
- for _, statisticsLog := range statisticsLogs {
- var gameInfo []*response.GameInfo
- err = json.Unmarshal([]byte(statisticsLog.GameInfo), &gameInfo)
- statisticsLogComputer := new(response.ComputerStatisticsReply1)
- statisticsLogComputer.GameInfo = gameInfo
- statisticsLogComputer.PcCode = statisticsLog.PcCode
- statisticsLogComputer.Operator = statisticsLog.Operator
- statisticsLogComputer.CreateDate = statisticsLog.CreateDate[:10]
- statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
- }
- return statisticsLogsComputer, total, err
- }
|