Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	api/v1/log/loging.go
wangbin лет назад: 3
Родитель
Сommit
d606a33f42

+ 15 - 0
api/v1/card/enter.go

@@ -0,0 +1,15 @@
+package card
+
+type ApiGroup struct {
+	// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
+	// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
+	IdCardApi
+}
+
+var(
+	//gameService = service.ServiceGroupApp.TypeServiceGroup.GameChannelService
+	//gameListService = service.ServiceGroupApp.TypeServiceGroup.GameListService
+	//loginTypeService = service.ServiceGroupApp.TypeServiceGroup.LoginTypeService
+	//responsiblePersonService = service.ServiceGroupApp.TypeServiceGroup.ResponsiblePersonService
+	//accountTypeService = service.ServiceGroupApp.TypeServiceGroup.AccountTypeService
+)

+ 11 - 0
api/v1/card/id_card.go

@@ -0,0 +1,11 @@
+package card
+
+import "github.com/gin-gonic/gin"
+
+type IdCardApi struct {
+}
+
+func (a *IdCardApi) GetIdCard(c *gin.Context) {
+	c.Param("")
+}
+

+ 2 - 0
api/v1/enter.go

@@ -1,6 +1,7 @@
 package v1
 
 import (
+	"log-server/api/v1/card"
 	"log-server/api/v1/dataStatistics"
 	"log-server/api/v1/example"
 	"log-server/api/v1/fileManager"
@@ -21,6 +22,7 @@ type ApiGroup struct {
 	RentComputerApiGroup rentComputer.ApiGroup
 	DataStatisticsGroup  dataStatistics.ApiGroup
 	FileManagerGroup     fileManager.ApiGroup
+	IdCardGroup			 card.ApiGroup
 }
 
 var ApiGroupApp = new(ApiGroup)

+ 1 - 0
api/v1/log/enter.go

@@ -9,6 +9,7 @@ type GroupLog struct {
 	ApiEnvLog
 	ApiLoging
 	ApiComputer
+	ApiIpLog
 }
 
 var (

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

@@ -0,0 +1,161 @@
+package log
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"log-server/global"
+	log2 "log-server/model/log"
+	"log-server/model/log/request"
+	"log-server/model/log/response"
+	"log-server/utils"
+)
+
+type ApiIpLog struct {
+
+}
+
+// @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 *ApiIpLog) GetIpLogList(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.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)
+	}
+}
+
+//根据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
+// @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 *ApiIpLog) 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)
+	}
+}
+
+//游戏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)
+	}
+}
+
+//导出gameIp列表
+func (s *ApiIpLog) GameIpExport(c *gin.Context) {
+	var excelInfo request.ExcelIpInfo
+	_ = c.ShouldBindJSON(&excelInfo)
+	fmt.Println(excelInfo)
+	paramsInfo := excelInfo.InfoList
+	paramsInfo.PageSize = 300
+	paramsInfo.Page = 1
+	if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	list, _, err := ServiceIpLog.GetGameIpList(paramsInfo.IpLogRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败 "+err.Error(), c)
+	}
+	//var nowTime string = time.Now().Format("2006-01-02_15:04")
+	//excelInfo.FileName = nowTime + "-ip.xlsx"
+	//fmt.Println(excelInfo.FileName)
+	filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
+	err = ServiceIpLog.GameIpListExcel(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)
+}

+ 2 - 2
api/v1/log/loging.go

@@ -2,7 +2,6 @@ package log
 
 import (
 	"encoding/json"
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 	"log-server/global"
@@ -194,6 +193,8 @@ func (s *ApiLoging) GetIp(c *gin.Context) {
 	}
 }
 
+
+
 // @Tags loging
 // @Summary 获取统计节点log
 // @Security ApiKeyAuth
@@ -392,7 +393,6 @@ func (s *ApiLoging) ComputerHeartbeat(c *gin.Context) {
 		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)
 }
 

+ 3 - 0
initialize/router.go

