loging.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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/getNodeStatisticsLogList [post]
  132. func (s *ApiLoging) GetNodeStatisticsLogList(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.StatisticsNodeLogList(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. // @Success 200 {object} response.Response{data=interface{}} "获取统计log"
  158. // @Router /loging/getStatisticsLogList [post]
  159. func (s *ApiLoging) GetStatisticsLogList(c *gin.Context) {
  160. var paramsInfo request.GetStatisticsLogRequest
  161. _ = c.ShouldBindJSON(&paramsInfo)
  162. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  163. response.FailWithMessage(err.Error(), c)
  164. return
  165. }
  166. list, total, err := ServiceStatisticsLog.OtherStatisticsLogList(c, paramsInfo.StatisticsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  167. if err != nil {
  168. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  169. response.FailWithMessage("获取失败", c)
  170. } else {
  171. response.OkWithDetailed(response.PageResult{
  172. List: list,
  173. Total: total,
  174. Page: paramsInfo.Page,
  175. PageSize: paramsInfo.PageSize,
  176. }, "获取成功", c)
  177. }
  178. }
  179. // @Tags loging
  180. // @Summary 重置统计log
  181. // @Security ApiKeyAuth
  182. // @accept application/json
  183. // @Produce application/json
  184. // @Param data body request.GetById true "根据id重置统计log"
  185. // @Success 200 {object} response.Response{data=interface{}} "重置统计log"
  186. // @Router /loging/resetStatisticsLog [post]
  187. func (s *ApiLoging) ResetStatisticsLog(c *gin.Context) {
  188. var paramsInfo request.GetById
  189. _ = c.ShouldBindJSON(&paramsInfo)
  190. if err := utils.Verify(paramsInfo, utils.IdVerify); err != nil {
  191. response.FailWithMessage(err.Error(), c)
  192. return
  193. }
  194. current := time.Now().Format("2006-01-02")
  195. key := current + ":" + strconv.Itoa(paramsInfo.ID) + ":reset"
  196. i, err := global.GVA_REDIS.Exists(c, key).Result()
  197. if err != nil {
  198. global.GVA_LOG.Error("重置统计数据检测key失败", zap.Error(err))
  199. response.FailWithMessage("重置失败", c)
  200. return
  201. }
  202. if i != 0 {
  203. global.GVA_LOG.Info("还在重置中", zap.Error(err))
  204. response.FailWithMessage("在重置中", c)
  205. return
  206. }
  207. go ServiceStatisticsLog.ResetStatisticsLog(c, paramsInfo.ID, current)
  208. response.OkWithMessage("后台重置中", c)
  209. }
  210. // @Tags loging
  211. // @Summary 获取统计电脑
  212. // @Security ApiKeyAuth
  213. // @accept application/json
  214. // @Produce application/json
  215. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑"
  216. // @Router /loging/getComputerStatistics [post]
  217. func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
  218. var paramsInfo request.GetStatisticsComputerRequest
  219. _ = c.ShouldBindJSON(&paramsInfo)
  220. /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  221. response.FailWithMessage(err.Error(), c)
  222. return
  223. }*/
  224. list, total, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  225. if err != nil {
  226. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  227. response.FailWithMessage("获取失败", c)
  228. } else {
  229. response.OkWithDetailed(response.PageResult{
  230. List: list,
  231. Total: total,
  232. Page: paramsInfo.Page,
  233. PageSize: paramsInfo.PageSize,
  234. }, "获取成功", c)
  235. }
  236. }
  237. // @Tags loging
  238. // @Summary 在线电脑
  239. // @Security ApiKeyAuth
  240. // @accept application/json
  241. // @Produce application/json
  242. // @Success 200 {object} response.Response{data=interface{}} "在线电脑"
  243. // @Router /loging/getOnlineComputer [post]
  244. func (s *ApiLoging) GetOnlineComputer(c *gin.Context) {
  245. var paramsInfo request.GetStatisticsComputerRequest
  246. _ = c.ShouldBindJSON(&paramsInfo)
  247. list, total, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  248. if err != nil {
  249. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  250. response.FailWithMessage("获取失败", c)
  251. } else {
  252. response.OkWithDetailed(response.PageResult{
  253. List: list,
  254. Total: total,
  255. Page: paramsInfo.Page,
  256. PageSize: paramsInfo.PageSize,
  257. }, "获取成功", c)
  258. }
  259. }
  260. // @Tags loging
  261. // @Summary 获取统计电脑数量
  262. // @Security ApiKeyAuth
  263. // @accept application/json
  264. // @Produce application/json
  265. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  266. // @Router /loging/getComputerNum [post]
  267. func (s *ApiLoging) GetComputerNum(c *gin.Context) {
  268. var paramsInfo request.GetStatisticsComputerRequest
  269. _ = c.ShouldBindJSON(&paramsInfo)
  270. num := ServiceStatisticsLog.GetComputerNum(paramsInfo.CreateDate)
  271. response.OkWithDetailed(num, "获取成功", c)
  272. }
  273. // @Tags loging
  274. // @Summary 获取统计数据通过GameId
  275. // @Security ApiKeyAuth
  276. // @accept application/json
  277. // @Produce application/json
  278. // @Success 200 {object} response.Response{data=interface{}} "获取统计数据通过GameId"
  279. // @Router /loging/getGameIdStatistics [post]
  280. func (s *ApiLoging) GetGameIdStatistics(c *gin.Context) {
  281. var paramsInfo request.GetStatisticsComputerRequest
  282. _ = c.ShouldBindJSON(&paramsInfo)
  283. /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  284. response.FailWithMessage(err.Error(), c)
  285. return
  286. }*/
  287. list, total, err := ServiceStatisticsLog.GameStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo)
  288. if err != nil {
  289. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  290. response.FailWithMessage("获取失败", c)
  291. } else {
  292. response.OkWithDetailed(response.PageResult{
  293. List: list,
  294. Total: total,
  295. Page: paramsInfo.Page,
  296. PageSize: paramsInfo.PageSize,
  297. }, "获取成功", c)
  298. }
  299. }
  300. // @Tags loging
  301. // @Summary 获取统计电脑数量
  302. // @Security ApiKeyAuth
  303. // @accept application/json
  304. // @Produce application/json
  305. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  306. // @Router /loging/computerHeartbeat [post]
  307. func (s *ApiLoging) ComputerHeartbeat(c *gin.Context) {
  308. var paramsInfo request.OnlineComputerRequest
  309. _ = c.ShouldBindJSON(&paramsInfo)
  310. if paramsInfo.PcCode == "" || paramsInfo.Operator == "" {
  311. global.GVA_LOG.Error("参数错误!")
  312. response.FailWithMessage("参数错误", c)
  313. return
  314. }
  315. num := ServiceStatisticsLog.ComputerHeartbeat(c, paramsInfo)
  316. response.OkWithDetailed(num, "上报成功", c)
  317. }
  318. // @Tags loging
  319. // @Summary 获取统计电脑数量
  320. // @Security ApiKeyAuth
  321. // @accept application/json
  322. // @Produce application/json
  323. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  324. // @Router /loging/test [post]
  325. func (s *ApiLoging) ComputerTest(c *gin.Context) {
  326. var paramsInfo request.OnlineComputerRequest
  327. _ = c.ShouldBindJSON(&paramsInfo)
  328. ServiceStatisticsLog.RegularCheckPc()
  329. response.OkWithDetailed("b", "上报成功", c)
  330. }
  331. // @Tags excel
  332. // @Summary 导出Excel
  333. // @Security ApiKeyAuth
  334. // @accept application/json
  335. // @Produce application/octet-stream
  336. // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
  337. // @Success 200
  338. // @Router /loging/exportExcel [post]
  339. func (e *ApiLoging) ExportExcel(c *gin.Context) {
  340. var excelInfo request.ExcelInfo
  341. _ = c.ShouldBindJSON(&excelInfo)
  342. paramsInfo := excelInfo.InfoList
  343. paramsInfo.PageSize = 300
  344. paramsInfo.Page = 1
  345. list, _, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  346. if err != nil {
  347. global.GVA_LOG.Error("获取电脑数据失败!", zap.Error(err))
  348. response.FailWithMessage("获取电脑数据失败", c)
  349. return
  350. }
  351. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  352. err = ServiceStatisticsLog.ParseInfoList2Excel(list, filePath)
  353. if err != nil {
  354. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  355. response.FailWithMessage("转换Excel失败", c)
  356. return
  357. }
  358. c.Writer.Header().Add("success", "true")
  359. c.File(filePath)
  360. }