loging.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package log
  2. import (
  3. "encoding/json"
  4. "github.com/gin-gonic/gin"
  5. "go.uber.org/zap"
  6. "log-server/global"
  7. "log-server/model/common/response"
  8. "log-server/model/log/request"
  9. "log-server/service/log"
  10. loging2 "log-server/service/log/loging"
  11. "log-server/utils"
  12. "strconv"
  13. "time"
  14. )
  15. type ApiLoging struct {
  16. }
  17. // @Tags loging
  18. // @Summary 添加日志
  19. // @Security ApiKeyAuth
  20. // @accept application/json
  21. // @Produce application/json
  22. // @Param data body request.AddLogRequest true "simulator_ip(模拟器ip),simulator_mac(模拟器mac地址),pc_code(租机编号),pc_mac(租机mac地址),pc_ip(租机ip),device_id(绑定的设备id),account(账号),game_id(游戏id),coding(上传编码),computer_type(电脑类型),env_code(环境编号),log_uuid(日志uuid唯一,可以时间戳加随机数。上报一轮后更换),operator(脚本开发员),account_type(账号类型),remarks(备注),report_points_data(打点数据),task_type(1新增,2活跃),script_type(1中控,2脚本)脚本类型"
  23. // @Success 200 {object} response.Response{msg=string} "添加日志"
  24. // @Router /loging/setLog [Post]
  25. func (s *ApiLoging) CreateLog(c *gin.Context) {
  26. var api request.AddLogRequest
  27. _ = c.ShouldBindJSON(&api)
  28. body, _ := json.Marshal(api)
  29. global.GVA_LOG.Info(string(body))
  30. if err := utils.Verify(api, utils.LogAddVerify); err != nil {
  31. response.FailWithMessage(err.Error(), c)
  32. return
  33. }
  34. coding := strconv.Itoa(api.Coding)
  35. if len(coding) != 7 {
  36. response.FailWithMessage("该日志码没有7位"+coding, c)
  37. return
  38. }
  39. nodeCoding := coding[:3]
  40. status := coding[5:]
  41. noLogStatus := coding[3:5]
  42. var logical log.ServiceLoging
  43. switch nodeCoding {
  44. case "410":
  45. logical = new(loging2.PullAccountLog)
  46. break
  47. case "430":
  48. logical = new(loging2.SimulatorStartLog)
  49. break
  50. case "450":
  51. logical = new(loging2.GameStartLog)
  52. break
  53. case "460":
  54. logical = new(loging2.LoginLog)
  55. break
  56. case "470":
  57. logical = new(loging2.EnterMainLog)
  58. break
  59. case "480":
  60. logical = new(loging2.FeeLog)
  61. break
  62. default:
  63. logical = new(loging2.OtherLog)
  64. break
  65. }
  66. go ServiceLogList.CreateLog(c, api, logical, status, noLogStatus)
  67. response.OkWithMessage("后台已接收数据", c)
  68. }
  69. // @Tags loging
  70. // @Summary 获取log
  71. // @Security ApiKeyAuth
  72. // @accept application/json
  73. // @Produce application/json
  74. // @Param data body request.GetLogListRequest true "获取log"
  75. // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "根据id获取coding,返回包括coding详情"
  76. // @Router /loging/getLogList [post]
  77. func (s *ApiLoging) GetLogList(c *gin.Context) {
  78. var paramsInfo request.GetLogListRequest
  79. _ = c.ShouldBindJSON(&paramsInfo)
  80. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  81. response.FailWithMessage(err.Error(), c)
  82. return
  83. }
  84. list, total, err := ServiceLogList.GetCodeLogList(c, paramsInfo.Loging, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, paramsInfo.Code)
  85. if err != nil {
  86. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  87. response.FailWithMessage("获取失败", c)
  88. } else {
  89. response.OkWithDetailed(response.PageResult{
  90. List: list,
  91. Total: total,
  92. Page: paramsInfo.Page,
  93. PageSize: paramsInfo.PageSize,
  94. }, "获取成功", c)
  95. }
  96. }
  97. // @Tags loging
  98. // @Summary 获取打点log
  99. // @Security ApiKeyAuth
  100. // @accept application/json
  101. // @Produce application/json
  102. // @Param data body request.GetLogListRequest true "获取打点log"
  103. // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "获取打点log列表"
  104. // @Router /loging/getReportLogList [post]
  105. func (s *ApiLoging) GetReportPointsLogList(c *gin.Context) {
  106. var paramsInfo request.ReportPointsListRequest
  107. _ = c.ShouldBindJSON(&paramsInfo)
  108. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  109. response.FailWithMessage(err.Error(), c)
  110. return
  111. }
  112. list, total, err := ServiceReportPointsLog.GetReportPointsLogList(paramsInfo.ReportPointsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  113. if err != nil {
  114. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  115. response.FailWithMessage("获取失败", c)
  116. } else {
  117. response.OkWithDetailed(response.PageResult{
  118. List: list,
  119. Total: total,
  120. Page: paramsInfo.Page,
  121. PageSize: paramsInfo.PageSize,
  122. }, "获取成功", c)
  123. }
  124. }
  125. // @Tags loging
  126. // @Summary 获取统计log
  127. // @Security ApiKeyAuth
  128. // @accept application/json
  129. // @Produce application/json
  130. // @Success 200 {object} response.Response{data=interface{}} "获取统计log"
  131. // @Router /loging/getStatisticsLogList [post]
  132. func (s *ApiLoging) GetStatisticsLogList(c *gin.Context) {
  133. var paramsInfo request.GetStatisticsLogRequest
  134. _ = c.ShouldBindJSON(&paramsInfo)
  135. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  136. response.FailWithMessage(err.Error(), c)
  137. return
  138. }
  139. list, total, err := ServiceStatisticsLog.OtherStatisticsLogList(c, paramsInfo.StatisticsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  140. if err != nil {
  141. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  142. response.FailWithMessage("获取失败", c)
  143. } else {
  144. response.OkWithDetailed(response.PageResult{
  145. List: list,
  146. Total: total,
  147. Page: paramsInfo.Page,
  148. PageSize: paramsInfo.PageSize,
  149. }, "获取成功", c)
  150. }
  151. }
  152. // @Tags loging
  153. // @Summary 重置统计log
  154. // @Security ApiKeyAuth
  155. // @accept application/json
  156. // @Produce application/json
  157. // @Param data body request.GetById true "根据id重置统计log"
  158. // @Success 200 {object} response.Response{data=interface{}} "重置统计log"
  159. // @Router /loging/resetStatisticsLog [post]
  160. func (s *ApiLoging) ResetStatisticsLog(c *gin.Context) {
  161. var paramsInfo request.GetById
  162. _ = c.ShouldBindJSON(&paramsInfo)
  163. if err := utils.Verify(paramsInfo, utils.IdVerify); err != nil {
  164. response.FailWithMessage(err.Error(), c)
  165. return
  166. }
  167. current := time.Now().Format("2006-01-02")
  168. key := current + ":" + strconv.Itoa(paramsInfo.ID) + ":reset"
  169. i, err := global.GVA_REDIS.Exists(c, key).Result()
  170. if err != nil {
  171. global.GVA_LOG.Error("重置统计数据检测key失败", zap.Error(err))
  172. response.FailWithMessage("重置失败", c)
  173. return
  174. }
  175. if i != 0 {
  176. global.GVA_LOG.Info("还在重置中", zap.Error(err))
  177. response.FailWithMessage("在重置中", c)
  178. return
  179. }
  180. go ServiceStatisticsLog.ResetStatisticsLog(c, paramsInfo.ID, current)
  181. response.OkWithMessage("后台重置中", c)
  182. }
  183. // @Tags loging
  184. // @Summary 获取统计电脑
  185. // @Security ApiKeyAuth
  186. // @accept application/json
  187. // @Produce application/json
  188. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑"
  189. // @Router /loging/getComputerStatistics [post]
  190. func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
  191. var paramsInfo request.GetStatisticsComputerRequest
  192. _ = c.ShouldBindJSON(&paramsInfo)
  193. /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  194. response.FailWithMessage(err.Error(), c)
  195. return
  196. }*/
  197. list, total, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo)
  198. if err != nil {
  199. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  200. response.FailWithMessage("获取失败", c)
  201. } else {
  202. response.OkWithDetailed(response.PageResult{
  203. List: list,
  204. Total: total,
  205. Page: paramsInfo.Page,
  206. PageSize: paramsInfo.PageSize,
  207. }, "获取成功", c)
  208. }
  209. }