@@ -23,6 +23,7 @@ func Routers() *gin.Engine {
 	taskRouter := router.RouterGroupApp.Task
 	uploadFileRouter := router.RouterGroupApp.UploadFile
 
+	ipLogRouter := router.RouterGroupApp.IpLog
 	typeManageRouter := router.RouterGroupApp.TypeManage
 	rentComputerRouter := router.RouterGroupApp.RentComputer
 	dataStatisticsRouter := router.RouterGroupApp.DataStatistics
@@ -65,6 +66,8 @@ func Routers() *gin.Engine {
 		typeManageRouter.InitLoginTypeRouter(PublicGroup)         //登录类型路由
 		typeManageRouter.InitResponsiblePersonRouter(PublicGroup) //负责人路由
 		typeManageRouter.InitAccountTypeRouter(PublicGroup)       //账号类型路由
+		ipLogRouter.InitIpLogRouter(PublicGroup)				  //ip日志路由
+
 		taskRouter.InitGameTaskRouter(PublicGroup)
 		uploadFileRouter.InitUploadFileRouter(PublicGroup)
 		rentComputerRouter.InitRentComputerRouter(PublicGroup)     //租机管理

+ 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 {

+ 12 - 0
model/log/request/log_statistics.go

@@ -69,6 +69,18 @@ type ExcelInfo struct {
 	} `json:"infoList"`
 }
 
+//导出ip列表
+type ExcelIpInfo struct {
+	FileName string `json:"fileName"` // 文件名
+	InfoList struct {
+		log.IpLogRequest
+		PageInfo
+		OrderKey string `json:"orderKey"` // 排序
+		Desc     bool   `json:"desc"`     // 排序方式:升序false(默认)|降序true
+	} `json:"infoList"`
+}
+
+
 type GetLogScanningCodeRequest struct {
 	LogScanningRequest
 	PageInfo

+ 5 - 0
router/card/enter.go

@@ -0,0 +1,5 @@
+package card
+
+type RouterGroup struct {
+	IdCardRouter
+}

+ 18 - 0
router/card/id_card.go

@@ -0,0 +1,18 @@
+package card
+
+import (
+	"github.com/gin-gonic/gin"
+	v1 "log-server/api/v1"
+)
+
+type IdCardRouter struct {
+}
+
+func (r *IdCardRouter) InitIdCardRouter(Router *gin.RouterGroup) {
+	IdCardRouter := Router.Group("idCard")
+	IdCardApi := v1.ApiGroupApp.IdCardGroup.IdCardApi
+	{
+		IdCardRouter.GET("getIdCard", IdCardApi.GetIdCard)
+	}
+
+}

+ 1 - 0
router/enter.go

@@ -22,6 +22,7 @@ type RouterGroup struct {
 	RentComputer   rentComputer.RouterGroup
 	DataStatistics dataStatistics.RouterGroup
 	FileManager    fileManager.RouterGroup
+	IpLog 		   log.IpLogRouter
 }
 
 var RouterGroupApp = new(RouterGroup)

+ 23 - 0
router/log/log_ip.go

@@ -0,0 +1,23 @@
+package log
+
+import (
+	"github.com/gin-gonic/gin"
+	v1 "log-server/api/v1"
+)
+
+type IpLogRouter struct {
+
+}
+
+func (e *IpLogRouter) InitIpLogRouter(Router *gin.RouterGroup) {
+	ipLogRouter := Router.Group("ipLog")
+	logApi := v1.ApiGroupApp.LogApiGroup.ApiIpLog
+	{
+		ipLogRouter.POST("getIpLogList", logApi.GetIpLogList)	//获取ip日志列表
+		ipLogRouter.POST("getIp", logApi.GetIp)	//获取ip
+		ipLogRouter.POST("getGameIpList", logApi.GetGameIPList)	//获取ip日志列表
+		ipLogRouter.POST("getGameIp", logApi.GetGameIp)	//获取游戏ip
+		ipLogRouter.POST("gameIpExport", logApi.GameIpExport)	//导出游戏ip列表
+	}
+}
+

+ 0 - 2
router/log/loging.go

@@ -28,8 +28,6 @@ func (e *LogingRouter) InitLogingRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("getLogScanningList", logApi.GetLogScanningList)
 		excelRouter.POST("computerRateExport", logApi.ComputerRateExport)
 		excelRouter.POST("computerSevenRate", logApi.ComputerSevenRate)
-		excelRouter.POST("getIpLogList", logApi.GetIpLogList)	//获取ip日志列表
-		excelRouter.POST("getIp", logApi.GetIp)	//获取ip
 
 	}
 }

+ 111 - 4
service/log/log_ip.go

@@ -1,6 +1,8 @@
 package log
 
 import (
+	"fmt"
+	"github.com/xuri/excelize/v2"
 	"go.uber.org/zap"
 	"log-server/global"
 	"log-server/model/log"
@@ -11,6 +13,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 +36,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 +49,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 +77,113 @@ 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) (apiList []log.GameIpResponse, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	db := global.GVA_DB.Model(&log.IpLog{})
+
+	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
+}
+
+//获取gameIP列表
+func (s *ServiceIpLog) GameIpListExcel(infoList []log.GameIpResponse, filePath string) error {
+	excel := excelize.NewFile()
+	excel.SetSheetRow("Sheet1", "A1", &[]string{
+		"游戏id",
+		"上报ip次数",
+		"任务完成",
+		"成功ip次数",
+		"ip个数",
+		"日期"})
+	for i, statisticsLog := range infoList {
+		axis := fmt.Sprintf("A%d", i+2)
+		excel.SetSheetRow("Sheet1", axis, &[]interface{}{
+			statisticsLog.GameId,
+			statisticsLog.CountTotal,
+			statisticsLog.TaskCount,
+			statisticsLog.SuccessIp,
+			statisticsLog.CountDistinctIp,
+			statisticsLog.CreateDate[:10],
+		})
+	}
+	err := excel.SaveAs(filePath)
+	return err
+}