log_ip.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package log
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "go.uber.org/zap"
  6. "log-server/global"
  7. log2 "log-server/model/log"
  8. "log-server/model/log/request"
  9. "log-server/model/log/response"
  10. "log-server/utils"
  11. )
  12. type ApiIpLog struct {
  13. }
  14. // @Tags loging
  15. // @Summary 获取iplog
  16. // @Security ApiKeyAuth
  17. // @accept application/json
  18. // @Produce application/json
  19. // @Param data body request.IpLogListRequest true "获取iplog"
  20. // @Success 200 {object} response.Response{data=log2.IpLog} "获取iplog列表"
  21. // @Router /loging/getIpLogList [post]
  22. func (s *ApiIpLog) GetIpLogList(c *gin.Context) {
  23. var paramsInfo request.IpLogListRequest
  24. _ = c.ShouldBindJSON(&paramsInfo)
  25. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  26. response.FailWithMessage(err.Error(), c)
  27. return
  28. }
  29. list, total, err := ServiceIpLog.GetIpLogList(paramsInfo.IpLogRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  30. if err != nil {
  31. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  32. response.FailWithMessage("获取失败", c)
  33. } else {
  34. response.OkWithDetailed(response.PageResult{
  35. List: list,
  36. Total: total,
  37. Page: paramsInfo.Page,
  38. PageSize: paramsInfo.PageSize,
  39. }, "获取成功", c)
  40. }
  41. }
  42. //根据gameId分组获取ip
  43. func (s *ApiIpLog) GetGameIPList(c *gin.Context) {
  44. var paramsInfo request.GameIpRequest
  45. _ = c.ShouldBindJSON(&paramsInfo)
  46. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  47. response.FailWithMessage(err.Error(), c)
  48. return
  49. }
  50. list, total, err := ServiceIpLog.GetGameIpList(paramsInfo.GameIpRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  51. if err != nil {
  52. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  53. response.FailWithMessage("获取失败", c)
  54. } else {
  55. response.OkWithDetailed(response.PageResult{
  56. List: list,
  57. Total: total,
  58. Page: paramsInfo.Page,
  59. PageSize: paramsInfo.PageSize,
  60. }, "获取成功", c)
  61. }
  62. }
  63. // @Tags loging
  64. // @Summary 获取某天具体ip
  65. // @Security ApiKeyAuth
  66. // @accept application/json
  67. // @Produce application/json
  68. // @Param data body log2.IpLog true "获取ip"
  69. // @Success 200 {object} response.Response{data=log2.IpResponse} "获取iplog列表"
  70. // @Router /loging/getIp [post]
  71. func (s *ApiIpLog) GetIp(c *gin.Context) {
  72. var ip log2.IpLogResponse
  73. _ = c.ShouldBindJSON(&ip)
  74. if ip.GameId == 0 {
  75. response.FailWithMessage("游戏id不能为空", c)
  76. return
  77. }
  78. if ip.PcCode == "" {
  79. response.FailWithMessage("租机编号不能为空", c)
  80. return
  81. }
  82. if ip.CreateDate == ""{
  83. response.FailWithMessage("创建日期不能为空", c)
  84. return
  85. }
  86. list, total, err := ServiceIpLog.GetIp(ip)
  87. if err != nil {
  88. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  89. response.FailWithMessage("获取失败", c)
  90. } else {
  91. response.OkWithDetailed(response.PageResult{
  92. List: list,
  93. Total: total,
  94. }, "获取成功", c)
  95. }
  96. }
  97. //游戏id分组获取某天具体ip
  98. func (s *ApiIpLog) GetGameIp(c *gin.Context) {
  99. var ip log2.GameIpResponse
  100. _ = c.ShouldBindJSON(&ip)
  101. if ip.GameId == 0 {
  102. response.FailWithMessage("游戏id不能为空", c)
  103. return
  104. }
  105. if ip.CreateDate == ""{
  106. response.FailWithMessage("创建日期不能为空", c)
  107. return
  108. }
  109. list, total, err := ServiceIpLog.GetGameIp(ip)
  110. if err != nil {
  111. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  112. response.FailWithMessage("获取失败", c)
  113. } else {
  114. response.OkWithDetailed(response.PageResult{
  115. List: list,
  116. Total: total,
  117. }, "获取成功", c)
  118. }
  119. }
  120. //导出列表
  121. func (s *ApiIpLog) GameIpExport(c *gin.Context) {
  122. var excelInfo request.ExcelIpInfo
  123. _ = c.ShouldBindJSON(&excelInfo)
  124. fmt.Println(excelInfo)
  125. paramsInfo := excelInfo.InfoList
  126. paramsInfo.PageSize = 300
  127. paramsInfo.Page = 1
  128. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  129. response.FailWithMessage(err.Error(), c)
  130. return
  131. }
  132. list, _, err := ServiceIpLog.GetGameIpList(paramsInfo.GameIpRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  133. if err != nil {
  134. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  135. response.FailWithMessage("获取失败 "+err.Error(), c)
  136. }
  137. //var nowTime string = time.Now().Format("2006-01-02_15:04")
  138. //excelInfo.FileName = nowTime + "-ip.xlsx"
  139. //fmt.Println(excelInfo.FileName)
  140. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  141. err = ServiceIpLog.GameIpListExcel(list, filePath)
  142. if err != nil {
  143. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  144. response.FailWithMessage("转换Excel失败", c)
  145. return
  146. }
  147. c.Writer.Header().Add("success", "true")
  148. c.File(filePath)
  149. }