wangbin лет назад: 3
Родитель
Сommit
bc667f28b9

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

@@ -130,6 +130,34 @@ func (s *ApiLoging) GetReportPointsLogList(c *gin.Context) {
 }
 }
 
 
 // @Tags loging
 // @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(&paramsInfo)
+	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
 // @Summary 获取统计log
 // @Security ApiKeyAuth
 // @Security ApiKeyAuth
 // @accept application/json
 // @accept application/json
@@ -203,7 +231,31 @@ func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
 		response.FailWithMessage(err.Error(), c)
 		response.FailWithMessage(err.Error(), c)
 		return
 		return
 	}*/
 	}*/
-	list, total, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo)
+	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(&paramsInfo)
+	list, total, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
 	if err != nil {
 	if err != nil {
 		global.GVA_LOG.Error("获取失败!", zap.Error(err))
 		global.GVA_LOG.Error("获取失败!", zap.Error(err))
 		response.FailWithMessage("获取失败", c)
 		response.FailWithMessage("获取失败", c)
@@ -227,7 +279,7 @@ func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
 func (s *ApiLoging) GetComputerNum(c *gin.Context) {
 func (s *ApiLoging) GetComputerNum(c *gin.Context) {
 	var paramsInfo request.GetStatisticsComputerRequest
 	var paramsInfo request.GetStatisticsComputerRequest
 	_ = c.ShouldBindJSON(&paramsInfo)
 	_ = c.ShouldBindJSON(&paramsInfo)
-	num := ServiceStatisticsLog.GetComputerNum()
+	num := ServiceStatisticsLog.GetComputerNum(paramsInfo.CreateDate)
 	response.OkWithDetailed(num, "获取成功", c)
 	response.OkWithDetailed(num, "获取成功", c)
 }
 }
 
 
@@ -258,3 +310,36 @@ func (s *ApiLoging) GetGameIdStatistics(c *gin.Context) {
 		}, "获取成功", c)
 		}, "获取成功", 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(&paramsInfo)
+	if paramsInfo.PcCode == "" || paramsInfo.Operator == "" {
+		global.GVA_LOG.Error("参数错误!")
+		response.FailWithMessage("参数错误", c)
+		return
+	}
+	num := ServiceStatisticsLog.ComputerHeartbeat(c, paramsInfo)
+	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(&paramsInfo)
+	ServiceStatisticsLog.CreateComputerStatisticsData()
+	response.OkWithDetailed(0, "上报成功", c)
+}

+ 10 - 10
initialize/timer.go

@@ -43,16 +43,16 @@ func Timer() {
 		fmt.Println("add CreateComputerStatisticsData timer error:", err)
 		fmt.Println("add CreateComputerStatisticsData timer error:", err)
 	}
 	}
 
 
-	_, err = global.GVA_Timer.AddTaskByFunc("TodayCreateStatisticsGameInfoLog", "2 0/4 6-23 * * * ", serviceStatisticsLog.TodayCreateStatisticsGameInfoLog)
-	if err != nil {
-		fmt.Println("add TodayCreateStatisticsGameInfoLog timer error:", err)
-	}
-
-	_, err = global.GVA_Timer.AddTaskByFunc("TodayCreateStatisticsGameInfoLog", "2 0/3 6-23 * * * ", serviceStatisticsLog.TaskStatisticsDataCache)
-	if err != nil {
-		fmt.Println("add TodayCreateStatisticsGameInfoLog timer error:", err)
-	}
-
+	//_, err = global.GVA_Timer.AddTaskByFunc("TodayCreateStatisticsGameInfoLog", "2 0/8 6-23 * * * ", serviceStatisticsLog.TodayCreateStatisticsGameInfoLog)
+	//if err != nil {
+	//	fmt.Println("add TodayCreateStatisticsGameInfoLog timer error:", err)
+	//}
+	//
+	//_, err = global.GVA_Timer.AddTaskByFunc("TodayCreateStatisticsGameInfoLog", "2 0/3 6-23 * * * ", serviceStatisticsLog.TaskStatisticsDataCache)
+	//if err != nil {
+	//	fmt.Println("add TodayCreateStatisticsGameInfoLog timer error:", err)
+	//}
+	//
 	//_, err = global.GVA_Timer.AddTaskByFunc("createFailLog", "2 0/5 6-23 * * * ", ServiceLogList.CreateFailLog)
 	//_, err = global.GVA_Timer.AddTaskByFunc("createFailLog", "2 0/5 6-23 * * * ", ServiceLogList.CreateFailLog)
 	//if err != nil {
 	//if err != nil {
 	//	fmt.Println("everyDayResetStatisticsCache timer error:", err)
 	//	fmt.Println("everyDayResetStatisticsCache timer error:", err)

+ 66 - 59
model/log/log_statistics.go

