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

数据优化导出功能电脑租机效率异常

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

+ 27 - 0
api/v1/log/loging.go

@@ -460,3 +460,30 @@ func (e *ApiLoging) ComputerRateExport(c *gin.Context) {
 	c.Writer.Header().Add("success", "true")
 	c.File(filePath)
 }
+
+// @Tags loging
+// @Summary 七天電腦效率
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce  application/octet-stream
+// @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
+// @Success 200
+// @Router /loging/computerSevenRate [post]
+func (e *ApiLoging) ComputerSevenRate(c *gin.Context) {
+	var paramsInfo request.GetStatisticsComputerRequest
+	_ = c.ShouldBindJSON(&paramsInfo)
+	paramsInfo.PageSize = 300
+	paramsInfo.Page = 1
+	list, _, err := ServiceStatisticsLog.ComputerSevenStatistics(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:    1,
+			Page:     paramsInfo.Page,
+			PageSize: paramsInfo.PageSize,
+		}, "获取成功", c)
+	}
+}

+ 1 - 0
router/log/loging.go

@@ -27,5 +27,6 @@ func (e *LogingRouter) InitLogingRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("updatePcRemarks", logApi.UpdatePcRemarks)
 		excelRouter.POST("getLogScanningList", logApi.GetLogScanningList)
 		excelRouter.POST("computerRateExport", logApi.ComputerRateExport)
+		excelRouter.POST("computerSevenRate", logApi.ComputerSevenRate)
 	}
 }

+ 6 - 2
service/dataStatistics/wechat_scanner_detailed.go

@@ -143,8 +143,12 @@ func (s *ServiceWeChatScannerDetailed) SyncWeChatScannerDetailed(today string) {
 			Time, _ := info.Get("Time").String()
 
 			orderArr := strings.Split(WeChatOrder, "|")
-			orderId := orderArr[0]
-			platform := orderArr[1]
+			orderId := ""
+			platform := ""
+			if len(orderArr) == 2 {
+				orderId = orderArr[0]
+				platform = orderArr[1]
+			}
 			var data dataStatistics.WeChatScannerDetailed
 			data.NewDate = today
 			data.TaskId = k

+ 75 - 8
service/log/log_statistics.go

@@ -515,13 +515,9 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 	var computer log.Computer
 	computerData, _ := computer.OnlinePcCodeCache()
 	var csReplys []*log.LogComputer
-	// 不统计本地测试电脑
-	notStatistics := map[string]int{
-		"001": 1,
-		"002": 1,
-	}
 	for code, r := range codeMps {
-		if _, ok := notStatistics[code]; ok {
+		// 不统计不在电脑列表里的
+		if _, ok := computerData[code]; !ok {
 			continue
 		}
 		accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
@@ -569,7 +565,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 			csReply.ComputerHourAverageRate = csReply.TaskSuccessNum / runTime
 			csReply.Status = 2
 			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).Where("game_id = ?", gameId).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
 				// 已存在,更新
 				mp := make(map[string]interface{})
 				if csReply.Operator != "" {
@@ -583,7 +579,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 				mp["game_fee_rate"] = csReply.GameFeeRate
 				mp["computer_hour_average_rate"] = csReply.ComputerHourAverageRate
 				mp["enter_main"] = csReply.EnterMain
-				err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Updates(mp).Error
+				err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Where("game_id = ?", gameId).Updates(mp).Error
 				if err != nil {
 					global.GVA_LOG.Error("更新数据失败", zap.Error(err))
 				}
@@ -1248,3 +1244,74 @@ func (exa *ServiceStatisticsLog) ComputeRateList2Excel(infoList []*response.Comp
 	err := excel.SaveAs(filePath)
 	return err
 }
+
+// 电脑效率七天数据查询
+func (s *ServiceStatisticsLog) ComputerSevenStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) (statisticsLogsComputer []*response.ComputerStatisticsReply1, total int64, err error) {
+	date := api.CreateDate
+	endDate := ""
+	startDate := ""
+	if date == "" {
+		endDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02")
+		startDate = time.Now().Add(-time.Hour * 24 * 8).Format("2006-01-02")
+	} else {
+		formatTime, _ := time.Parse("2006-01-02", date)
+		endDate = date
+		startDate = formatTime.Add(-time.Hour * 24 * 7).Format("2006-01-02")
+	}
+	db := global.GVA_DB.Model(&log.LogComputer{})
+	db = db.Where("create_date >= ? and create_date <= ?", startDate, endDate)
+	db = db.Where("pc_code = ?", api.PcCode)
+
+	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)
+	db.Group("create_date")
+	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 statisticsLogsComputer, 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 {
+		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.ComputerFeeRate = statisticsLog.ComputerFeeRate
+		statisticsLogComputer.ComputerHourAverageRate = statisticsLog.ComputerHourAverageRate
+		statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
+	}
+	return statisticsLogsComputer, total, err
+}

+ 3 - 3
service/task/sync_data.go

@@ -214,7 +214,7 @@ func (s *SyncData) SyncTaskData() {
 			gameTarget.NewComplete = roomData.NewCompleteLocal
 			gameTarget.PayComplete = roomData.PayCompleteLocal
 			gameTarget.RetainedComplete = roomData.NewCompleteLocal + roomData.RetainedCompleteLocal
-			gameTarget.Amount = 6 * roomData.PayCompleteLocal
+			gameTarget.Amount = gameTask.PayPrice * roomData.PayCompleteLocal
 			if gameTarget.RetainedComplete < roomData.RetainedComplete {
 				gameTarget.RetainedComplete = roomData.RetainedComplete
 			}
@@ -694,7 +694,7 @@ func (s *SyncData) TaskMsgSendFreeData(ctx context.Context, completesInfo []task
 			data.TimeRate = 60 * 60 * 2
 		}
 		// 5分钟数据没动报异常数据
-		if data.TimeRate/60 >= 4 {
+		if data.TimeRate/60 >= 2 {
 			if data.Rate == 0 {
 				lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, data.TaskId)
 				payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, data.TaskId)
@@ -850,7 +850,7 @@ func (s *SyncData) CheckTaskCompletedInfo() {
 		global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
 		time.Sleep(time.Second * 10)
 		_ = s.cache.SetCacheStr(ctx, taskCompletedStatusKey, 1)
-		msg := "# 测试监控报警 "
+		msg := "# 监控报警 "
 		msg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
 		msg += "\n"
 		msg += "今日任务目标已完成"