瀏覽代碼

ip导出功能添加

maker 3 年之前
父節點
當前提交
d7893c38e9

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

+ 33 - 1
api/v1/log/log_ip.go

@@ -1,6 +1,7 @@
 package log
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 	"log-server/global"
@@ -103,7 +104,7 @@ func (s *ApiIpLog) GetIp(c *gin.Context) {
 	}
 }
 
-//游戏id分组获取ip
+//游戏id分组获取某天具体ip
 func (s *ApiIpLog) GetGameIp(c *gin.Context) {
 	var ip log2.GameIpResponse
 	_ = c.ShouldBindJSON(&ip)
@@ -126,4 +127,35 @@ func (s *ApiIpLog) GetGameIp(c *gin.Context) {
 			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)
 }

+ 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/log/log_ip.go

@@ -17,6 +17,7 @@ func (e *IpLogRouter) InitIpLogRouter(Router *gin.RouterGroup) {
 		ipLogRouter.POST("getIp", logApi.GetIp)	//获取ip
 		ipLogRouter.POST("getGameIpList", logApi.GetGameIPList)	//获取ip日志列表
 		ipLogRouter.POST("getGameIp", logApi.GetGameIp)	//获取游戏ip
+		ipLogRouter.POST("gameIpExport", logApi.GameIpExport)	//导出游戏ip列表
 	}
 }
 

+ 28 - 2
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"
@@ -76,12 +78,11 @@ 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) (list interface{}, total int64, err error) {
+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{})
 
-	var apiList []log.GameIpResponse
 	startDate := time.Now().Format("2006-01-02")
 	endDate := time.Now().Format("2006-01-02")
 	if len(api.Date) == 2 {
@@ -161,3 +162,28 @@ func (s *ServiceIpLog) GetGameIp(ip log.GameIpResponse) (list interface{}, 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
+}