@@ -1,65 +1,72 @@
 package log
 package log
 
 
 type StatisticsLog struct {
 type StatisticsLog struct {
-	Id                  uint   `json:"id"`
-	GameId              int    `json:"game_id"`
-	PullAccountOk       int    `json:"pull_account_ok"`
-	PullAccountFail     int    `json:"pull_account_fail"`
-	StartProxyFail      int    `json:"start_proxy_fail"`
-	StartProxyOk        int    `json:"start_proxy_ok"`
-	SimulatorStartFail  int    `json:"simulator_start_fail"`
-	SimulatorStartOk    int    `json:"simulator_start_ok"`
-	NetworkCheckFail    int    `json:"network_check_fail"`
-	NetworkCheckOk      int    `json:"network_check_ok"`
-	EnterMainFail       int    `json:"enter_main_fail"`
-	EnterMainOk         int    `json:"enter_main_ok"`
-	ScriptStartOk       int    `json:"script_start_ok"`
-	ScriptStartFail     int    `json:"script_start_fail"`
-	GameStartOk         int    `json:"game_start_ok"`
-	GameStartFail       int    `json:"game_start_fail"`
-	EnterStartGame      int    `json:"enter_start_game"`
-	EnterLogin          int    `json:"enter_login"`
-	EnterAuthentication int    `json:"enter_authentication"`
-	EnterRole           int    `json:"enter_role"`
-	EnterConstituency   int    `json:"enter_constituency"`
-	EnterGame           int    `json:"enter_game"`
-	EnterMain           int    `json:"enter_main"`
-	EnterFee            int    `json:"enter_fee"`
-	LoginOk             int    `json:"login_ok"`
-	LoginFail           int    `json:"login_fail"`
-	XmyLoginOk          int    `json:"xmy_login_ok"`
-	XmyLoginFail        int    `json:"xmy_login_ok"`
-	WxLoginOk           int    `json:"wx_login_ok"`
-	WxLoginFail         int    `json:"wx_login_fail"`
-	MzLoginOk           int    `json:"mz_login_ok"`
-	MzLoginFail         int    `json:"mz_login_fail"`
-	EnterGameFail       int    `json:"enter_game_fail"`
-	EnterGameOk         int    `json:"enter_game_ok"`
-	FeeOk               int    `json:"fee_ok"`
-	FeeFail             int    `json:"fee_fail"`
-	ConstituencyOk      int    `json:"constituency_ok"`
-	ConstituencyFail    int    `json:"constituency_fail"`
-	AuthenticationFail  int    `json:"authentication_fail"`
-	AuthenticationOk    int    `json:"authentication_ok"`
-	HasRole             int    `json:"has_role"`
-	NotRole             int    `json:"not_role"`
-	BanOff              int    `json:"ban_off"`
-	Freeze              int    `json:"freeze"`
-	Type                int    `json:"type"` // 0新增1活跃
-	CreateDate          string `json:"create_date"`
-	CreateTime          string `json:"create_time"` // 创建时间
-	GameName            string `json:"game_name"`
-	PayComplete         int    `json:"pay_complete"`
-	TargetNum           int    `json:"target_num"`          // 目标数
-	TargetCompleteNum   int    `json:"target_complete_num"` // 目标完成数
-	PayTarget           int    `json:"pay_target"`          // 目标付费
-	OrderSuccessRate    string `json:"order_success_rate"`  // 订单成功率
-	IssuedAccount       int    `json:"issued_account"`
-	NewScanningCode     int    `json:"new_scanning_code"`
-	OrderSuccess        int    `json:"order_success"`        //小绵羊成功付费数
-	OrderCreate         int    `json:"order_create"`         // 小绵羊创建付费订单数
-	RetainedAccountNum  int    `json:"retained_account_num"` // 留存账号
-	FeeAccountNum       int    `json:"fee_account_num"`      // 付费账号
+	Id                    uint    `json:"id"`
+	GameId                int     `json:"game_id"`
+	PullAccountOk         int     `json:"pull_account_ok"`
+	PullAccountFail       int     `json:"pull_account_fail"`
+	StartProxyFail        int     `json:"start_proxy_fail"`
+	StartProxyOk          int     `json:"start_proxy_ok"`
+	SimulatorStartFail    int     `json:"simulator_start_fail"`
+	SimulatorStartOk      int     `json:"simulator_start_ok"`
+	NetworkCheckFail      int     `json:"network_check_fail"`
+	NetworkCheckOk        int     `json:"network_check_ok"`
+	EnterMainFail         int     `json:"enter_main_fail"`
+	EnterMainOk           int     `json:"enter_main_ok"`
+	ScriptStartOk         int     `json:"script_start_ok"`
+	ScriptStartFail       int     `json:"script_start_fail"`
+	GameStartOk           int     `json:"game_start_ok"`
+	GameStartFail         int     `json:"game_start_fail"`
+	EnterStartGame        int     `json:"enter_start_game"`
+	EnterLogin            int     `json:"enter_login"`
+	EnterAuthentication   int     `json:"enter_authentication"`
+	EnterRole             int     `json:"enter_role"`
+	EnterConstituency     int     `json:"enter_constituency"`
+	EnterGame             int     `json:"enter_game"`
+	EnterMain             int     `json:"enter_main"`
+	EnterFee              int     `json:"enter_fee"`
+	LoginOk               int     `json:"login_ok"`
+	LoginFail             int     `json:"login_fail"`
+	XmyLoginOk            int     `json:"xmy_login_ok"`
+	XmyLoginFail          int     `json:"xmy_login_ok"`
+	WxLoginOk             int     `json:"wx_login_ok"`
+	WxLoginFail           int     `json:"wx_login_fail"`
+	MzLoginOk             int     `json:"mz_login_ok"`
+	MzLoginFail           int     `json:"mz_login_fail"`
+	EnterGameFail         int     `json:"enter_game_fail"`
+	EnterGameOk           int     `json:"enter_game_ok"`
+	FeeOk                 int     `json:"fee_ok"`
+	FeeFail               int     `json:"fee_fail"`
+	ConstituencyOk        int     `json:"constituency_ok"`
+	ConstituencyFail      int     `json:"constituency_fail"`
+	AuthenticationFail    int     `json:"authentication_fail"`
+	AuthenticationOk      int     `json:"authentication_ok"`
+	HasRole               int     `json:"has_role"`
+	NotRole               int     `json:"not_role"`
+	BanOff                int     `json:"ban_off"`
+	Freeze                int     `json:"freeze"`
+	Type                  int     `json:"type"` // 0新增1活跃
+	CreateDate            string  `json:"create_date"`
+	CreateTime            string  `json:"create_time"` // 创建时间
+	GameName              string  `json:"game_name"`
+	PayComplete           int     `json:"pay_complete"`
+	TargetNum             int     `json:"target_num"`          // 目标数
+	TargetCompleteNum     int     `json:"target_complete_num"` // 目标完成数
+	PayTarget             int     `json:"pay_target"`          // 目标付费
+	OrderSuccessRate      string  `json:"order_success_rate"`  // 订单成功率
+	IssuedAccount         int     `json:"issued_account"`
+	NewScanningCode       int     `json:"new_scanning_code"`
+	OrderSuccess          int     `json:"order_success"`        //小绵羊成功付费数
+	OrderCreate           int     `json:"order_create"`         // 小绵羊创建付费订单数
+	RetainedAccountNum    int     `json:"retained_account_num"` // 留存账号
+	FeeAccountNum         int     `json:"fee_account_num"`      // 付费账号
+	PullSuccessRate       float64 `json:"pull_success_rate"`
+	StartSuccessRate      float64 `json:"start_success_rate"`
+	MainSuccessRate       float64 `json:"main_success_rate"`
+	TaskSuccessRate       float64 `json:"task_success_rate"`
+	ScanningSuccessRate   float64 `json:"scanning_success_rate"`
+	LocalOrderSuccessRate float64 `json:"local_order_success_rate"`
+	Operator              string  `json:"operator"`
 }
 }
 
 
 func (StatisticsLog) TableName() string {
 func (StatisticsLog) TableName() string {

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

@@ -16,6 +16,11 @@ type GetStatisticsComputerRequest struct {
 	Desc     bool   `json:"desc"`     // 排序方式:升序false(默认)|降序true
 	Desc     bool   `json:"desc"`     // 排序方式:升序false(默认)|降序true
 }
 }
 
 
+type OnlineComputerRequest struct {
+	PcCode   string `json:"pc_code"`
+	Operator string `json:"operator"`
+}
+
 type TaskStatistics struct {
 type TaskStatistics struct {
 	GameId                int    `json:"game_id"`
 	GameId                int    `json:"game_id"`
 	GameName              string `json:"game_name"`
 	GameName              string `json:"game_name"`
@@ -38,6 +43,7 @@ type TaskStatistics struct {
 	RetainedScanningCode  int    `json:"retained_scanning_code"`
 	RetainedScanningCode  int    `json:"retained_scanning_code"`
 	RetainedAccountNum    int    `json:"retained_account_num"` // 留存账号
 	RetainedAccountNum    int    `json:"retained_account_num"` // 留存账号
 	FeeAccountNum         int    `json:"fee_account_num"`      // 付费账号
 	FeeAccountNum         int    `json:"fee_account_num"`      // 付费账号
+	Remark                string `json:"remark"`               //负责人
 }
 }
 
 
 type TaskData struct {
 type TaskData struct {

+ 4 - 1
router/log/loging.go

@@ -16,9 +16,12 @@ func (e *LogingRouter) InitLogingRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("getLogList", logApi.GetLogList) // 上报日志
 		excelRouter.POST("getLogList", logApi.GetLogList) // 上报日志
 		excelRouter.POST("getReportLogList", logApi.GetReportPointsLogList)
 		excelRouter.POST("getReportLogList", logApi.GetReportPointsLogList)
 		excelRouter.POST("getStatisticsLogList", logApi.GetStatisticsLogList)
 		excelRouter.POST("getStatisticsLogList", logApi.GetStatisticsLogList)
-		excelRouter.POST("resetStatisticsLog", logApi.ResetStatisticsLog)
+		excelRouter.POST("getNodeStatisticsLogList", logApi.GetNodeStatisticsLogList)
 		excelRouter.POST("getComputerStatistics", logApi.GetComputerStatistics)
 		excelRouter.POST("getComputerStatistics", logApi.GetComputerStatistics)
+		excelRouter.POST("getOnlineComputer", logApi.GetOnlineComputer)
 		excelRouter.POST("getGameIdStatistics", logApi.GetGameIdStatistics)
 		excelRouter.POST("getGameIdStatistics", logApi.GetGameIdStatistics)
 		excelRouter.POST("getComputerNum", logApi.GetComputerNum)
 		excelRouter.POST("getComputerNum", logApi.GetComputerNum)
+		excelRouter.POST("computerHeartbeat", logApi.ComputerHeartbeat)
+		excelRouter.POST("test", logApi.ComputerTest)
 	}
 	}
 }
 }

