maker пре 3 година
родитељ
комит
426ed95dd3
4 измењених фајлова са 148 додато и 8 уклоњено
  1. 50 0
      api/v1/log/log_ip.go
  2. 11 3
      model/log/log_ip.go
  3. 2 1
      router/log/log_ip.go
  4. 85 4
      service/log/log_ip.go

+ 50 - 0
api/v1/log/log_ip.go

@@ -43,6 +43,31 @@ func (s *ApiIpLog) GetIpLogList(c *gin.Context) {
 	}
 }
 
+//根据gameId分组获取ip
+func (s *ApiIpLog) GetGameIPList(c *gin.Context) {
+	var paramsInfo request.IpLogListRequest
+	_ = c.ShouldBindJSON(&paramsInfo)
+	if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	list, total, err := ServiceIpLog.GetGameIpList(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
@@ -77,3 +102,28 @@ func (s *ApiIpLog) GetIp(c *gin.Context) {
 		}, "获取成功", c)
 	}
 }
+
+//游戏id分组获取ip
+func (s *ApiIpLog) GetGameIp(c *gin.Context) {
+	var ip log2.GameIpResponse
+	_ = c.ShouldBindJSON(&ip)
+	if ip.GameId == 0 {
+		response.FailWithMessage("游戏id不能为空", c)
+		return
+	}
+
+	if ip.CreateDate == ""{
+		response.FailWithMessage("创建日期不能为空", c)
+		return
+	}
+	list, total, err := ServiceIpLog.GetGameIp(ip)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(response.PageResult{
+			List:     list,
+			Total:    total,
+		}, "获取成功", c)
+	}
+}

+ 11 - 3
model/log/log_ip.go

