log_statistics.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package log
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/go-redis/redis/v8"
  8. "go.uber.org/zap"
  9. "gorm.io/gorm"
  10. "log-server/global"
  11. "log-server/model/log"
  12. "log-server/model/log/request"
  13. "log-server/model/log/response"
  14. loging2 "log-server/service/log/loging"
  15. "math"
  16. "strconv"
  17. "time"
  18. )
  19. type ServiceStatisticsLog struct {
  20. loging2.LogicalLog
  21. }
  22. var StatisticsCompletedKey = "%s:StatisticsCompleted"
  23. var TaskType = []int{0, 1}
  24. func (s *ServiceStatisticsLog) CreateStatisticsLog() {
  25. key := fmt.Sprintf(StatisticsCompletedKey, s.LogicalLog.CurrentDate())
  26. ctx := context.Background()
  27. b, err := s.LogicalLog.ExistsKey(ctx, key)
  28. if err != nil {
  29. global.GVA_LOG.Error("获取redis key失败!"+key, zap.Error(err))
  30. return
  31. }
  32. if b {
  33. global.GVA_LOG.Info("统计数据已完成!"+key, zap.Error(err))
  34. return
  35. }
  36. gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.YesterdayDate())
  37. if err != nil {
  38. global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
  39. return
  40. }
  41. if len(gameMps) == 0 {
  42. global.GVA_LOG.Info("获取redis game list没有数据!")
  43. return
  44. }
  45. var statisticsLogs []*log.StatisticsLog
  46. for gameId, _ := range gameMps {
  47. for _, tt := range TaskType {
  48. statisticsLog := new(log.StatisticsLog)
  49. gameIdInt, _ := strconv.Atoi(gameId)
  50. pullAccountOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4100000", loging2.OkStatus, tt)
  51. pullAccountFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4100000", loging2.FailStatus, tt)
  52. ConstituencyFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.FailStatus, tt)
  53. ConstituencyOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.OkStatus, tt)
  54. StartProxyFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4200000", loging2.FailStatus, tt)
  55. StartProxyOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4200000", loging2.OkStatus, tt)
  56. SimulatorStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
  57. SimulatorStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
  58. NetworkCheckFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4400000", loging2.FailStatus, tt)
  59. NetworkCheckOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4400000", loging2.OkStatus, tt)
  60. GameStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4500000", loging2.FailStatus, tt)
  61. GameStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4500000", loging2.OkStatus, tt)
  62. xmyLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.FailStatus, tt)
  63. xmyLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.OkStatus, tt)
  64. wxLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.FailStatus, tt)
  65. wxLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.OkStatus, tt)
  66. mzLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.FailStatus, tt)
  67. mzLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.OkStatus, tt)
  68. LoginFail := xmyLoginFail + wxLoginFail + mzLoginFail
  69. LoginOk := xmyLoginOk + wxLoginOk + mzLoginOk
  70. EnterMainFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4700000", loging2.FailStatus, tt)
  71. EnterMainOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4700000", loging2.OkStatus, tt)
  72. FeeFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.FailStatus, tt)
  73. FeeOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.OkStatus, tt)
  74. ScriptStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
  75. ScriptStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
  76. EnterGameFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.FailStatus, tt)
  77. EnterGameOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.OkStatus, tt)
  78. AuthenticationFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.FailStatus, tt)
  79. AuthenticationOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.OkStatus, tt)
  80. HasRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4609902", loging2.NoLogStatus, tt)
  81. NotRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4609901", loging2.NoLogStatus, tt)
  82. EnterStartGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4501000", loging2.NoLogStatus, tt)
  83. EnterAuthentication, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4607000", loging2.NoLogStatus, tt)
  84. EnterConstituency, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4604000", loging2.NoLogStatus, tt)
  85. EnterGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4605000", loging2.NoLogStatus, tt)
  86. EnterMain, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4701000", loging2.NoLogStatus, tt)
  87. EnterFee, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4800000", loging2.NoLogStatus, tt)
  88. EnterXmyLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4601000", loging2.NoLogStatus, tt)
  89. EnterWxLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4602000", loging2.NoLogStatus, tt)
  90. EnterMzLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.YesterdayDate(), gameIdInt, "4603000", loging2.NoLogStatus, tt)
  91. BanOff1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601006", loging2.FailStatus, tt) // 小绵羊登录封号
  92. BanOff2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602008", loging2.FailStatus, tt) // 微信登录封号
  93. BanOff3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603006", loging2.FailStatus, tt) // 魅族登录封号
  94. BanOff4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701003", loging2.FailStatus, tt) // 主线封号
  95. Freeze, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4809904", loging2.NoLogStatus, tt) // 冻结
  96. BanOff := BanOff1 + BanOff2 + BanOff3 + BanOff4
  97. EnterLogin := EnterXmyLogin + EnterMzLogin + EnterWxLogin
  98. statisticsLog.PullAccountOk = pullAccountOk
  99. statisticsLog.PullAccountFail = pullAccountFail
  100. statisticsLog.StartProxyFail = StartProxyFail
  101. statisticsLog.StartProxyOk = StartProxyOk
  102. statisticsLog.SimulatorStartFail = SimulatorStartFail
  103. statisticsLog.SimulatorStartOk = SimulatorStartOk
  104. statisticsLog.NetworkCheckFail = NetworkCheckFail
  105. statisticsLog.NetworkCheckOk = NetworkCheckOk
  106. statisticsLog.EnterMainFail = EnterMainFail
  107. statisticsLog.EnterMainOk = EnterMainOk
  108. statisticsLog.EnterGameFail = EnterGameFail
  109. statisticsLog.EnterGameOk = EnterGameOk
  110. statisticsLog.GameId = gameIdInt
  111. statisticsLog.ConstituencyFail = ConstituencyFail
  112. statisticsLog.ConstituencyOk = ConstituencyOk
  113. statisticsLog.FeeFail = FeeFail
  114. statisticsLog.FeeOk = FeeOk
  115. statisticsLog.GameStartFail = GameStartFail
  116. statisticsLog.GameStartOk = GameStartOk
  117. statisticsLog.LoginFail = LoginFail
  118. statisticsLog.LoginOk = LoginOk
  119. statisticsLog.XmyLoginFail = xmyLoginFail
  120. statisticsLog.XmyLoginOk = xmyLoginOk
  121. statisticsLog.WxLoginFail = wxLoginFail
  122. statisticsLog.WxLoginOk = wxLoginOk
  123. statisticsLog.MzLoginFail = mzLoginFail
  124. statisticsLog.MzLoginOk = mzLoginOk
  125. statisticsLog.ScriptStartFail = ScriptStartFail
  126. statisticsLog.ScriptStartOk = ScriptStartOk
  127. statisticsLog.AuthenticationFail = AuthenticationFail
  128. statisticsLog.AuthenticationOk = AuthenticationOk
  129. statisticsLog.HasRole = HasRole
  130. statisticsLog.NotRole = NotRole
  131. statisticsLog.EnterStartGame = EnterStartGame
  132. statisticsLog.EnterAuthentication = EnterAuthentication
  133. statisticsLog.EnterConstituency = EnterConstituency
  134. statisticsLog.EnterGame = EnterGame
  135. statisticsLog.EnterMain = EnterMain
  136. statisticsLog.EnterFee = EnterFee
  137. statisticsLog.EnterLogin = EnterLogin
  138. statisticsLog.BanOff = BanOff
  139. statisticsLog.Freeze = Freeze
  140. statisticsLog.Type = tt
  141. statisticsLog.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  142. statisticsLog.CreateDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02")
  143. statisticsLogs = append(statisticsLogs, statisticsLog)
  144. if len(statisticsLogs) == 100 {
  145. err = global.GVA_DB.Create(statisticsLogs).Error
  146. if err != nil {
  147. global.GVA_LOG.Error("添加statisticsLogs失败!", zap.Error(err))
  148. return
  149. }
  150. statisticsLogs = []*log.StatisticsLog{}
  151. }
  152. }
  153. }
  154. if len(statisticsLogs) == 0 {
  155. global.GVA_REDIS.Set(ctx, key, 1, 24*time.Hour)
  156. return
  157. }
  158. err = global.GVA_DB.Create(statisticsLogs).Error
  159. if err != nil {
  160. global.GVA_LOG.Error("添加statisticsLogs失败!", zap.Error(err))
  161. return
  162. }
  163. global.GVA_REDIS.Set(ctx, key, 1, 24*time.Hour)
  164. return
  165. }
  166. func (s *ServiceStatisticsLog) TodayStatisticsLogList1() (interface{}, error) {
  167. gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.CurrentDate())
  168. if err != nil {
  169. global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
  170. return nil, err
  171. }
  172. /*var statisticsLogs []*log.StatisticsLog
  173. for _,info := range apiList{
  174. statisticsLog := new(log.StatisticsLog)
  175. statisticsLog.PullAccountOk = info.PullAccountOk
  176. statisticsLog.PullAccountFail = info.PullAccountFail
  177. statisticsLog.StartProxyFail = info.StartProxyFail
  178. statisticsLog.StartProxyOk = info.StartProxyOk
  179. statisticsLog.SimulatorStartFail = info.SimulatorStartFail
  180. statisticsLog.SimulatorStartOk = info.SimulatorStartOk
  181. statisticsLog.NetworkCheckFail = info.NetworkCheckFail
  182. statisticsLog.NetworkCheckOk = info.NetworkCheckOk
  183. statisticsLog.EnterMainFail = info.EnterMainFail
  184. statisticsLog.EnterMainOk = info.EnterMainOk
  185. statisticsLog.EnterGameFail = info.EnterGameFail
  186. statisticsLog.EnterGameOk = info.EnterGameOk
  187. statisticsLog.GameId = info.GameId
  188. statisticsLog.ConstituencyFail = info.ConstituencyFail
  189. statisticsLog.ConstituencyOk = info.ConstituencyOk
  190. statisticsLog.FeeFail = info.FeeFail
  191. statisticsLog.FeeOk = info.FeeOk
  192. statisticsLog.GameStartFail = info.GameStartFail
  193. statisticsLog.GameStartOk = info.GameStartOk
  194. statisticsLog.LoginFail = info.LoginFail
  195. statisticsLog.LoginOk = info.LoginOk
  196. statisticsLog.XmyLoginFail = info.XmyLoginFail
  197. statisticsLog.XmyLoginOk = info.XmyLoginOk
  198. statisticsLog.WxLoginFail = info.WxLoginFail
  199. statisticsLog.WxLoginOk = info.WxLoginOk
  200. statisticsLog.MzLoginFail = info.MzLoginFail
  201. statisticsLog.MzLoginOk = info.MzLoginOk
  202. statisticsLog.ScriptStartFail = info.ScriptStartFail
  203. statisticsLog.ScriptStartOk = info.ScriptStartOk
  204. statisticsLog.AuthenticationFail = info.AuthenticationFail
  205. statisticsLog.AuthenticationOk = info.AuthenticationOk
  206. statisticsLog.HasRole = info.HasRole
  207. statisticsLog.NotRole = info.NotRole
  208. statisticsLog.EnterStartGame = info.EnterStartGame
  209. statisticsLog.EnterAuthentication = info.EnterAuthentication
  210. statisticsLog.EnterConstituency = info.EnterConstituency
  211. statisticsLog.EnterGame = info.EnterGame
  212. statisticsLog.EnterMain = info.EnterMain
  213. statisticsLog.EnterFee = info.EnterFee
  214. statisticsLog.EnterLogin = info.EnterLogin
  215. statisticsLog.BanOff = info.BanOff
  216. statisticsLog.Freeze = info.Freeze
  217. statisticsLog.Type = info.Type
  218. statisticsLog.CreateTime = info.CreateTime
  219. statisticsLog.CreateDate = info.CreateDate
  220. statisticsLogs = append(statisticsLogs,statisticsLog)
  221. }*/
  222. ctx := context.Background()
  223. var gmps = map[string][]map[int]interface{}{}
  224. for gameId, _ := range gameMps {
  225. var TTmps = map[int]interface{}{}
  226. gameIdInt, _ := strconv.Atoi(gameId)
  227. for _, tt := range TaskType {
  228. cacheKeys, err := s.LogicalLog.GetGameStatisticsCacheKeys(ctx, s.CurrentDate(), gameIdInt, tt)
  229. if err != nil {
  230. if err == redis.Nil {
  231. continue
  232. }
  233. return nil, err
  234. }
  235. var dmps = map[string]string{}
  236. for _, cacheKey := range cacheKeys {
  237. num, _ := global.GVA_REDIS.Get(ctx, cacheKey).Result()
  238. code := s.LogicalLog.ByCacheKeyGetEndNode(cacheKey)
  239. dmps[code] = num
  240. }
  241. if len(dmps) != 0 {
  242. TTmps[tt] = dmps
  243. }
  244. }
  245. gmps[gameId] = append(gmps[gameId], TTmps)
  246. }
  247. return gmps, err
  248. }
  249. func (s *ServiceStatisticsLog) TodayStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo) (interface{}, int64, error) {
  250. gameMps, err := s.LogicalLog.GetGameCache(context.Background(), s.CurrentDate())
  251. if err != nil {
  252. global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
  253. return nil, 0, err
  254. }
  255. if len(gameMps) == 0 {
  256. global.GVA_LOG.Info("获取redis game list没有数据!")
  257. return nil, 0, err
  258. }
  259. if api.GameId != 0 {
  260. _, b := gameMps[strconv.Itoa(api.GameId)]
  261. if !b {
  262. return nil, 0, nil
  263. }
  264. gameMps = map[string]string{strconv.Itoa(api.GameId): "1"}
  265. }
  266. limit := info.PageSize
  267. offset := info.PageSize * (info.Page - 1)
  268. total := len(gameMps)
  269. var statisticsLogs []*log.StatisticsLog
  270. for i := 0; i < limit+offset; i++ {
  271. }
  272. i := 0
  273. lf := limit + offset
  274. for gameId, _ := range gameMps {
  275. if i < offset {
  276. i++
  277. continue
  278. }
  279. if i >= lf {
  280. break
  281. }
  282. for _, tt := range TaskType {
  283. statisticsLog := new(log.StatisticsLog)
  284. gameIdInt, _ := strconv.Atoi(gameId)
  285. pullAccountOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4100000", loging2.OkStatus, tt)
  286. pullAccountFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4100000", loging2.FailStatus, tt)
  287. ConstituencyFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.FailStatus, tt)
  288. ConstituencyOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.OkStatus, tt)
  289. StartProxyFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4200000", loging2.FailStatus, tt)
  290. StartProxyOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4200000", loging2.OkStatus, tt)
  291. SimulatorStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
  292. SimulatorStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
  293. NetworkCheckFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4400000", loging2.FailStatus, tt)
  294. NetworkCheckOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4400000", loging2.OkStatus, tt)
  295. GameStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4500000", loging2.FailStatus, tt)
  296. GameStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4500000", loging2.OkStatus, tt)
  297. xmyLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.FailStatus, tt)
  298. xmyLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.OkStatus, tt)
  299. wxLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.FailStatus, tt)
  300. wxLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.OkStatus, tt)
  301. mzLoginFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.FailStatus, tt)
  302. mzLoginOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.OkStatus, tt)
  303. LoginFail := xmyLoginFail + wxLoginFail + mzLoginFail
  304. LoginOk := xmyLoginOk + wxLoginOk + mzLoginOk
  305. EnterMainFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4700000", loging2.FailStatus, tt)
  306. EnterMainOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4700000", loging2.OkStatus, tt)
  307. FeeFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4800000", loging2.FailStatus, tt)
  308. FeeOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4800000", loging2.OkStatus, tt)
  309. ScriptStartFail, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.FailStatus, tt)
  310. ScriptStartOk, _ := s.LogicalLog.NodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4300000", loging2.OkStatus, tt)
  311. EnterGameFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.FailStatus, tt)
  312. EnterGameOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.OkStatus, tt)
  313. AuthenticationFail, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.FailStatus, tt)
  314. AuthenticationOk, _ := s.LogicalLog.TypeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.OkStatus, tt)
  315. HasRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4609902", loging2.NoLogStatus, tt)
  316. NotRole, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4609901", loging2.NoLogStatus, tt)
  317. EnterStartGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4501000", loging2.NoLogStatus, tt)
  318. EnterAuthentication, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4607000", loging2.NoLogStatus, tt)
  319. EnterConstituency, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4604000", loging2.NoLogStatus, tt)
  320. EnterGame, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4605000", loging2.NoLogStatus, tt)
  321. EnterMain, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701000", loging2.NoLogStatus, tt)
  322. EnterFee1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4801000", loging2.NoLogStatus, tt) //小绵羊进入付费
  323. EnterFee2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4802000", loging2.NoLogStatus, tt) //微信进入付费
  324. EnterFee3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4803000", loging2.NoLogStatus, tt) //魅族进入付费
  325. EnterFee4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4804000", loging2.NoLogStatus, tt) //QQ卡进入付费
  326. EnterFee := EnterFee1 + EnterFee2 + EnterFee3 + EnterFee4
  327. EnterXmyLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601000", loging2.NoLogStatus, tt)
  328. EnterWxLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602000", loging2.NoLogStatus, tt)
  329. EnterMzLogin, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603000", loging2.NoLogStatus, tt)
  330. BanOff1, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4601006", loging2.FailStatus, tt) // 小绵羊登录封号
  331. BanOff2, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4602008", loging2.FailStatus, tt) // 微信登录封号
  332. BanOff3, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4603006", loging2.FailStatus, tt) // 魅族登录封号
  333. BanOff4, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4701003", loging2.FailStatus, tt) // 主线封号
  334. Freeze, _ := s.LogicalLog.CodeLogGetNum(ctx, s.CurrentDate(), gameIdInt, "4809904", loging2.NoLogStatus, tt) // 冻结
  335. BanOff := BanOff1 + BanOff2 + BanOff3 + BanOff4
  336. EnterLogin := EnterXmyLogin + EnterMzLogin + EnterWxLogin
  337. statisticsLog.PullAccountOk = pullAccountOk
  338. statisticsLog.PullAccountFail = pullAccountFail
  339. statisticsLog.StartProxyFail = StartProxyFail
  340. statisticsLog.StartProxyOk = StartProxyOk
  341. statisticsLog.SimulatorStartFail = SimulatorStartFail
  342. statisticsLog.SimulatorStartOk = SimulatorStartOk
  343. statisticsLog.NetworkCheckFail = NetworkCheckFail
  344. statisticsLog.NetworkCheckOk = NetworkCheckOk
  345. statisticsLog.EnterMainFail = EnterMainFail
  346. statisticsLog.EnterMainOk = EnterMainOk
  347. statisticsLog.EnterGameFail = EnterGameFail
  348. statisticsLog.EnterGameOk = EnterGameOk
  349. statisticsLog.GameId = gameIdInt
  350. statisticsLog.ConstituencyFail = ConstituencyFail
  351. statisticsLog.ConstituencyOk = ConstituencyOk
  352. statisticsLog.FeeFail = FeeFail
  353. statisticsLog.FeeOk = FeeOk
  354. statisticsLog.GameStartFail = GameStartFail
  355. statisticsLog.GameStartOk = GameStartOk
  356. statisticsLog.LoginFail = LoginFail
  357. statisticsLog.LoginOk = LoginOk
  358. statisticsLog.XmyLoginFail = xmyLoginFail
  359. statisticsLog.XmyLoginOk = xmyLoginOk
  360. statisticsLog.WxLoginFail = wxLoginFail
  361. statisticsLog.WxLoginOk = wxLoginOk
  362. statisticsLog.MzLoginFail = mzLoginFail
  363. statisticsLog.MzLoginOk = mzLoginOk
  364. statisticsLog.ScriptStartFail = ScriptStartFail
  365. statisticsLog.ScriptStartOk = ScriptStartOk
  366. statisticsLog.AuthenticationFail = AuthenticationFail
  367. statisticsLog.AuthenticationOk = AuthenticationOk
  368. statisticsLog.HasRole = HasRole
  369. statisticsLog.NotRole = NotRole
  370. statisticsLog.EnterStartGame = EnterStartGame
  371. statisticsLog.EnterAuthentication = EnterAuthentication
  372. statisticsLog.EnterConstituency = EnterConstituency
  373. statisticsLog.EnterGame = EnterGame
  374. statisticsLog.EnterMain = EnterMain
  375. statisticsLog.EnterFee = EnterFee
  376. statisticsLog.EnterLogin = EnterLogin
  377. statisticsLog.BanOff = BanOff
  378. statisticsLog.Freeze = Freeze
  379. statisticsLog.Type = tt
  380. statisticsLog.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  381. statisticsLog.CreateDate = time.Now().Format("2006-01-02")
  382. statisticsLogs = append(statisticsLogs, statisticsLog)
  383. }
  384. }
  385. return statisticsLogs, int64(total), err
  386. }
  387. func (s *ServiceStatisticsLog) OtherStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
  388. date := api.CreateDate
  389. if date == "" || date == s.CurrentDate() {
  390. apilist, total, err := s.TodayStatisticsLogList(ctx, api, info)
  391. return apilist, total, err
  392. }
  393. db := global.GVA_DB.Model(&log.StatisticsLog{})
  394. if api.GameId != 0 {
  395. db = db.Where("game_id = ?", api.GameId)
  396. }
  397. var total int64
  398. err := db.Count(&total).Error
  399. if err != nil {
  400. return nil, 0, err
  401. }
  402. limit := info.PageSize
  403. offset := info.PageSize * (info.Page - 1)
  404. var statisticsLogs []*log.StatisticsLog
  405. db = db.Where("create_date = ?", date)
  406. db = db.Limit(limit).Offset(offset)
  407. err = db.Order("id").Find(&statisticsLogs).Error
  408. if err != nil {
  409. return nil, 0, err
  410. }
  411. for _, statisticsLog := range statisticsLogs {
  412. statisticsLog.CreateDate = statisticsLog.CreateDate[:10]
  413. }
  414. return statisticsLogs, total, err
  415. }
  416. func (s *ServiceStatisticsLog) ResetStatisticsLog(ctx context.Context, gameId int, date string) {
  417. var total int64
  418. key := date + ":" + strconv.Itoa(gameId) + ":reset"
  419. global.GVA_REDIS.Set(ctx, key, 1, time.Minute*15)
  420. db := global.GVA_DB.Table("loging")
  421. db = db.Where("game_id = ?", gameId)
  422. err := db.Count(&total).Error
  423. if err != nil {
  424. global.GVA_LOG.Error("重置统计数据总数报错", zap.Error(err))
  425. return
  426. }
  427. limit := 100
  428. num := int(math.Ceil(float64(total) / float64(limit)))
  429. offset := 0
  430. err = s.LogicalLog.DelStatisticsNumCache(ctx, date, gameId)
  431. if err != nil {
  432. global.GVA_LOG.Error("重置统计数据删除缓存报错", zap.Error(err))
  433. return
  434. }
  435. err = s.LogicalLog.DelUuidCodeCache(ctx, date, gameId)
  436. if err != nil {
  437. global.GVA_LOG.Error("重置统计数据删除缓存报错2", zap.Error(err))
  438. return
  439. }
  440. global.GVA_LOG.Info("num = " + strconv.Itoa(num))
  441. for i := 0; i < num; i++ {
  442. global.GVA_LOG.Info("offset = " + strconv.Itoa(offset))
  443. var statisticsLogs []request.AddLogRequest
  444. db2 := global.GVA_DB.Table("loging")
  445. db2 = db2.Where("create_date = ?", date)
  446. db2 = db2.Where("game_id = ?", gameId)
  447. db2 = db2.Limit(limit).Offset(offset)
  448. err = db2.Order("id").Find(&statisticsLogs).Error
  449. for _, statisticsLog := range statisticsLogs {
  450. s.ResetStatisticsCache(ctx, statisticsLog, date)
  451. }
  452. offset += limit
  453. }
  454. global.GVA_LOG.Info("重置统计数据完成")
  455. }
  456. func (s *ServiceStatisticsLog) ResetStatisticsCache(c context.Context, api request.AddLogRequest, date string) {
  457. coding := strconv.Itoa(api.Coding)
  458. nodeCoding := coding[:3]
  459. status := coding[5:]
  460. noLogStatus := coding[3:5]
  461. var logical ServiceResetLoging
  462. switch nodeCoding {
  463. case "410":
  464. logical = new(loging2.ResetLog)
  465. break
  466. case "430":
  467. logical = new(loging2.ResetLog)
  468. break
  469. default:
  470. logical = new(loging2.ResetOtherLog)
  471. break
  472. }
  473. var err error
  474. if status == "99" {
  475. err = logical.SuccessLog(c, api, date)
  476. } else if noLogStatus == "99" {
  477. err = logical.NoLogStatusData(c, api, date)
  478. } else {
  479. err = logical.FailLog(c, api, date)
  480. }
  481. if err != nil {
  482. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  483. }
  484. }
  485. // 每天凌晨reset统计数据
  486. func (s *ServiceStatisticsLog) EveryDayResetStatisticsCache() {
  487. date := s.YesterdayDate()
  488. ctx := context.Background()
  489. gameMps, err := s.LogicalLog.GetGameCache(ctx, date)
  490. if err != nil {
  491. global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
  492. return
  493. }
  494. if len(gameMps) == 0 {
  495. global.GVA_LOG.Info("获取redis game list没有数据!")
  496. return
  497. }
  498. for gameId, _ := range gameMps {
  499. id, _ := strconv.Atoi(gameId)
  500. s.ResetStatisticsLog(ctx, id, date)
  501. }
  502. global.GVA_LOG.Info("游戏重置缓存完成!")
  503. }
  504. func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
  505. ctx := context.Background()
  506. codeMps, err := s.LogicalLog.GetComputerCache(ctx, s.LogicalLog.CurrentDate())
  507. if err != nil {
  508. return
  509. }
  510. if len(codeMps) == 0 {
  511. return
  512. }
  513. var csReplys []*log.LogComputer
  514. for code, r := range codeMps {
  515. csReply := new(log.LogComputer)
  516. csReply.PcCode = code
  517. csReply.Operator = r
  518. var gameInfos []*response.GameInfo
  519. accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
  520. if err != nil {
  521. continue
  522. }
  523. taskMps, err := s.LogicalLog.GetComputerTaskSuccessNumCache(ctx, s.LogicalLog.CurrentDate(), code)
  524. if err != nil {
  525. continue
  526. }
  527. for gameId, num := range accountMps {
  528. gameInfo := new(response.GameInfo)
  529. gameInfo.GameId = gameId
  530. gameInfo.PullAccountNum = num
  531. gameInfo.TaskSuccessNum = taskMps[gameId]
  532. gameInfos = append(gameInfos, gameInfo)
  533. }
  534. gameInfoByte, _ := json.Marshal(gameInfos)
  535. csReply.GameInfo = string(gameInfoByte)
  536. csReply.CreateDate = time.Now().Format("2006-01-02")
  537. if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
  538. // 已存在,更新
  539. mp := make(map[string]interface{})
  540. mp["game_info"] = string(gameInfoByte)
  541. if csReply.Operator != "" {
  542. mp["operator"] = csReply.Operator
  543. }
  544. err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Updates(mp).Error
  545. if err != nil {
  546. global.GVA_LOG.Error("更新数据失败", zap.Error(err))
  547. }
  548. continue
  549. }
  550. csReplys = append(csReplys, csReply)
  551. }
  552. if len(csReplys) != 0 {
  553. err = global.GVA_DB.Table("log_computer").Create(csReplys).Error
  554. if err != nil {
  555. global.GVA_LOG.Error("更新数据失败", zap.Error(err))
  556. }
  557. }
  558. return
  559. }
  560. func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.StatisticsLog, info request.PageInfo) (interface{}, int64, error) {
  561. date := api.CreateDate
  562. if date == "" {
  563. date = s.CurrentDate()
  564. }
  565. db := global.GVA_DB.Model(&log.LogComputer{})
  566. var total int64
  567. err := db.Count(&total).Error
  568. if err != nil {
  569. return nil, 0, err
  570. }
  571. limit := info.PageSize
  572. offset := info.PageSize * (info.Page - 1)
  573. var statisticsLogs []*log.LogComputer
  574. db = db.Where("create_date = ?", date)
  575. db = db.Limit(limit).Offset(offset)
  576. err = db.Order("id").Find(&statisticsLogs).Error
  577. if err != nil {
  578. return nil, 0, err
  579. }
  580. var statisticsLogsComputer []*response.ComputerStatisticsReply1
  581. for _, statisticsLog := range statisticsLogs {
  582. var gameInfo []*response.GameInfo
  583. err = json.Unmarshal([]byte(statisticsLog.GameInfo), &gameInfo)
  584. statisticsLogComputer := new(response.ComputerStatisticsReply1)
  585. statisticsLogComputer.GameInfo = gameInfo
  586. statisticsLogComputer.PcCode = statisticsLog.PcCode
  587. statisticsLogComputer.Operator = statisticsLog.Operator
  588. statisticsLogComputer.CreateDate = statisticsLog.CreateDate[:10]
  589. statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
  590. }
  591. return statisticsLogsComputer, total, err
  592. }