| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- 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/getNodeStatisticsLogList [post]
- func (s *ApiLoging) GetNodeStatisticsLogList(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.StatisticsNodeLogList(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
- // @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, 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 在线电脑
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "在线电脑"
- // @Router /loging/getOnlineComputer [post]
- func (s *ApiLoging) GetOnlineComputer(c *gin.Context) {
- var paramsInfo request.GetStatisticsComputerRequest
- _ = c.ShouldBindJSON(¶msInfo)
- list, total, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, 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 获取统计电脑数量
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
- // @Router /loging/getComputerNum [post]
- func (s *ApiLoging) GetComputerNum(c *gin.Context) {
- var paramsInfo request.GetStatisticsComputerRequest
- _ = c.ShouldBindJSON(¶msInfo)
- num := ServiceStatisticsLog.GetComputerNum(paramsInfo.CreateDate)
- response.OkWithDetailed(num, "获取成功", c)
- }
- // @Tags loging
- // @Summary 获取统计数据通过GameId
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计数据通过GameId"
- // @Router /loging/getGameIdStatistics [post]
- func (s *ApiLoging) GetGameIdStatistics(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.GameStatistics(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)
- }
- }
- // @Tags loging
- // @Summary 获取统计电脑数量
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
- // @Router /loging/computerHeartbeat [post]
- func (s *ApiLoging) ComputerHeartbeat(c *gin.Context) {
- var paramsInfo request.OnlineComputerRequest
- _ = c.ShouldBindJSON(¶msInfo)
- if paramsInfo.PcCode == "" || paramsInfo.Operator == "" {
- global.GVA_LOG.Error("参数错误!")
- response.FailWithMessage("参数错误", c)
- return
- }
- num := ServiceStatisticsLog.ComputerHeartbeat(c, paramsInfo)
- response.OkWithDetailed(num, "上报成功", c)
- }
- // @Tags loging
- // @Summary 获取统计电脑数量
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
- // @Router /loging/test [post]
- func (s *ApiLoging) ComputerTest(c *gin.Context) {
- var paramsInfo request.OnlineComputerRequest
- _ = c.ShouldBindJSON(¶msInfo)
- ServiceStatisticsLog.RegularCheckPc()
- response.OkWithDetailed("b", "上报成功", c)
- }
- // @Tags excel
- // @Summary 导出Excel
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/octet-stream
- // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
- // @Success 200
- // @Router /loging/exportExcel [post]
- func (e *ApiLoging) ExportExcel(c *gin.Context) {
- var excelInfo request.ExcelInfo
- _ = c.ShouldBindJSON(&excelInfo)
- paramsInfo := excelInfo.InfoList
- paramsInfo.PageSize = 300
- paramsInfo.Page = 1
- list, _, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
- if err != nil {
- global.GVA_LOG.Error("获取电脑数据失败!", zap.Error(err))
- response.FailWithMessage("获取电脑数据失败", c)
- return
- }
- filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
- err = ServiceStatisticsLog.ParseInfoList2Excel(list, filePath)
- if err != nil {
- global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
- response.FailWithMessage("转换Excel失败", c)
- return
- }
- c.Writer.Header().Add("success", "true")
- c.File(filePath)
- }
|