@@ -24,12 +24,20 @@ type IpLogRequest struct {
 }
 
 type IpLogResponse struct {
-	Ip     		string  `json:"ip"`	//模拟器ip
 	PcCode 		string 	`json:"pc_code"`	//电脑编号
 	GameId		int 	`json:"game_id"`	//游戏id
 	CreateDate  string 	`json:"create_date"` // 创建日期
-	CountTotal  int		`json:"count_total"`	//总数
-	CountDistinctIp	int	`json:"count_distinct_ip"`
+	CountTotal  int		`json:"count_total"`	//ip总上报次数
+	CountDistinctIp	int	`json:"count_distinct_ip"`	//IP个数
+}
+
+type GameIpResponse struct {
+	GameId		int 	`json:"game_id"`	//游戏id
+	CreateDate  string 	`json:"create_date"` // 创建日期
+	CountTotal  int		`json:"count_total"`	//ip总上报次数
+	SuccessIp   int 	`json:"success_ip"`		//进入游戏所上报ip个数
+	CountDistinctIp	int	`json:"count_distinct_ip"`	//ip个数
+	TaskCount	int		`json:"task_count"`			//完成任务总数
 }
 
 type QueryIpList struct {

+ 2 - 1
router/log/log_ip.go

@@ -15,7 +15,8 @@ func (e *IpLogRouter) InitIpLogRouter(Router *gin.RouterGroup) {
 	{
 		ipLogRouter.POST("getIpLogList", logApi.GetIpLogList)	//获取ip日志列表
 		ipLogRouter.POST("getIp", logApi.GetIp)	//获取ip
-
+		ipLogRouter.POST("getGameIpList", logApi.GetGameIPList)	//获取ip日志列表
+		ipLogRouter.POST("getGameIp", logApi.GetGameIp)	//获取游戏ip
 	}
 }
 

+ 85 - 4
service/log/log_ip.go

@@ -11,6 +11,7 @@ import (
 type ServiceIpLog struct {
 }
 
+//根据gameId、机器编号分组获取ip
 func (s *ServiceIpLog) GetIpLogList(api log.IpLogRequest, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
@@ -33,7 +34,7 @@ func (s *ServiceIpLog) GetIpLogList(api log.IpLogRequest, info request.PageInfo,
 		db = db.Where("ip = ?", api.Ip)
 	}
 
-	db = db.Select("create_date,ip,pc_code,game_id,count(*) as count_total,count(distinct(ip)) as count_distinct_ip")
+	db = db.Select("create_date,pc_code,game_id,count(*) as count_total,count(distinct(ip)) as count_distinct_ip")
 	db = db.Group("pc_code, game_id, create_date")
 	//db.Select("count(*)").Count(&countTotal)
 	//db.Select("count(distinct(ip))").Count(&countDistinctIp)
@@ -46,10 +47,11 @@ func (s *ServiceIpLog) GetIpLogList(api log.IpLogRequest, info request.PageInfo,
 			var OrderStr string
 			// 设置有效排序key 防止sql注入
 			// 感谢 Tom4t0 提交漏洞信息
-			orderMap := make(map[string]bool, 3)
+			orderMap := make(map[string]bool, 4)
 			orderMap["game_id"] = true
 			orderMap["count_distinct_ip"] = true
 			orderMap["count_total"] = true
+			orderMap["create_date"] = true
 			if orderMap[order] {
 				if desc {
 					OrderStr = order + " desc"
@@ -73,10 +75,89 @@ func (s *ServiceIpLog) GetIpLogList(api log.IpLogRequest, info request.PageInfo,
 	return apiList, total, err
 }
 
+//根据gameId获取ip
+func (s *ServiceIpLog) GetGameIpList(api log.IpLogRequest, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	db := global.GVA_DB.Model(&log.IpLog{})
+
+	var apiList []log.GameIpResponse
+	startDate := time.Now().Format("2006-01-02")
+	endDate := time.Now().Format("2006-01-02")
+	if len(api.Date) == 2 {
+		startDate = api.Date[0]
+		endDate = api.Date[1]
+	}
+	db = db.Where("ip_log.create_date >= ? and ip_log.create_date <= ?", startDate, endDate)
+	if api.GameId != 0 {
+		db = db.Where("ip_log.game_id = ?", api.GameId)
+		db = db.Joins("left join" + "(select count(*) as count, game_id, create_date from ip_log where game_id = ? and create_date >= ? and create_date <= ? group by game_id, create_date)" + " as late on late.game_id = ip_log.game_id and late.create_date = ip_log.create_date", api.GameId, startDate, endDate)
+	} else {
+		db = db.Joins("left join" + "(select count(*) as count, game_id, create_date from ip_log where create_date >= ? and create_date <= ? group by game_id, create_date)" + " as late on late.game_id = ip_log.game_id and late.create_date = ip_log.create_date",  startDate, endDate)
+	}
+
+	db = db.Where("status = 2")
+
+	db = db.Select("ip_log.create_date,ip_log.game_id,late.count as count_total, count(*) as success_ip , retained_complete as task_count, count(distinct(ip)) as count_distinct_ip")
+	db = db.Joins("left join game_target_complete as gtc on gtc.task_id = ip_log.game_id and gtc.create_date = ip_log.create_date")
+
+	db = db.Group("ip_log.game_id, ip_log.create_date")
+	//db.Select("count(*)").Count(&countTotal)
+	//db.Select("count(distinct(ip))").Count(&countDistinctIp)
+	err = db.Count(&total).Error
+	if err != nil {
+		return apiList, total, err
+	} else {
+		db = db.Limit(limit).Offset(offset)
+		if order != "" {
+			var OrderStr string
+			// 设置有效排序key 防止sql注入
+			// 感谢 Tom4t0 提交漏洞信息
+			orderMap := make(map[string]bool, 5)
+			//orderMap["game_id"] = true
+			orderMap["count_distinct_ip"] = true
+			orderMap["count_total"] = true
+			orderMap["success_ip"] = true
+			orderMap["task_count"] = true
+			orderMap["create_date"] = true
+			if orderMap[order] {
+				if desc {
+					OrderStr = order + " desc"
+				} else {
+					OrderStr = order
+				}
+			} else { // didn't matched any order key in `orderMap`
+				global.GVA_LOG.Error("获取失败!", zap.Error(err))
+				return apiList, total, err
+			}
+
+			err = db.Order(OrderStr).Find(&apiList).Error
+		} else {
+			err = db.Order("ip_log.id").Find(&apiList).Error
+		}
+	}
+	//遍历更改日期格式
+	for i, _ := range apiList {
+		apiList[i].CreateDate = apiList[i].CreateDate[:10]
+	}
+	return apiList, total, err
+}
+
+
+//展示ip
 func (s *ServiceIpLog) GetIp(iplog log.IpLogResponse) (list interface{}, total int64, err error) {
 	var ipList []log.QueryIpList
 	db := global.GVA_DB.Model(&log.IpLog{}).Select("ip, COUNT(1) as count").Where("game_id = ? and pc_code = ? and create_date = ?", iplog.GameId, iplog.PcCode, iplog.CreateDate).Group("ip")
-	//db.Group("ip").Count(&total)
-	err = db.Find(&ipList).Count(&total).Error
+	db.Count(&total)
+	err = db.Order("count desc").Find(&ipList).Error
+	return ipList, total, err
+}
+
+//gameID分组展示ip
+func (s *ServiceIpLog) GetGameIp(ip log.GameIpResponse) (list interface{}, total int64, err error) {
+	var ipList []log.QueryIpList
+	db := global.GVA_DB.Model(&log.IpLog{}).Select("ip, COUNT(1) as count").Where("game_id = ? and status = 2 and create_date = ?", ip.GameId, ip.CreateDate).Group("ip")
+	db.Count(&total)
+	err = db.Order("count desc").Find(&ipList).Error
 	return ipList, total, err
 }