+ 11 - 0
service/cache/cache.go

@@ -75,6 +75,17 @@ func (s *Cache) GetCacheNum(ctx context.Context, key string) (num int, err error
 	return num, err
 	return num, err
 }
 }
 
 
+func (s *Cache) GetCacheStr(ctx context.Context, key string) (str string, err error) {
+	str, err = global.GVA_REDIS.Get(ctx, key).Result()
+	if err != nil {
+		if err == redis.Nil {
+			return "", nil
+		}
+		return "", err
+	}
+	return str, err
+}
+
 func (s *Cache) ExistsKey(ctx context.Context, key string) (bool, error) {
 func (s *Cache) ExistsKey(ctx context.Context, key string) (bool, error) {
 	isNull, err := global.GVA_REDIS.Exists(ctx, key).Result()
 	isNull, err := global.GVA_REDIS.Exists(ctx, key).Result()
 	if err != nil {
 	if err != nil {

+ 233 - 23
service/log/log_statistics.go

@@ -82,6 +82,7 @@ func (s *ServiceStatisticsLog) CreateStatisticsLog() {
 
 
 func (s *ServiceStatisticsLog) TodayCreateStatisticsGameInfoLog() {
 func (s *ServiceStatisticsLog) TodayCreateStatisticsGameInfoLog() {
 	date := s.LogicalLog.CurrentDate()
 	date := s.LogicalLog.CurrentDate()
+	ctx := context.Background()
 	gameMps, err := s.LogicalLog.GetGameCache(context.Background(), date)
 	gameMps, err := s.LogicalLog.GetGameCache(context.Background(), date)
 	if err != nil {
 	if err != nil {
 		global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
 		global.GVA_LOG.Error("获取redis game list失败!", zap.Error(err))
@@ -93,17 +94,19 @@ func (s *ServiceStatisticsLog) TodayCreateStatisticsGameInfoLog() {
 	}
 	}
 	var statisticsLogs []*log.StatisticsLog
 	var statisticsLogs []*log.StatisticsLog
 	for gameId, _ := range gameMps {
 	for gameId, _ := range gameMps {
-		gameIdInt, _ := strconv.Atoi(gameId)
-		if !errors.Is(global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", gameIdInt).First(&log.StatisticsLog{}).Error, gorm.ErrRecordNotFound) {
-			// 已存在,跳过
-			continue
-		}
 		for _, tt := range TaskType {
 		for _, tt := range TaskType {
-			statisticsLog := new(log.StatisticsLog)
-			statisticsLog.GameId = gameIdInt
-			statisticsLog.Type = tt
-			statisticsLog.CreateTime = time.Now().Format("2006-01-02 15:04:05")
-			statisticsLog.CreateDate = date
+			gameIdInt, _ := strconv.Atoi(gameId)
+			statisticsLogNew := new(log.StatisticsLog)
+			statisticsLog := s.statisticsData(ctx, gameIdInt, tt, date, statisticsLogNew)
+			if !errors.Is(global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", gameIdInt).First(&log.StatisticsLog{}).Error, gorm.ErrRecordNotFound) {
+				// 已存在,跳过
+				err = global.GVA_DB.Where("game_id", gameIdInt).Where("create_date = ?", date).Where("type = ?", tt).Updates(statisticsLog).Error
+				if err != nil {
+					global.GVA_LOG.Error("update StatisticsLogs失败!", zap.Error(err))
+					continue
+				}
+				continue
+			}
 			statisticsLogs = append(statisticsLogs, statisticsLog)
 			statisticsLogs = append(statisticsLogs, statisticsLog)
 			if len(statisticsLogs) == 100 {
 			if len(statisticsLogs) == 100 {
 				err = global.GVA_DB.Create(statisticsLogs).Error
 				err = global.GVA_DB.Create(statisticsLogs).Error
@@ -267,25 +270,103 @@ func (s *ServiceStatisticsLog) statisticsData(ctx context.Context, gameIdInt, tt
 		statisticsLog.IssuedAccount = taskStatistics.RetainedPullAccount
 		statisticsLog.IssuedAccount = taskStatistics.RetainedPullAccount
 		statisticsLog.TargetNum = taskStatistics.RetainedTarget
 		statisticsLog.TargetNum = taskStatistics.RetainedTarget
 		statisticsLog.TargetCompleteNum = taskStatistics.RetainedComplete
 		statisticsLog.TargetCompleteNum = taskStatistics.RetainedComplete
+		statisticsLog.ScanningSuccessRate = 0
 	} else {
 	} else {
 		statisticsLog.NotRole = 0
 		statisticsLog.NotRole = 0
 		statisticsLog.HasRole, _ = s.LogicalLog.CodeLogGetNum(ctx, date, gameIdInt, "4609902", loging2.NoLogStatus, tt)
 		statisticsLog.HasRole, _ = s.LogicalLog.CodeLogGetNum(ctx, date, gameIdInt, "4609902", loging2.NoLogStatus, tt)
 		statisticsLog.IssuedAccount = taskStatistics.NewPullAccount
 		statisticsLog.IssuedAccount = taskStatistics.NewPullAccount
 		statisticsLog.TargetCompleteNum = taskStatistics.NewComplete
 		statisticsLog.TargetCompleteNum = taskStatistics.NewComplete
 		statisticsLog.TargetNum = taskStatistics.NewTarget
 		statisticsLog.TargetNum = taskStatistics.NewTarget
+		statisticsLog.NewScanningCode = taskStatistics.NewScanningCode
+		if statisticsLog.NewScanningCode != 0 {
+			statisticsLog.ScanningSuccessRate = float64(statisticsLog.TargetNum) / float64(statisticsLog.NewScanningCode) * 100
+		}
 	}
 	}
-	statisticsLog.NewScanningCode = taskStatistics.NewScanningCode
 	statisticsLog.PayComplete = taskStatistics.PayComplete
 	statisticsLog.PayComplete = taskStatistics.PayComplete
 	statisticsLog.PayTarget = taskStatistics.PayTarget
 	statisticsLog.PayTarget = taskStatistics.PayTarget
 	statisticsLog.OrderCreate = taskStatistics.OrderCreate
 	statisticsLog.OrderCreate = taskStatistics.OrderCreate
 	statisticsLog.OrderSuccess = taskStatistics.OrderSuccess
 	statisticsLog.OrderSuccess = taskStatistics.OrderSuccess
 	statisticsLog.RetainedAccountNum = taskStatistics.RetainedAccountNum
 	statisticsLog.RetainedAccountNum = taskStatistics.RetainedAccountNum
 	statisticsLog.FeeAccountNum = taskStatistics.FeeAccountNum
 	statisticsLog.FeeAccountNum = taskStatistics.FeeAccountNum
+	statisticsLog.Operator = taskStatistics.Remark
+	statisticsLog.GameName = taskStatistics.GameName
+	if statisticsLog.IssuedAccount != 0 {
+		statisticsLog.PullSuccessRate = float64(statisticsLog.PullAccountOk) / float64(statisticsLog.IssuedAccount) * 100
+	}
+	if statisticsLog.PullAccountOk != 0 {
+		statisticsLog.StartSuccessRate = float64(statisticsLog.SimulatorStartOk) / float64(statisticsLog.PullAccountOk) * 100
+	}
+	if statisticsLog.GameStartOk != 0 {
+		statisticsLog.MainSuccessRate = float64(statisticsLog.EnterMain) / float64(statisticsLog.GameStartOk) * 100
+	}
+	if statisticsLog.TargetNum != 0 {
+		statisticsLog.TaskSuccessRate = float64(statisticsLog.EnterMain) / float64(statisticsLog.TargetNum) * 100
+	}
+	if statisticsLog.OrderCreate != 0 {
+		statisticsLog.LocalOrderSuccessRate = float64(statisticsLog.FeeOk) / float64(statisticsLog.OrderCreate) * 100
+	}
+
 	return statisticsLog
 	return statisticsLog
 }
 }
 
 
 func (s *ServiceStatisticsLog) OtherStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
 func (s *ServiceStatisticsLog) OtherStatisticsLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
 	date := api.CreateDate
 	date := api.CreateDate
+	if date == "" {
+		date = s.CurrentDate()
+	}
+
+	db := global.GVA_DB.Model(&log.StatisticsLog{})
+	if api.GameId != 0 {
+		db = db.Where("game_id = ?", api.GameId)
+	}
+	db = db.Where("create_date = ?", date)
+	var total int64
+	err := db.Count(&total).Error
+	if err != nil {
+		return nil, 0, err
+	}
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	var statisticsLogs []*log.StatisticsLog
+	db = db.Limit(limit).Offset(offset)
+	if order != "" {
+		var OrderStr string
+		// 设置有效排序key 防止sql注入
+		// 感谢 Tom4t0 提交漏洞信息
+		orderMap := make(map[string]bool, 7)
+		orderMap["pull_success_rate"] = true
+		orderMap["start_success_rate"] = true
+		orderMap["main_success_rate"] = true
+		orderMap["task_success_rate"] = true
+		orderMap["scanning_success_rate"] = true
+		orderMap["local_order_success_rate"] = true
+		orderMap["game_id"] = 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 statisticsLogs, total, err
+		}
+
+		err = db.Order(OrderStr).Find(&statisticsLogs).Error
+	} else {
+		err = db.Order("id").Find(&statisticsLogs).Error
+	}
+	if err != nil {
+		return nil, 0, err
+	}
+	for _, statisticsLog := range statisticsLogs {
+		statisticsLog.CreateDate = statisticsLog.CreateDate[:10]
+	}
+	return statisticsLogs, total, err
+}
+
+func (s *ServiceStatisticsLog) StatisticsNodeLogList(ctx context.Context, api log.StatisticsLog, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
+	date := api.CreateDate
 	if date == "" || date == s.CurrentDate() {
 	if date == "" || date == s.CurrentDate() {
 		apilist, total, err := s.TodayStatisticsLogList(ctx, api, info)
 		apilist, total, err := s.TodayStatisticsLogList(ctx, api, info)
 		return apilist, total, err
 		return apilist, total, err
@@ -416,10 +497,9 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 	if len(codeMps) == 0 {
 	if len(codeMps) == 0 {
 		return
 		return
 	}
 	}
-	// 统计运行的电脑台数
-	computerNumKey := fmt.Sprintf(ComputerNum, s.CurrentDate())
-	global.GVA_REDIS.Set(ctx, computerNumKey, len(codeMps), 24*time.Hour)
 	key := fmt.Sprintf(taskStatistics, s.LogicalLog.CurrentDate())
 	key := fmt.Sprintf(taskStatistics, s.LogicalLog.CurrentDate())
+	onlineComputerMpa, _ := s.LogicalLog.GetOnlineComputerNumCache(ctx, s.LogicalLog.CurrentDate())
+	fmt.Println(onlineComputerMpa)
 	var csReplys []*log.LogComputer
 	var csReplys []*log.LogComputer
 	for code, r := range codeMps {
 	for code, r := range codeMps {
 		accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
 		accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
@@ -434,8 +514,12 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 		if err != nil {
 		if err != nil {
 			continue
 			continue
 		}
 		}
+
 		for gameId, num := range accountMps {
 		for gameId, num := range accountMps {
 			csReply := new(log.LogComputer)
 			csReply := new(log.LogComputer)
+			if _, ok := onlineComputerMpa[csReply.PcCode]; ok {
+				delete(onlineComputerMpa, csReply.PcCode)
+			}
 			csReply.PcCode = code
 			csReply.PcCode = code
 			csReply.Operator = r
 			csReply.Operator = r
 			data, err := global.GVA_REDIS.HGet(ctx, key, gameId).Result()
 			data, err := global.GVA_REDIS.HGet(ctx, key, gameId).Result()
@@ -461,6 +545,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 			csReply.GameFeeRate = s.GetStatisticsFeeRate(ctx, csReply.GameId)
 			csReply.GameFeeRate = s.GetStatisticsFeeRate(ctx, csReply.GameId)
 			runTime := time.Now().Hour() + 1 - csReply.ComputerFreeTime
 			runTime := time.Now().Hour() + 1 - csReply.ComputerFreeTime
 			csReply.ComputerHourAverageRate = csReply.TaskSuccessNum / runTime
 			csReply.ComputerHourAverageRate = csReply.TaskSuccessNum / runTime
+			global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Where("game_id = ?", 0).Delete(&log.LogComputer{})
 			if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
 			if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
 				// 已存在,更新
 				// 已存在,更新
 				mp := make(map[string]interface{})
 				mp := make(map[string]interface{})
@@ -483,7 +568,6 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 			}
 			}
 			csReplys = append(csReplys, csReply)
 			csReplys = append(csReplys, csReply)
 		}
 		}
-
 	}
 	}
 	if len(csReplys) != 0 {
 	if len(csReplys) != 0 {
 		err = global.GVA_DB.Table("log_computer").Create(csReplys).Error
 		err = global.GVA_DB.Table("log_computer").Create(csReplys).Error
@@ -491,10 +575,31 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 			global.GVA_LOG.Error("更新数据失败", zap.Error(err))
 			global.GVA_LOG.Error("更新数据失败", zap.Error(err))
 		}
 		}
 	}
 	}
+	// 在线电脑没有跑数据记录
+	if len(onlineComputerMpa) != 0 {
+		var onlineComputer []*log.LogComputer
+		for pcCode, op := range onlineComputerMpa {
+			csReply := new(log.LogComputer)
+			csReply.PcCode = pcCode
+			csReply.Operator = op
+			csReply.CreateDate = time.Now().Format("2006-01-02")
+			if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
+				continue
+			}
+			onlineComputer = append(onlineComputer, csReply)
+		}
+		if len(onlineComputer) != 0 {
+			err = global.GVA_DB.Table("log_computer").Create(onlineComputer).Error
+			if err != nil {
+				global.GVA_LOG.Error("更新数据失败", zap.Error(err))
+			}
+		}
+	}
+
 	return
 	return
 }
 }
 
 
-func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo) (interface{}, int64, error) {
+func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
 	date := api.CreateDate
 	date := api.CreateDate
 	isCurrentDate := false
 	isCurrentDate := false
 	if date == "" {
 	if date == "" {
@@ -521,7 +626,28 @@ func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.L
 	offset := info.PageSize * (info.Page - 1)
 	offset := info.PageSize * (info.Page - 1)
 	var statisticsLogs []*log.LogComputer
 	var statisticsLogs []*log.LogComputer
 	db = db.Limit(limit).Offset(offset)
 	db = db.Limit(limit).Offset(offset)
-	err = db.Order("id").Find(&statisticsLogs).Error
+	if order != "" {
+		var OrderStr string
+		// 设置有效排序key 防止sql注入
+		// 感谢 Tom4t0 提交漏洞信息
+		orderMap := make(map[string]bool, 3)
+		orderMap["pc_code"] = true
+		orderMap["game_id"] = true
+		orderMap["operator"] = 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 statisticsLogs, total, err
+		}
+		err = db.Order(OrderStr).Find(&statisticsLogs).Error
+	} else {
+		err = db.Order("id").Find(&statisticsLogs).Error
+	}
 	if err != nil {
 	if err != nil {
 		return nil, 0, err
 		return nil, 0, err
 	}
 	}
@@ -563,6 +689,74 @@ func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.L
 	return statisticsLogsComputer, total, err
 	return statisticsLogsComputer, total, err
 }
 }
 
 
+// 在线电脑
+func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
+	date := api.CreateDate
+	if date == "" {
+		date = s.CurrentDate()
+	}
+	db := global.GVA_DB.Model(&log.LogComputer{})
+	var total int64
+	db = db.Where("create_date = ?", date)
+	if api.Operator != "" {
+		db = db.Where("operator = ?", api.Operator)
+	}
+	if api.PcCode != "" {
+		db = db.Where("pc_code = ?", api.PcCode)
+	}
+	db = db.Group("pc_code")
+	err := db.Count(&total).Error
+	if err != nil {
+		return nil, 0, err
+	}
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	var statisticsLogs []*log.LogComputer
+	db = db.Limit(limit).Offset(offset)
+	if order != "" {
+		var OrderStr string
+		// 设置有效排序key 防止sql注入
+		// 感谢 Tom4t0 提交漏洞信息
+		orderMap := make(map[string]bool, 3)
+		orderMap["pc_code"] = true
+		orderMap["operator"] = 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 statisticsLogs, total, err
+		}
+		err = db.Order(OrderStr).Find(&statisticsLogs).Error
+	} else {
+		err = db.Order("id").Find(&statisticsLogs).Error
+	}
+	if err != nil {
+		return nil, 0, err
+	}
+	var statisticsLogsComputer []*response.ComputerStatisticsReply1
+
+	for _, statisticsLog := range statisticsLogs {
+		statisticsLogComputer := new(response.ComputerStatisticsReply1)
+		statisticsLogComputer.PcCode = statisticsLog.PcCode
+		statisticsLogComputer.Operator = statisticsLog.Operator
+		statisticsLogComputer.CreateDate = statisticsLog.CreateDate[:10]
+		statisticsLogComputer.GameId = statisticsLog.GameId
+		statisticsLogComputer.PullAccountNum = statisticsLog.PullAccountNum
+		statisticsLogComputer.TaskSuccessNum = statisticsLog.TaskSuccessNum
+		statisticsLogComputer.TargetNum = statisticsLog.TargetNum
+		statisticsLogComputer.ComputerFreeTime = statisticsLog.ComputerFreeTime
+		statisticsLogComputer.ComputerFeeRate = statisticsLog.ComputerFeeRate
+		statisticsLogComputer.EnterMain = statisticsLog.EnterMain
+		statisticsLogComputer.ComputerHourAverageRate = statisticsLog.ComputerHourAverageRate
+		statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
+	}
+	return statisticsLogsComputer, total, err
+}
+
 //根据游戏id查询数据
 //根据游戏id查询数据
 func (s *ServiceStatisticsLog) GameStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo) (interface{}, int64, error) {
 func (s *ServiceStatisticsLog) GameStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo) (interface{}, int64, error) {
 	date := api.CreateDate
 	date := api.CreateDate
@@ -715,12 +909,28 @@ func (s *ServiceStatisticsLog) TaskStatisticsDataCache1() {
 }
 }
 
 
 // 同步群控任务数据到缓存
 // 同步群控任务数据到缓存
-func (s *ServiceStatisticsLog) GetComputerNum() int {
-	ctx := context.Background()
-	computerNumKey := fmt.Sprintf(ComputerNum, s.CurrentDate())
-	num, err := global.GVA_REDIS.Get(ctx, computerNumKey).Int()
+func (s *ServiceStatisticsLog) GetComputerNum(date string) int64 {
+	var total int64
+	if date == "" {
+		date = s.CurrentDate()
+	}
+	db := global.GVA_DB.Model(&log.LogComputer{})
+	db = db.Distinct("pc_code").Where("create_date = ?", date)
+	_ = db.Count(&total).Error
+	return total
+}
+
+// 在线电脑接口
+func (s *ServiceStatisticsLog) ComputerHeartbeat(c context.Context, onlineComputer request.OnlineComputerRequest) error {
+	err := s.LogicalLog.SetOnlineComputerNumCache(c, s.LogicalLog.CurrentDate(), onlineComputer.PcCode, onlineComputer.Operator)
+	return err
+}
+
+// 在线电脑接口测试
+func (s *ServiceStatisticsLog) ComputerTest(c context.Context) (interface{}, error) {
+	mps, err := s.LogicalLog.GetOnlineComputerNumCache(c, s.LogicalLog.CurrentDate())
 	if err != nil {
 	if err != nil {
-		num = 0
+		return mps, err
 	}
 	}
-	return num
+	return mps, err
 }
 }

+ 35 - 0
service/log/loging/logical_log.go

@@ -32,6 +32,7 @@ var (
 	GameComputerRateCacheKey    = "%s:Computer:Rate:%s:"
 	GameComputerRateCacheKey    = "%s:Computer:Rate:%s:"
 	GamePcFeeRateCacheKey       = "%s:gamePc:gameFeeRate:%d:%s"
 	GamePcFeeRateCacheKey       = "%s:gamePc:gameFeeRate:%d:%s"
 	PcGameFeeRateCacheKey       = "%s:PcGame:FeeRate:%s"
 	PcGameFeeRateCacheKey       = "%s:PcGame:FeeRate:%s"
+	OnLineComputerNum           = "%s:OnLineComputerNum:"
 )
 )
 
 
 type LogicalLog struct {
 type LogicalLog struct {
@@ -679,3 +680,37 @@ func (s *LogicalLog) RequestTaskData() (result []byte, err error) {
 	result, err = utils.HttpGet(jfurl, jfparams)
 	result, err = utils.HttpGet(jfurl, jfparams)
 	return
 	return
 }
 }
+
+// 统计在线电脑数据
+func (s *LogicalLog) SetOnlineComputerNumCache(ctx context.Context, date string, pcCode string, operator string) (err error) {
+	key := fmt.Sprintf(OnLineComputerNum, date)
+	key += pcCode
+	err = s.cache.SetCacheStr(ctx, key, operator)
+	return err
+}
+
+// 获取在线电脑数据
+func (s *LogicalLog) GetOnlineComputerNumCache(ctx context.Context, date string) (mps map[string]string, err error) {
+	key := fmt.Sprintf(OnLineComputerNum, date)
+	mps, err = s.GetAllOnlineComputerNumCache(ctx, key)
+	if len(mps) == 0 {
+		return
+	}
+	return
+}
+
+// 获取所有在线电脑
+func (s *LogicalLog) GetAllOnlineComputerNumCache(ctx context.Context, key string) (mps map[string]string, err error) {
+	key += "*"
+	data, err := s.cache.GetCacheKeys(ctx, key)
+	if len(data) == 0 {
+		return
+	}
+	mps = make(map[string]string)
+	for _, k := range data {
+		pcCode := s.ByCacheKeyGetEndNode(k)
+		operator, _ := s.cache.GetCacheStr(ctx, k)
+		mps[pcCode] = operator
+	}
+	return
+}

+ 38 - 0
utils/requst_http.go

@@ -0,0 +1,38 @@
+package utils
+
+import (
+	"fmt"
+	"io/ioutil"
+	"net/http"
+)
+
+func HttpGet(url string, params map[string]string) (result []byte, err error) {
+	req, err := http.NewRequest("GET", url, nil)
+	if err != nil {
+		fmt.Println(err.Error())
+		return
+	}
+	q := req.URL.Query()
+	for k, v := range params {
+		q.Add(k, v)
+	}
+	req.URL.RawQuery = q.Encode()
+	fmt.Println(req.URL.String())
+	var resp *http.Response
+
+	resp, err = http.DefaultClient.Do(req)
+	if err != nil || resp == nil {
+		return
+	}
+	output, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return
+	}
+	result = output
+	defer func() {
+		if resp != nil {
+			resp.Body.Close()
+		}
+	}()
+	return
+}