| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package log
- import (
- "encoding/json"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "log-server/global"
- "log-server/model/common/response"
- "log-server/model/log/request"
- "log-server/service/log"
- loging2 "log-server/service/log/loging"
- "log-server/utils"
- "strconv"
- "time"
- )
- type ApiLoging struct {
- }
- // @Tags loging
- // @Summary 添加日志
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @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脚本)脚本类型"
- // @Success 200 {object} response.Response{msg=string} "添加日志"
- // @Router /loging/setLog [Post]
- func (s *ApiLoging) CreateLog(c *gin.Context) {
- var api request.AddLogRequest
- _ = c.ShouldBindJSON(&api)
- body, _ := json.Marshal(api)
- global.GVA_LOG.Info(string(body))
- if err := utils.Verify(api, utils.LogAddVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- coding := strconv.Itoa(api.Coding)
- if len(coding) != 7 {
- response.FailWithMessage("该日志码没有7位"+coding, c)
- return
- }
- nodeCoding := coding[:3]
- status := coding[5:]
- noLogStatus := coding[3:5]
- var logical log.ServiceLoging
- switch nodeCoding {
- case "410":
- logical = new(loging2.PullAccountLog)
- break
- case "430":
- logical = new(loging2.SimulatorStartLog)
- break
- case "450":
- logical = new(loging2.GameStartLog)
- break
- case "460":
- logical = new(loging2.LoginLog)
- break
- case "470":
- logical = new(loging2.EnterMainLog)
- break
- case "480":
- logical = new(loging2.FeeLog)
- break
- default:
- logical = new(loging2.OtherLog)
- break
- }
- go ServiceLogList.CreateLog(c, api, logical, status, noLogStatus)
- response.OkWithMessage("后台已接收数据", c)
- }
- // @Tags loging
- // @Summary 获取log
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.GetLogListRequest true "获取log"
- // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "根据id获取coding,返回包括coding详情"
- // @Router /loging/getLogList [post]
- func (s *ApiLoging) GetLogList(c *gin.Context) {
- var paramsInfo request.GetLogListRequest
- _ = c.ShouldBindJSON(¶msInfo)
- if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- list, total, err := ServiceLogList.GetCodeLogList(c, paramsInfo.Loging, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, paramsInfo.Code)
- if err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: paramsInfo.Page,
- PageSize: paramsInfo.PageSize,
- }, "获取成功", c)
- }
- }
- // @Tags loging
- // @Summary 获取打点log
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.GetLogListRequest true "获取打点log"
- // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "获取打点log列表"
- // @Router /loging/getReportLogList [post]
- func (s *ApiLoging) GetReportPointsLogList(c *gin.Context) {
- var paramsInfo request.ReportPointsListRequest
- _ = c.ShouldBindJSON(¶msInfo)
- if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- list, total, err := ServiceReportPointsLog.GetReportPointsLogList(paramsInfo.ReportPointsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
- if err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: paramsInfo.Page,
- PageSize: paramsInfo.PageSize,
- }, "获取成功", c)
- }
- }
- // @Tags loging
- // @Summary 获取统计log
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计log"
- // @Router /loging/getStatisticsLogList [post]
- func (s *ApiLoging) GetStatisticsLogList(c *gin.Context) {
- var paramsInfo request.GetStatisticsLogRequest
- _ = c.ShouldBindJSON(¶msInfo)
- if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- list, total, err := ServiceStatisticsLog.OtherStatisticsLogList(c, paramsInfo.StatisticsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
- if err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: paramsInfo.Page,
- PageSize: paramsInfo.PageSize,
- }, "获取成功", c)
- }
- }
- // @Tags loging
- // @Summary 重置统计log
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.GetById true "根据id重置统计log"
- // @Success 200 {object} response.Response{data=interface{}} "重置统计log"
- // @Router /loging/resetStatisticsLog [post]
- func (s *ApiLoging) ResetStatisticsLog(c *gin.Context) {
- var paramsInfo request.GetById
- _ = c.ShouldBindJSON(¶msInfo)
- if err := utils.Verify(paramsInfo, utils.IdVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- current := time.Now().Format("2006-01-02")
- key := current + ":" + strconv.Itoa(paramsInfo.ID) + ":reset"
- i, err := global.GVA_REDIS.Exists(c, key).Result()
- if err != nil {
- global.GVA_LOG.Error("重置统计数据检测key失败", zap.Error(err))
- response.FailWithMessage("重置失败", c)
- return
- }
- if i != 0 {
- global.GVA_LOG.Info("还在重置中", zap.Error(err))
- response.FailWithMessage("在重置中", c)
- return
- }
- go ServiceStatisticsLog.ResetStatisticsLog(c, paramsInfo.ID, current)
- response.OkWithMessage("后台重置中", c)
- }
- // @Tags loging
- // @Summary 获取统计电脑
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑"
- // @Router /loging/getComputerStatistics [post]
- func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
- var paramsInfo request.GetStatisticsComputerRequest
- _ = c.ShouldBindJSON(¶msInfo)
- /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }*/
- list, total, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo)
- if err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: paramsInfo.Page,
- PageSize: paramsInfo.PageSize,
- }, "获取成功", c)
- }
- }
|