|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"log-server/global"
|
|
|
"log-server/model/log"
|
|
|
"log-server/model/log/request"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -78,7 +79,7 @@ func (s *ServiceIpLog) GetIpLogList(api log.IpLogRequest, info request.PageInfo,
|
|
|
}
|
|
|
|
|
|
//根据gameId获取ip
|
|
|
-func (s *ServiceIpLog) GetGameIpList(api log.IpLogRequest, info request.PageInfo, order string, desc bool) (apiList []log.GameIpResponse, total int64, err error) {
|
|
|
+func (s *ServiceIpLog) GetGameIpList(api log.GameIpRequest, info request.PageInfo, order string, desc bool) (apiList []log.GameIpResponse, total int64, err error) {
|
|
|
limit := info.PageSize
|
|
|
offset := info.PageSize * (info.Page - 1)
|
|
|
db := global.GVA_DB.Model(&log.IpLog{})
|
|
|
@@ -89,19 +90,30 @@ func (s *ServiceIpLog) GetGameIpList(api log.IpLogRequest, info request.PageInfo
|
|
|
startDate = api.Date[0]
|
|
|
endDate = api.Date[1]
|
|
|
}
|
|
|
+
|
|
|
+ //筛选负责人
|
|
|
+ if api.User != "" {
|
|
|
+ db = db.Where("user = ?", api.User)
|
|
|
+ }
|
|
|
+
|
|
|
+ //筛选日期
|
|
|
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)
|
|
|
+ //查找总ip上报次数
|
|
|
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 {
|
|
|
+ //查找总ip上报次数
|
|
|
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.Where("ip_log.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.Select("ip_log.create_date,ip_log.game_id,late.count as count_total, task_name, user, 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")
|
|
|
-
|
|
|
+ //拼接game_task表获取任务名称和负责人名称
|
|
|
+ db = db.Joins("left join game_task as gt on gt.task_id = ip_log.game_id")
|
|
|
db = db.Group("ip_log.game_id, ip_log.create_date")
|
|
|
//db.Select("count(*)").Count(&countTotal)
|
|
|
//db.Select("count(distinct(ip))").Count(&countDistinctIp)
|
|
|
@@ -140,6 +152,14 @@ func (s *ServiceIpLog) GetGameIpList(api log.IpLogRequest, info request.PageInfo
|
|
|
//遍历更改日期格式
|
|
|
for i, _ := range apiList {
|
|
|
apiList[i].CreateDate = apiList[i].CreateDate[:10]
|
|
|
+ err = global.GVA_DB.Model(&log.IpLog{}).Select("COUNT(1) as max_count").Where("game_id = ? and create_date = ? and status = 2", apiList[i].GameId, apiList[i].CreateDate).Group("ip").Order("max_count desc").Limit(1).Find(&apiList[i]).Error
|
|
|
+ global.GVA_DB.Model(&log.IpLog{}).Select("id,ip,count(*) ").Where("game_id = ? and create_date = ? and status = 2", apiList[i].GameId, apiList[i].CreateDate).Group("ip").Having("count(*) > 4").Count(&apiList[i].ExceedThree)
|
|
|
+ //获取平均重复率和ip重复率 并保留小数点后两位
|
|
|
+ countDistinctIp := float64(apiList[i].CountDistinctIp)
|
|
|
+ successIp := float64(apiList[i].SuccessIp)
|
|
|
+ taskCount := float64(apiList[i].TaskCount)
|
|
|
+ apiList[i].IpRepetitionRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp/ successIp) *100), 64)
|
|
|
+ apiList[i].AverageIpRepetitionRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp / taskCount) *100), 64)
|
|
|
}
|
|
|
return apiList, total, err
|
|
|
}
|
|
|
@@ -168,19 +188,31 @@ func (s *ServiceIpLog) GameIpListExcel(infoList []log.GameIpResponse, filePath s
|
|
|
excel := excelize.NewFile()
|
|
|
excel.SetSheetRow("Sheet1", "A1", &[]string{
|
|
|
"游戏id",
|
|
|
+ "负责人",
|
|
|
+ "任务名称",
|
|
|
"上报ip次数",
|
|
|
"任务完成",
|
|
|
+ "最大ip数",
|
|
|
+ "异常ip个数",
|
|
|
"成功ip次数",
|
|
|
"ip个数",
|
|
|
+ "ip重复率",
|
|
|
+ "平均重复率",
|
|
|
"日期"})
|
|
|
for i, statisticsLog := range infoList {
|
|
|
axis := fmt.Sprintf("A%d", i+2)
|
|
|
excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
|
statisticsLog.GameId,
|
|
|
+ statisticsLog.User,
|
|
|
+ statisticsLog.TaskName,
|
|
|
statisticsLog.CountTotal,
|
|
|
statisticsLog.TaskCount,
|
|
|
+ statisticsLog.MaxCount,
|
|
|
+ statisticsLog.ExceedThree,
|
|
|
statisticsLog.SuccessIp,
|
|
|
statisticsLog.CountDistinctIp,
|
|
|
+ statisticsLog.IpRepetitionRate,
|
|
|
+ statisticsLog.AverageIpRepetitionRate,
|
|
|
statisticsLog.CreateDate[:10],
|
|
|
})
|
|
|
}
|