package log import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" "go.uber.org/zap" "log-server/global" "log-server/model/common/response" log2 "log-server/model/log" "log-server/model/log/request" "log-server/service/log" loging2 "log-server/service/log/loging" "log-server/utils" "net/url" "strconv" "strings" "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 获取iplog // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body request.IpLogListRequest true "获取iplog" // @Success 200 {object} response.Response{data=log2.IpLog} "获取iplog列表" // @Router /loging/getIpLogList [post] func (s *ApiLoging) GetIpLogList(c *gin.Context) { var paramsInfo request.IpLogListRequest _ = c.ShouldBindJSON(¶msInfo) if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } list, total, err := ServiceIpLog.GetIpLogList(paramsInfo.IpLogRequest, 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 获取某天具体ip // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body log2.IpLog true "获取ip" // @Success 200 {object} response.Response{data=log2.IpResponse} "获取iplog列表" // @Router /loging/getIp [post] func (s *ApiLoging) GetIp(c *gin.Context) { var ip log2.IpLogResponse _ = c.ShouldBindJSON(&ip) if ip.GameId == 0 { response.FailWithMessage("游戏id不能为空", c) return } if ip.PcCode == "" { response.FailWithMessage("租机编号不能为空", c) return } if ip.CreateDate == "" { response.FailWithMessage("创建日期不能为空", c) return } list, total, err := ServiceIpLog.GetIp(ip) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败", c) } else { response.OkWithDetailed(response.PageResult{ List: list, Total: total, }, "获取成功", 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, paramsInfo.GamePortId) 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) global.GVA_LOG.Warn(fmt.Sprintf("电脑上报参数pcc_code=%s Operator=%s", paramsInfo.PcCode, paramsInfo.Operator)) 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 loging // @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) } // @Tags loging // @Summary 修改租机使用备注信息 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body log2.ComputerUseRemarks true "id, 租机编号, 使用者, 租机供应商" // @Success 200 {object} response.Response{msg=string} "修改租机使用备注信息" // @Router /computer/updatePcRemarks [post] func (s *ApiLoging) UpdatePcRemarks(c *gin.Context) { var paramsInfo log2.ComputerUseRemarks _ = c.ShouldBindJSON(¶msInfo) if err := utils.Verify(paramsInfo, utils.PcVerify); err != nil { response.FailWithMessage(err.Error(), c) return } if paramsInfo.PcCode == "" || paramsInfo.CreateDate == "" { response.FailWithMessage("有必要的参数未添加", c) return } if err := ServiceStatisticsLog.UpdateComputerUseLog(paramsInfo); err != nil { global.GVA_LOG.Error("修改失败!", zap.Error(err)) response.FailWithMessage(err.Error(), c) } else { response.OkWithMessage("修改成功", c) } } // @Tags loging // @Summary 上报扫码订单信息 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body request.GetCardListRequest true "扫码订单列表" // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量" // @Router /loging/getLogScanningList [post] func (s *ApiLoging) GetLogScanningList(c *gin.Context) { var paramsInfo request.GetLogScanningCodeRequest _ = c.ShouldBindJSON(¶msInfo) if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } if list, total, err := ServiceStatisticsLog.GetScanningInfoList(paramsInfo.LogScanningRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败"+err.Error(), c) } else { response.OkWithDetailed(response.PageResult{ List: list, Total: total, Page: paramsInfo.Page, PageSize: paramsInfo.PageSize, }, "获取成功", c) } } // @Tags loging // @Summary 导出Excel // @Security ApiKeyAuth // @accept application/json // @Produce application/octet-stream // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息" // @Success 200 // @Router /loging/computerRateExport [post] func (e *ApiLoging) ComputerRateExport(c *gin.Context) { var excelInfo request.ExcelInfo _ = c.ShouldBindJSON(&excelInfo) paramsInfo := excelInfo.InfoList paramsInfo.PageSize = 300 paramsInfo.Page = 1 list, _, 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) return } filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName err = ServiceStatisticsLog.ComputeRateList2Excel(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) } // @Tags loging // @Summary 七天電腦效率 // @Security ApiKeyAuth // @accept application/json // @Produce application/octet-stream // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息" // @Success 200 // @Router /loging/computerSevenRate [post] func (e *ApiLoging) ComputerSevenRate(c *gin.Context) { var paramsInfo request.GetStatisticsComputerRequest _ = c.ShouldBindJSON(¶msInfo) paramsInfo.PageSize = 300 paramsInfo.Page = 1 list, _, err := ServiceStatisticsLog.ComputerSevenStatistics(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: 1, Page: paramsInfo.Page, PageSize: paramsInfo.PageSize, }, "获取成功", c) } } // @Tags loging // @Summary 设备统计接口 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body request.GetDeviceStatisticsRequest true "设备统计接口" // @Success 200 // @Router /loging/getDeviceStatistics [post] func (e *ApiLoging) GetDeviceStatistics(c *gin.Context) { var paramsInfo request.GetDeviceStatisticsRequest _ = c.ShouldBindJSON(¶msInfo) list, total, err := ServiceStatisticsLog.GetDeviceStatistics(c, paramsInfo.DeviceStatisticsReply, 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 // @Param data body request.GetDeviceStatisticsRequest true "设备统计接口" // @Success 200 // @Router /loging/getDeviceInfoLog [post] func (e *ApiLoging) GetDeviceInfoLog(c *gin.Context) { var paramsInfo request.GetDeviceInfoLogRequest _ = c.ShouldBindJSON(¶msInfo) list, total, err := ServiceStatisticsLog.GetDeviceInfo(c, paramsInfo.DeviceLog, 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 设备id异常数据 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body request.GetDeviceStatisticsRequest true "设备id异常数据" // @Success 200 // @Router /loging/getDeviceIdErr [post] func (e *ApiLoging) GetDeviceIdErr(c *gin.Context) { var paramsInfo request.GetDeviceIdErrRequest _ = c.ShouldBindJSON(¶msInfo) list, total, err := ServiceStatisticsLog.GetDeviceIdErr(c, paramsInfo.ScriptDeviceErr, 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 导出Excel // @Security ApiKeyAuth // @accept application/json // @Produce application/octet-stream // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息" // @Success 200 // @Router /loging/deviceErrRateExcel [post] func (e *ApiLoging) DeviceErrRateExcel(c *gin.Context) { var excelInfo request.ExcelDeviceErrRate _ = c.ShouldBindJSON(&excelInfo) paramsInfo := excelInfo.InfoList paramsInfo.PageSize = 1000 paramsInfo.Page = 1 list, _, err := ServiceStatisticsLog.GetDeviceStatistics(c, paramsInfo.DeviceStatisticsReply, 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.DeviceErrRateExcel(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) } // @Tags loging // @Summary 设备异常数据接口 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body log2.DeviceLog true "设备异常数据接口" // @Success 200 // @Router /loging/getErrDeviceLog [post] func (e *ApiLoging) GetErrDeviceLog(c *gin.Context) { var paramsInfo log2.DeviceLog _ = c.ShouldBindJSON(¶msInfo) list, err := ServiceStatisticsLog.GetDeviceContrastInfo(c, paramsInfo) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败", c) } else { response.OkWithDetailed(response.PageResult{ List: list, }, "获取成功", c) } } // @Tags loging // @Summary 获取无忧token // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body log2.DeviceLog true "设备异常数据接口" // @Success 200 // @Router /loging/getWuYToken [Get] func (e *ApiLoging) GetWuYToken(c *gin.Context) { type Data struct { Token string `json:"token"` } var data Data key := fmt.Sprintf("%s:wuYToken", time.Now().Format("2006-01-02")) t, _ := global.GVA_REDIS.Get(c, key).Result() if t != "" { data.Token = t response.OkWithDetailed(data, "获取成功", c) return } header := map[string]string{"Content-Type": "application/x-www-form-urlencoded"} var ( params = url.Values{} ) params.Set("username", "18408246387") params.Set("password", "der123456") params.Set("source", "3") params.Set("auth", "none") requestData := params.Encode() reqUrl := "https://user.wuyouip.com/Sign/_In" reqs, err := utils.Request("POST", reqUrl, strings.NewReader(requestData), header, nil) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败", c) return } token := reqs.Cookies()[1].Value if token != "" { token = "token=" + token global.GVA_REDIS.Set(c, key, token, time.Hour*15) } data.Token = token response.OkWithDetailed(data, "获取成功", c) return }